-
-
Notifications
You must be signed in to change notification settings - Fork 346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: remove store providers and restrict initial flow for EditorContainer
#6167
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
24a829e
to
d5ed6f6
Compare
EditorContainer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you clarify the API changes in PR description? Thanks!
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the impressive refactoring!
This PR may have an impact on the encapsulation of the AFFiNE side, as it constrains the mounting requirements of the |
Remove the
provider
field fromstore
The original implementation of the provider was mostly considered for AFFiNE's use cases. Now, as AFFiNE no longer uses the provider mechanism of BlockSuite itself and has implemented synchronization logic separately, the provider mechanism of BlockSuite is no longer necessary. Moreover, as an editor project natively supporting Yjs, BlockSuite should not have excessive constraints on the provider. Considering the above points, the provider-related code of BlockSuite has been removed.
Standardize the editor initialization process
The original implementation of the editor's initialization process was very chaotic, mainly manifested in the following aspects:
The API design of loading a Page Y.Doc is confusing. The positioning of
load
andtrySyncFromExistingDoc
is redundant, and it further leads to unclear timing of the triggering ofslots.ready
.load
actually callstrySyncFromExistingDoc
, and bothload
andtrySyncFromExistingDoc
may triggerslots.ready
.The handling of the editor mounting timing is chaotic.
EditorHost
is the ultimate management centre of the editor, as long asEditorHost
is successfully mounted, it can automatically update the Dom based on the updates of Yjs data. The basic condition for mountingEditorHost
is aPage
with a block of root type, and there are many situations regarding the source and timing of data when initializing the editor2.1. Completely manual initialization, that is, calling
workspace.createPage()
andpage.addBlock()
2.2. Pulling data from the provider, with no page in the workspace.
2.3. Pulling data from the provider, with pages in the workspace but no block of root type.
2.4. Pulling data from the provider, with pages in the workspace and a block of root type.
If it is impossible to know from the provider whether the data pull has ended, we need to manually subscribe to determine which of the situations 2.2, 2.3, and 2.4 we are in. In the original code, the above subscription operations were distributed in different levels and modules, for example, handling the situation 2.2 in the entry function, and handling the situation 2.4 in the
EditorContainer
.After the restructuring:
Page no longer exposes
trySyncFromExistingDoc
, only exposesload
, andslots.ready
is only triggered inload
.ready
only ensures that the blocks tree is synchronized with Yjs data when callingpage.load()
, and does not guarantee that the data meets the requirements for mountingEditorHost
.The mounting requirements of
EditorContainer
are aligned withEditorHost
, requiring a Page with a block of root type. Before mountingEditorContainer
, it is necessary to ensure that the data in the Page meets the mounting requirements.Basic initialization process after restructuring:
For 2.1, the usage is not much different from before.
For 2.2, 2.3, 2.4, it's like gathering the previously scattered handling code together.
If we can know the timing of synchronization completion from the provider, and we know that the synchronized block structure meets the requirements, the code can be simplified a lot.