In Lexical source code, alongside with every node class, there are also $create*Node
and $is*Node
functions being exported - for example:
export function $createTextNode(text?: string = ''): TextNode {
return new TextNode(text);
}
export function $isTextNode(node: ?LexicalNode): boolean %checks {
return node instanceof TextNode;
}
The same pattern is explicitely encouraged in documentation.
But why the dollar prefixes? According to documentation, the prefix denotes functions which "leverage the lexical scope":
This is when we decided to leverage the "lexical" scope instead to perform EditorState manipulation, and the $ represents just that.
But judging from the implementation, $create*Node
and $is*Node
seem to be just regular functions, that can be called from anywhere. So what's going on here?