-
After using lexical for a brief moment I fell in love with it. I only have one question — why opt for using dollar-sign ( I don't have anything in particular against them. I know there's other projects who utilize them as well, but there's typically a reason. For example styletron uses them for props that shouldn't be applied to the dom element. In case of lexical I could not figure it out. Is it purely a style choice? Keep up the good work, and keep the documentation coming! 💜 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
It’s for methods that need to be called within a read or update block (since they rely on getActiveEditor() etc) |
Beta Was this translation helpful? Give feedback.
-
To expand on the why: Originally, Lexical didn't have $ functions, instead these functions were provided to you through callback params:
Internally, this approach raised some negative feedback:
This is when we decided to leverage the "lexical" scope instead to perform EditorState manipulation, and the $ represents just that.
^ In the above 3 where I added the Additionally, the $ functions can extend beyond the functionality provided by the lexical package. If you've used React before they resemble hooks to certain extend. A function of your own that uses a $ functions becomes a $ function to represent that it touches the EditorState, this becomes very intuitive to read and understand where you can use these functions. For example:
Lastly, why the $? It's the most intuitive we could come up with and short - the second is particularly important because that's where most of your Lexical code will live. |
Beta Was this translation helpful? Give feedback.
To expand on the why:
Originally, Lexical didn't have $ functions, instead these functions were provided to you through callback params:
Internally, this approach raised some negative feedback:
viewState
terminology was confusing. It wasn't really a viewState, more like a toolkit to manipulate the EditorStateThis is when we decided to leverage the "lexical" scope instead to perform EditorState manipulation, and the $ re…