Skip to content
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: Make the plugin self-contained #6

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

dmaretskyi
Copy link
Contributor

@dmaretskyi dmaretskyi commented Dec 19, 2023

  • Plugin is now now self-contained where only extensions: [automergePlugin(handle, path)] needs to be passed to configure the editor.
  • Replaced the dependency on automerge-repo via an interface describing doc-handle so it can be used with Doc from @automerge/automerge package as well.

): AutomergePlugin => {
const stateField: StateField<Value> = StateField.define({
create: () => ({
lastHeads: automerge.getHeads(handle.docSync()!),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like a bit of a footgun. If a user passes a handle which is not ready yet then this will throw an error. I think we have three options:

  1. Add a "loading" state to the plugin and then attach a then handle to handle.doc() which transitions to a "ready" state. In the "loading" state the plugin would not allow input.
  2. Make automergePlugin async and wait for handle.doc().await
  3. Document in big letters that you must make sure the handle is ready before passing it to the plugin.

My preference would be for 2. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

Having a loading state seems to be out of scope for the editor plugin. Developers would want to customize the look of the loading state anyway or integrate with their UI library like react suspense.

I'd be hesitant to make the plugin async as there's no precedent for it. Main alternative - yjs, has a sync plugin. It also makes using wrappers that take extensions in props like https://uiwjs.github.io/react-codemirror/ more difficult.

I think my preference would be on option #3 with a clear error message that directs developers to implement a loading state for the editor. This seems to be the most flexible option in terms of API design.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point on the extension props. I agree with your argument, #3 is probably the best we can do.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seconding what's being said, as a developer I think not implementing the loading state in the plugin is the right way to go - off the top of my head I can think of two ways one might want to integrate it, either not showing the editor at all while loading or having a CM Compartment that is initially empty but is updated to contain the plugin once the handle is ready.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmaretskyi is adding an error message when passed a DocHandle with an undefined doc something you have capacity for? I think it would be really useful to merge this PR so would love to get that in there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants