Seems that it can be used to toggle any type of entity, so why isn't it name toggleEntity?
+1
I wonder why is it toggle in the first place, since you have to manually pass null as the entity key if you want to disable entity, as in the link example... Something like setEntity would be semantically more expectable
UPD. Anyway, the difference between subj and Modifier.applyEntity is unclear in docs
Beacuse they don't care about this.
I have the same question.
applyEntity would be a better name, becausetoggleLink is just a "syntax sugar" for applying an entity (Modifier.applyEntity + EditorState.push) and it's not a real toggler:
toggleLink: function(
editorState: EditorState,
targetSelection: SelectionState,
entityKey: ?string,
): EditorState {
var withoutLink = DraftModifier.applyEntity(
editorState.getCurrentContent(),
targetSelection,
entityKey,
);
return EditorState.push(
editorState,
withoutLink,
'apply-entity',
);
},
@flarnie if you agree with us and suggest a better name, I would like to make the changes and send a pull request.
following up here - I was also confused by this and agree that applyEntity would be a much clearer name
+1
I was digging the link example, and saw this. No comments, no docs, so confusing.
Most helpful comment
+1
I was digging the link example, and saw this. No comments, no docs, so confusing.