β‘ Plugin Bridge & Event Lifecycle
π Bridge Architecture (SPA β Editor)
- Outbound (Editor β Host): Intercept changes via
view.dispatch() β‘οΈ broadcast external state.
- Inbound (Host β Editor): Dispatch transactions imperatively via
view.dispatch(tr) β‘οΈ update doc state.
π Event Registry & Lifecycle
[Event Trigger] β‘οΈ [Capture: High-Precedence Listeners] β‘οΈ [Bubble/Dispatch] β‘οΈ [Destruction: Cleanup]
- DOM Listeners: Bind directly via
view.dom.addEventListener().
- Editor Handlers: Declare via
EditorView.domEventHandlers({...}) for internal event mapping.
- π§Ή Teardown: ALWAYS remove DOM listeners in the pluginβs
destroy() hook to prevent memory leaks.
βοΈ State Sync & Reconciliation
- β±οΈ Debounce: Batch outbound updates to prevent input lag and performance thrashing.
- π Reconciliation: Diff incoming host state against
view.state.doc before applying updates.
- βοΈ Conflict Resolution: Employ LWW (Last-Writer-Wins) for simple state, or OT (Operational Transformation) for concurrent edits.