Skip to content

Commit

Permalink
docs(json-crdt-extensions): ✏️ add MV-Register demo
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 4, 2024
1 parent 953108c commit 0c600f9
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/json-crdt-extensions/mval/__demos__/usage.ts
Original file line number Diff line number Diff line change
@@ -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 + '');

0 comments on commit 0c600f9

Please sign in to comment.