Skip to content

Commit 1ff823f

Browse files
authored
Merge pull request #666 from streamich/json-patch-state-2
`JsonPatchState` improvements
2 parents e737bc0 + b377d7c commit 1ff823f

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/json-crdt/json-patch/JsonPatch.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ export class JsonPatch<N extends JsonNode = JsonNode<any>> {
1515

1616
public apply(ops: Operation[]): this {
1717
const length = ops.length;
18-
for (let i = 0; i < length; i++) this.applyOp(ops[i]);
18+
this.model.api.transaction(() => {
19+
for (let i = 0; i < length; i++) this.applyOp(ops[i]);
20+
});
1921
return this;
2022
}
2123

src/json-crdt/json-patch/JsonPatchStore.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ import type {JsonNode, JsonNodeView} from '../nodes';
99
export class JsonPatchStore<N extends JsonNode = JsonNode<any>> implements SyncStore<Readonly<JsonNodeView<N>>> {
1010
public readonly node: N;
1111
public readonly api: JsonNodeApi<N>;
12-
protected _patcher: JsonPatch<N>;
13-
protected _pfx: string;
12+
public readonly patcher: JsonPatch<N>;
13+
public readonly pfx: string;
1414

1515
constructor(
1616
protected readonly model: Model<N>,
17-
protected readonly path: Path = [],
17+
public readonly path: Path = [],
1818
) {
19-
this._pfx = path.length ? path.join() : '';
19+
this.pfx = path.length ? path.join() : '';
2020
const api = model.api;
2121
this.node = api.find(path) as N;
2222
this.api = api.wrap(this.node) as unknown as JsonNodeApi<N>;
23-
this._patcher = new JsonPatch(model, path);
23+
this.patcher = new JsonPatch(model, path);
2424
}
2525

2626
public readonly update = (change: Operation | Operation[]): void => {
2727
const ops = Array.isArray(change) ? change : [change];
28-
this._patcher.apply(ops);
28+
this.patcher.apply(ops);
2929
};
3030

3131
// ---------------------------------------------------------------- SyncStore

0 commit comments

Comments
 (0)