2.0.15 • Published 7 months ago

@csbenjamin/ymmutable v2.0.15

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

Ymmutable

Mix between @syncedstore and Automerge. Using yjs in background.

import * as Y from 'yjs';
import {Ymmutable} from '@csbenjamin/ymmutable'

interface MyAmazingData {
  someObject: {hello: string};
  todoList: {description: string, done: boolean}[];
}
let store = Ymmutable<MyAmazingData>({someObject: 'object', todoList: 'array'});

expect(store.immutable.someObject).equal({});
expect(store.immutable.todoList).equal([]);
expect(store.doc instanceof Y.Doc).toBe(true);
expect(store.undoManager instanceof Y.UndoManager).toBe(true);

store.mutate(data => {
  data.someObject.hello = 'World!';
  data.todoList.push({descript: 'Share this with the World', done: false});
  data.todoList.push({descript: 'Share this with the World 2', done: false});
});

expect(store.immutable.someObject).equal({hello: 'World!'});
expect(store.immutable.todoList[0]).equal([{descript: 'Share this with the World', done: false}]);

const oldImmutable = store.immutable;

store.mutate(data => {
  data.todoList[0].done = true;
});

expect(store.immutable.todoList[0]).equal([{descript: 'Share this with the World', done: true}]);
expect(store.immutable === oldImmutable).toBe(false);
expect(store.immutable.someObject === oldImmutable.someObject).toBe(true);
expect(store.immutable.todoList === oldImmutable.todoList).toBe(false);
expect(store.immutable.todoList[0] === oldImmutable.todoList[0]).toBe(false);
expect(store.immutable.todoList[1] === oldImmutable.todoList[1]).toBe(true);

store.undoManager.undo();

expect(store.immutable.todoList[0]).equal([{descript: 'Share this with the World', done: false}]);

store.undoManager.undo();
expect(store.immutable.someObject).equal({});
expect(store.immutable.todoList).equal([]);
2.0.15

7 months ago

2.0.3

11 months ago

2.0.2

11 months ago

2.0.13

7 months ago

2.0.5

8 months ago

2.0.14

7 months ago

2.0.4

11 months ago

2.0.11

8 months ago

2.0.7

8 months ago

2.0.12

8 months ago

2.0.6

8 months ago

2.0.9

8 months ago

2.0.10

8 months ago

2.0.8

8 months ago

2.0.1

11 months ago

2.0.0

11 months ago

1.1.4

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago