From 0c600f94a806e65736e8cc96eca23c4f9d4753a9 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 4 Mar 2024 15:33:37 +0100 Subject: [PATCH] =?UTF-8?q?docs(json-crdt-extensions):=20=E2=9C=8F?= =?UTF-8?q?=EF=B8=8F=20add=20MV-Register=20demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mval/__demos__/usage.ts | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/json-crdt-extensions/mval/__demos__/usage.ts diff --git a/src/json-crdt-extensions/mval/__demos__/usage.ts b/src/json-crdt-extensions/mval/__demos__/usage.ts new file mode 100644 index 0000000000..938954a693 --- /dev/null +++ b/src/json-crdt-extensions/mval/__demos__/usage.ts @@ -0,0 +1,44 @@ +/* tslint:disable no-console */ + +/** + * Run this demo with: + * + * npx nodemon -q -x ts-node src/json-crdt-extensions/mval/__demos__/usage.ts + */ + +import {Model} from '../../../json-crdt'; +import {ValueMvExt} from '..'; + +console.clear(); + +const model = Model.withLogicalClock(1234); + +model.ext.register(ValueMvExt) + +model.api.root({ + mv: ValueMvExt.new(1), +}); + +console.log(''); +console.log('Initial value:'); +console.log(model + ''); + +const api = model.api.in('mv').asExt(ValueMvExt); + +api.set(5); + +console.log(''); +console.log('After update:'); +console.log(model + ''); + +const model2 = model.fork(); + +const api2 = model2.api.in('mv').asExt(ValueMvExt); + +api.set(10); +api2.set(20); +model.applyPatch(model2.api.flush()); + +console.log(''); +console.log('After two users update concurrently:'); +console.log(model + '');