@@ -43,16 +43,12 @@ export class BasicBlock<Data, Patch> {
4343
4444 public apply ( patch : Patch ) : void {
4545 this . model . apply ( patch ) ;
46- this . v$ . next ( this . v$ . getValue ( ) + 1 ) ;
46+ this . v$ . next ( this . v$ . getValue ( ) ) ;
4747 }
4848}
4949
5050export type PatchResponse < Patch > = true | false | Patch ;
5151
52- export interface BranchDependencies < Patch > {
53- readonly merge : ( baseVersion : number , patches : Patch [ ] ) => Promise < BranchMergeResponse < Patch > > ;
54- }
55-
5652export interface BranchMergeResponse < Patch > {
5753 version : number ;
5854 batches : PatchResponse < Patch > [ ] [ ] ;
@@ -66,31 +62,23 @@ export class Branch<Data, Patch> {
6662 protected readonly head$ : BehaviorSubject < BasicBlock < Data , Patch > > ;
6763
6864 /**
69- * List of patches applied locally to the head, but not saved
70- * on the server. This is delta between the base and the head .
65+ * List of patches applied locally to the head, but not yet
66+ * added to the `batches` list .
7167 */
7268 protected patches : Patch [ ] ;
7369
74- /** Number of patches currently being merged to the server. */
75- protected merging : number = 0 ;
70+ /** List of batches to be persisted on the server. */
71+ protected batches : Patch [ ] [ ] = [ ] ;
7672
7773 constructor ( base : BasicBlock < Data , Patch > ) {
7874 this . base$ = new BehaviorSubject ( base ) ;
7975 this . patches = [ ] ;
8076 this . head$ = new BehaviorSubject ( base . fork ( ) ) ;
8177 }
8278
83- public async merge ( opts : BranchDependencies < Patch > ) : Promise < void > {
84- try {
85- const base = this . base$ . getValue ( ) ;
86- const baseVersion = base . v$ . getValue ( ) ;
87- const batch = [ ...this . patches ] ;
88- this . merging = batch . length ;
89- const res = await opts . merge ( baseVersion , batch ) ;
90-
91- } catch ( error ) {
92- this . merging = 0 ;
93- }
79+ public cutBatch ( ) : void {
80+ this . batches . push ( this . patches ) ;
81+ this . patches = [ ] ;
9482 }
9583
9684 /** Apply a patch locally to the head. */
0 commit comments