-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(json-crdt-extensions): ✏️ add MV-Register demo
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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 + ''); |