feat(collaborative-vue): optional collaborate() proxy for v-model (stacked on #1041)#1042
Open
mmamedel wants to merge 2 commits into
Open
feat(collaborative-vue): optional collaborate() proxy for v-model (stacked on #1041)#1042mmamedel wants to merge 2 commits into
mmamedel wants to merge 2 commits into
Conversation
… json-joy CRDTs
Adds @jsonjoy.com/collaborative-vue — the Vue 3 counterpart of
@jsonjoy.com/collaborative-react, mirroring its surface and names:
- context.ts — provide/inject helpers (createNodeCtx, provideModel/provideNode,
useCtx{Model,Node}[Strict]) and <ModelProvider>/<NodeProvider>
- composables.ts — useModelTick/View/Model/ModelTry, useNodeEvents/Effect/
Change/Node/NodeView, usePath/PathView/Obj/Arr/Str
- components.ts — <UseModel>/<UseNode> render-prop components via scoped slots
Reads return Vue refs/computed; writes use json-joy's existing node verbs
(obj.set, str.ins, arr.push, …) — no additions to json-joy core. Node/path
composables force-trigger on every matching change so stable node handles still
re-notify, matching React's re-render-on-change semantics.
Builds entirely on the existing public API. Tested with jest (composables via
effectScope, context/components mounted in jsdom).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…omposables
Adds a high-level `collaborate(model)` that returns a single fine-grained
reactive `state` proxy — plain-object reads and `v-model` two-way binding, the
Vue-idiomatic ergonomics the low-level composables serve awkwardly.
It is sugar over the composables: reactivity uses the same per-node
`onNodeChange('self')` subscription, and writes dispatch through json-joy's
existing node verbs (ObjApi.set/del, ArrApi.ins/upd/del/merge, VecApi.set).
No additions to json-joy core.
5 tests (jest, watchEffect): reads mirror the view; assignment + array methods
record ops; fine-grained (sibling edits don't cross-trigger); remote-patch
convergence; dispose() teardown.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
Stacked on #1041 (the
collaborative-vuecomposables). This branch contains #1041's commit as a dependency, so the diff currently shows both. Please review/merge #1041 first; the only new commit here ised998ec(the optionalcollaborate()proxy). Once #1041 lands, this reduces to just that commit.What
Adds an optional high-level
collaborate(model)to@jsonjoy.com/collaborative-vue— a single fine-grained reactivestateproxy you read and mutate like a plain object, purpose-built for Vuev-modeltwo-way binding, which the low-level composables (#1041) serve awkwardly.Why a separate, additive layer
This keeps the project's layering — node API ← composables ← optional sugar — rather than competing with it:
onNodeChange('self')subscription; writes dispatch through json-joy's existing node verbs (ObjApi.set/del,ArrApi.ins/upd/del/merge,VecApi.set)..wAPI, now living entirely in the binding).applyPatchre-renders only the nodes that changed — no reconcile pass, no echo guard, no second store.mergevsset, explicitself/child/subtreegranularity) you drop down to the composables; the proxy doesn't hide them.API
collaborate<T>(model): { state: T; dispose(): void }dispose()runs automatically when called inside a componentsetup()(viaonScopeDispose).Tests
5 tests (jest +
watchEffect), all green: reads mirror the view; plain assignment + array methods record ops; fine-grained (a title edit doesn't re-run an effect reading the notes); remote-patch convergence re-renders the affected node;dispose()stops reacting. Builds via the root solutiontsc -b.