feat(collaborative-vue): Vue.js composables, components & context for json-joy CRDTs#1041
Open
mmamedel wants to merge 1 commit into
Open
feat(collaborative-vue): Vue.js composables, components & context for json-joy CRDTs#1041mmamedel wants to merge 1 commit into
mmamedel wants to merge 1 commit 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>
mmamedel
force-pushed
the
feat/collaborative-vue
branch
from
June 6, 2026 12:58
7a49245 to
69c7e90
Compare
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.
What
Adds
@jsonjoy.com/collaborative-vue— the Vue 3 counterpart of@jsonjoy.com/collaborative-react, mirroring its surface and naming: composables, provide/inject context helpers, and render-prop components for binding Vue UI to json-joy CRDT models and nodes.Note
Supersedes the earlier approach in this PR. The first revision was a writable-proxy binding built on a proposed
.wcore API (#1040). Per the feedback on #1040 — that the existing verbs already cover every write and are more precise — this PR was rewritten to build entirely on json-joy's existing public API. There are no changes to json-joy core, and the branch no longer depends on #1040.Surface (mirrors
collaborative-react)context.tscontext.tsxcreateNodeCtx,provideModel/provideNode,useCtx{Model,Node}[Strict],<ModelProvider>/<NodeProvider>composables.tshooks.tsuseModelTick/useModelView/useModel/useModelTry;useNodeEvents/useNodeEffect/useNodeChange/useNode/useNodeView;usePath/usePathView/useObj/useArr/useStrcomponents.tscomponents.ts<UseModel>/<UseNode>(scoped-slot render props)types.ts/utils.tsCrdtNodeApi,selectNodeDesign
obj.set/del,str.ins,arr.push/upd/del, …). The binding adds no write abstraction, so the full precise CRDT API stays available (setvsmerge, character-level text ops, etc.).eventarg —'self'|'child'|'subtree'— just like React.triggerRefon every matching change, so a stable node handle still re-notifies dependents (React re-renders on change regardless of return identity).useModelViewis identity-gated (re-renders only when the view object changes);useModelTick/useModelViewbuffer on a microtask, node events fire synchronously.onScopeDisposewhen used inside a component/effectScope.Tests
11 tests, all green:
composables.spec.ts—useModelView/useModelTickreactivity + microtask flush,useStrresolve+read+in-place edit,usePathmissing→present,useNodeView, scope teardown (run undereffectScope).context.spec.ts—ModelProviderprovide/inject, strict-context throws,UseModel/UseNoderender and update on change (mounted in jsdom).Builds via the root solution
tsc -b.Follow-up
A small stacked PR will add an optional high-level
collaborate()proxy (plain-object reads +v-modeltwo-way binding) built on top of these composables — keeping the project's layering (node API ← composables ← optional sugar) instead of competing with it.