@dra2020/baseclient 1.0.122 → 1.0.124
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +433 -21
- package/dist/baseclient.js +105 -77
- package/dist/baseclient.js.map +1 -1
- package/dist/fsm/fsm.d.ts +3 -4
- package/dist/ot-js/otarray.d.ts +2 -0
- package/dist/ot-js/otcomposite.d.ts +2 -0
- package/dist/ot-js/ottypes.d.ts +4 -0
- package/lib/fsm/fsm.ts +80 -124
- package/lib/ot-js/otarray.ts +18 -0
- package/lib/ot-js/otcomposite.ts +30 -0
- package/lib/ot-js/otserverengine.ts +36 -0
- package/lib/ot-js/ottypes.ts +17 -0
- package/package.json +1 -1
package/dist/fsm/fsm.d.ts
CHANGED
|
@@ -14,9 +14,7 @@ export declare const FSM_CUSTOM6: number;
|
|
|
14
14
|
export declare const FSM_CUSTOM7: number;
|
|
15
15
|
export declare const FSM_CUSTOM8: number;
|
|
16
16
|
export declare const FSM_CUSTOM9: number;
|
|
17
|
-
export declare type FsmIndex =
|
|
18
|
-
[key: number]: Fsm;
|
|
19
|
-
};
|
|
17
|
+
export declare type FsmIndex = Set<Fsm>;
|
|
20
18
|
export declare class FsmManager {
|
|
21
19
|
theId: number;
|
|
22
20
|
theEpoch: number;
|
|
@@ -54,7 +52,8 @@ export declare class Fsm {
|
|
|
54
52
|
waitOn(fsm: Fsm | Fsm[]): Fsm;
|
|
55
53
|
setState(state: number): void;
|
|
56
54
|
end(state?: number): void;
|
|
57
|
-
|
|
55
|
+
waitOnCompleted(f: Fsm): void;
|
|
56
|
+
_completed(f: Fsm): void;
|
|
58
57
|
tick(): void;
|
|
59
58
|
}
|
|
60
59
|
export declare class FsmOnDone extends Fsm {
|
package/dist/ot-js/otarray.d.ts
CHANGED
|
@@ -91,8 +91,10 @@ export declare class OTArrayLikeResource extends OT.OTResourceBase {
|
|
|
91
91
|
alignEdges(rhs: OTArrayLikeResource, st: OTalignEdgesType): void;
|
|
92
92
|
getCursorCache(): any;
|
|
93
93
|
compose(rhs: OTArrayLikeResource): void;
|
|
94
|
+
tryCompose(rhs: OTArrayLikeResource): boolean;
|
|
94
95
|
performTransformReorder(bForceRetainBeforeInsert: boolean, newA: OTEdits, iBegin: number, iEnd: number): void;
|
|
95
96
|
normalizeNewRetainsAfterTransform(bForceRetainBeforeInsert: boolean): void;
|
|
97
|
+
tryTransform(prior: OTArrayLikeResource, bPriorIsService: boolean): boolean;
|
|
96
98
|
transform(prior: OTArrayLikeResource, bPriorIsService: boolean): void;
|
|
97
99
|
generateRandom(nInitial: number, clientID: string): void;
|
|
98
100
|
}
|
|
@@ -26,7 +26,9 @@ export declare class OTCompositeResource extends OT.OTResourceBase {
|
|
|
26
26
|
copy(): OTCompositeResource;
|
|
27
27
|
effectivelyEqual(rhs: OTCompositeResource): boolean;
|
|
28
28
|
transform(rhs: OTCompositeResource, bPriorIsService: boolean): void;
|
|
29
|
+
tryTransform(rhs: OTCompositeResource, bPriorIsService: boolean): boolean;
|
|
29
30
|
compose(rhs: OTCompositeResource): void;
|
|
31
|
+
tryCompose(rhs: OTCompositeResource): boolean;
|
|
30
32
|
apply(runningValue: any): any;
|
|
31
33
|
toPartialValue(resourceName: string): any;
|
|
32
34
|
toValue(): any;
|
package/dist/ot-js/ottypes.d.ts
CHANGED
|
@@ -8,7 +8,9 @@ export interface IOTResource {
|
|
|
8
8
|
copy(): IOTResource;
|
|
9
9
|
effectivelyEqual(rhs: IOTResource): boolean;
|
|
10
10
|
transform(rhs: IOTResource, bPriorIsService: boolean): void;
|
|
11
|
+
tryTransform(rhs: IOTResource, bPriorIsService: boolean): boolean;
|
|
11
12
|
compose(rhs: IOTResource): void;
|
|
13
|
+
tryCompose(rhs: IOTResource): boolean;
|
|
12
14
|
apply(startValue: any): any;
|
|
13
15
|
minimize(): void;
|
|
14
16
|
}
|
|
@@ -23,7 +25,9 @@ export declare class OTResourceBase implements IOTResource {
|
|
|
23
25
|
copy(): OTResourceBase;
|
|
24
26
|
effectivelyEqual(rhs: OTResourceBase): boolean;
|
|
25
27
|
transform(rhs: OTResourceBase, bPriorIsService: boolean): void;
|
|
28
|
+
tryTransform(rhs: OTResourceBase, bPriorIsServer: boolean): boolean;
|
|
26
29
|
compose(rhs: OTResourceBase): void;
|
|
30
|
+
tryCompose(rhs: OTResourceBase): boolean;
|
|
27
31
|
apply(startValue: any): any;
|
|
28
32
|
minimize(): void;
|
|
29
33
|
}
|
package/lib/fsm/fsm.ts
CHANGED
|
@@ -51,7 +51,7 @@ function FsmStateToString(state: number): string
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
export type FsmIndex =
|
|
54
|
+
export type FsmIndex = Set<Fsm>;
|
|
55
55
|
|
|
56
56
|
export class FsmManager
|
|
57
57
|
{
|
|
@@ -66,14 +66,14 @@ export class FsmManager
|
|
|
66
66
|
this.theId = 0;
|
|
67
67
|
this.theEpoch = 0;
|
|
68
68
|
this.bTickSet = false;
|
|
69
|
-
this.theTickList =
|
|
69
|
+
this.theTickList = new Set<Fsm>();
|
|
70
70
|
this.theBusyLoopCount = 0;
|
|
71
71
|
this.doTick = this.doTick.bind(this);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
forceTick(fsm: Fsm): void
|
|
75
75
|
{
|
|
76
|
-
this.theTickList
|
|
76
|
+
this.theTickList.add(fsm);
|
|
77
77
|
if (! this.bTickSet)
|
|
78
78
|
{
|
|
79
79
|
this.bTickSet = true;
|
|
@@ -82,32 +82,26 @@ export class FsmManager
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
doTick(): void
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
while (nLoops < 1 && !Util.isEmpty(this.theTickList))
|
|
90
|
-
{
|
|
91
|
-
nLoops++;
|
|
92
|
-
let thisTickList = this.theTickList;
|
|
93
|
-
this.theTickList = {};
|
|
94
|
-
|
|
95
|
-
for (let id in thisTickList) if (thisTickList.hasOwnProperty(id))
|
|
96
|
-
{
|
|
97
|
-
let f = thisTickList[id];
|
|
98
|
-
f.preTick();
|
|
99
|
-
f.tick();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
85
|
+
{
|
|
86
|
+
this.bTickSet = false;
|
|
87
|
+
let nLoops = 0;
|
|
102
88
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
89
|
+
while (nLoops < 1 && this.theTickList.size > 0)
|
|
90
|
+
{
|
|
91
|
+
nLoops++;
|
|
92
|
+
let thisTickList = this.theTickList;
|
|
93
|
+
this.theTickList = new Set<Fsm>();
|
|
107
94
|
|
|
108
|
-
|
|
95
|
+
thisTickList.forEach((f: Fsm) => f.tick());
|
|
109
96
|
}
|
|
110
97
|
|
|
98
|
+
if (this.theTickList.size == 0)
|
|
99
|
+
this.theBusyLoopCount = 0;
|
|
100
|
+
else
|
|
101
|
+
this.theBusyLoopCount++;
|
|
102
|
+
|
|
103
|
+
this.theEpoch++;
|
|
104
|
+
}
|
|
111
105
|
}
|
|
112
106
|
|
|
113
107
|
export interface FsmEnvironment
|
|
@@ -132,143 +126,105 @@ export class Fsm
|
|
|
132
126
|
this.state = FSM_STARTING;
|
|
133
127
|
this.dependentError = false;
|
|
134
128
|
this.epochDone = -1;
|
|
135
|
-
this._waitOn =
|
|
136
|
-
this._waitedOn =
|
|
129
|
+
this._waitOn = new Set<Fsm>();
|
|
130
|
+
this._waitedOn = new Set<Fsm>();
|
|
137
131
|
this.manager.forceTick(this);
|
|
138
132
|
}
|
|
139
133
|
|
|
140
134
|
get env(): FsmEnvironment { return this._env; }
|
|
141
135
|
get manager(): FsmManager { return this.env.fsmManager; }
|
|
142
136
|
|
|
143
|
-
get done(): boolean
|
|
144
|
-
{
|
|
145
|
-
return FsmDone(this.state);
|
|
146
|
-
}
|
|
137
|
+
get done(): boolean { return FsmDone(this.state) }
|
|
147
138
|
|
|
148
|
-
get ready(): boolean
|
|
149
|
-
{
|
|
150
|
-
return !this.done && this._waitOn == null;
|
|
151
|
-
}
|
|
139
|
+
get ready(): boolean { return !this.done && this.nWaitOn == 0 }
|
|
152
140
|
|
|
153
|
-
get iserror(): boolean
|
|
154
|
-
{
|
|
155
|
-
return (this.state === FSM_ERROR || this.state === FSM_CANCEL);
|
|
156
|
-
}
|
|
141
|
+
get iserror(): boolean { return this.state === FSM_ERROR || this.state === FSM_CANCEL }
|
|
157
142
|
|
|
158
|
-
get isDependentError(): boolean
|
|
159
|
-
{
|
|
160
|
-
return this.dependentError;
|
|
161
|
-
}
|
|
143
|
+
get isDependentError(): boolean { return this.dependentError }
|
|
162
144
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
// Override if you need to do more than marking complete
|
|
166
|
-
this.setState(FSM_CANCEL);
|
|
167
|
-
}
|
|
145
|
+
// Override if you need to do more than marking complete
|
|
146
|
+
cancel(): void { this.setState(FSM_CANCEL) }
|
|
168
147
|
|
|
169
|
-
setDependentError(): void
|
|
170
|
-
{
|
|
171
|
-
this.dependentError = true;
|
|
172
|
-
}
|
|
148
|
+
setDependentError(): void { this.dependentError = true }
|
|
173
149
|
|
|
174
|
-
clearDependentError(): void
|
|
175
|
-
{
|
|
176
|
-
this.dependentError = false;
|
|
177
|
-
}
|
|
150
|
+
clearDependentError(): void { this.dependentError = false }
|
|
178
151
|
|
|
179
|
-
get ticked(): boolean
|
|
180
|
-
{
|
|
181
|
-
return this.done && this.manager.theEpoch > this.epochDone;
|
|
182
|
-
}
|
|
152
|
+
get ticked(): boolean { return this.done && this.manager.theEpoch > this.epochDone }
|
|
183
153
|
|
|
184
|
-
get nWaitOn(): number
|
|
185
|
-
{
|
|
186
|
-
return Util.countKeys(this._waitOn);
|
|
187
|
-
}
|
|
154
|
+
get nWaitOn(): number { return this._waitOn.size }
|
|
188
155
|
|
|
189
|
-
get nWaitedOn(): number
|
|
190
|
-
{
|
|
191
|
-
return Util.countKeys(this._waitedOn);
|
|
192
|
-
}
|
|
156
|
+
get nWaitedOn(): number { return this._waitedOn.size }
|
|
193
157
|
|
|
194
158
|
waitOn(fsm: Fsm | Fsm[]): Fsm
|
|
159
|
+
{
|
|
160
|
+
if (fsm == null)
|
|
161
|
+
return this;
|
|
162
|
+
else if (Array.isArray(fsm))
|
|
195
163
|
{
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
164
|
+
fsm.forEach((f: Fsm) => this.waitOn(f));
|
|
165
|
+
}
|
|
166
|
+
else
|
|
167
|
+
{
|
|
168
|
+
if (fsm.done)
|
|
199
169
|
{
|
|
200
|
-
|
|
201
|
-
|
|
170
|
+
// If dependency is already done, don't add to waitOn list but ensure that
|
|
171
|
+
// this Fsm gets ticked during next epoch. This is because the dependent tick
|
|
172
|
+
// only happens when the dependency state is changed.
|
|
173
|
+
this.manager.forceTick(this);
|
|
174
|
+
if (fsm.iserror)
|
|
175
|
+
this.setDependentError();
|
|
202
176
|
}
|
|
203
177
|
else
|
|
204
178
|
{
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
// If dependency is already done, don't add to waitOn list but ensure that
|
|
208
|
-
// this Fsm gets ticked during next epoch. This is because the dependent tick
|
|
209
|
-
// only happens when the dependency state is changed.
|
|
210
|
-
this.manager.forceTick(this);
|
|
211
|
-
if (fsm.iserror)
|
|
212
|
-
this.setDependentError();
|
|
213
|
-
}
|
|
214
|
-
else
|
|
215
|
-
{
|
|
216
|
-
if (this._waitOn == null) this._waitOn = {};
|
|
217
|
-
this._waitOn[fsm.id] = fsm;
|
|
218
|
-
if (fsm._waitedOn == null) fsm._waitedOn = {};
|
|
219
|
-
fsm._waitedOn[this.id] = this;
|
|
220
|
-
}
|
|
179
|
+
this._waitOn.add(fsm);
|
|
180
|
+
fsm._waitedOn.add(this);
|
|
221
181
|
}
|
|
222
|
-
return this;
|
|
223
182
|
}
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
224
185
|
|
|
225
186
|
setState(state: number): void
|
|
187
|
+
{
|
|
188
|
+
this.state = state;
|
|
189
|
+
if (this.done)
|
|
226
190
|
{
|
|
227
|
-
|
|
228
|
-
|
|
191
|
+
// Loop because completion might add more to wait list
|
|
192
|
+
while (this.nWaitedOn)
|
|
229
193
|
{
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
this._waitedOn = null;
|
|
234
|
-
for (let id in on) if (on.hasOwnProperty(id))
|
|
235
|
-
{
|
|
236
|
-
let f = on[id];
|
|
237
|
-
if (this.iserror) f.setDependentError();
|
|
238
|
-
this.manager.forceTick(f);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
this.epochDone = this.manager.theEpoch;
|
|
194
|
+
let waitedOn = this._waitedOn;
|
|
195
|
+
this._waitedOn = new Set<Fsm>();
|
|
196
|
+
waitedOn.forEach((f: Fsm) => { f._completed(this); this.manager.forceTick(f) });
|
|
243
197
|
}
|
|
244
|
-
|
|
198
|
+
|
|
199
|
+
this.epochDone = this.manager.theEpoch;
|
|
245
200
|
}
|
|
201
|
+
this.manager.forceTick(this);
|
|
202
|
+
}
|
|
246
203
|
|
|
247
204
|
// Can override if need to do more here
|
|
248
205
|
end(state: number = FSM_DONE): void
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
206
|
+
{
|
|
207
|
+
this.setState(state);
|
|
208
|
+
}
|
|
252
209
|
|
|
253
|
-
//
|
|
254
|
-
|
|
210
|
+
// Override if subclass needs to respond to individual items completing rather than waiting
|
|
211
|
+
// in tick. Useful to avoid O(n^2) if waiting on lots of items and not wanting to do a linear
|
|
212
|
+
// scan for completed FSMs. Or to not require separate bookkeeping for list of dependents.
|
|
213
|
+
waitOnCompleted(f: Fsm): void { }
|
|
214
|
+
|
|
215
|
+
_completed(f: Fsm): void
|
|
216
|
+
{
|
|
217
|
+
if (f.iserror) this.setDependentError();
|
|
218
|
+
if (f.done && this._waitOn.has(f))
|
|
255
219
|
{
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
for (let id in this._waitOn) if (this._waitOn.hasOwnProperty(id))
|
|
259
|
-
{
|
|
260
|
-
let fsm = this._waitOn[id];
|
|
261
|
-
if (fsm.done)
|
|
262
|
-
delete this._waitOn[id];
|
|
263
|
-
else
|
|
264
|
-
bMore = true;
|
|
265
|
-
}
|
|
266
|
-
if (!bMore) this._waitOn = null;
|
|
220
|
+
this._waitOn.delete(f);
|
|
221
|
+
this.waitOnCompleted(f);
|
|
267
222
|
}
|
|
223
|
+
}
|
|
268
224
|
|
|
269
225
|
tick(): void
|
|
270
|
-
|
|
271
|
-
|
|
226
|
+
{
|
|
227
|
+
}
|
|
272
228
|
}
|
|
273
229
|
|
|
274
230
|
// Launches callback provided when the associated Fsm (or Fsm array) completes.
|
package/lib/ot-js/otarray.ts
CHANGED
|
@@ -770,6 +770,16 @@ export class OTArrayLikeResource extends OT.OTResourceBase
|
|
|
770
770
|
this.coalesce();
|
|
771
771
|
}
|
|
772
772
|
|
|
773
|
+
tryCompose(rhs: OTArrayLikeResource): boolean
|
|
774
|
+
{
|
|
775
|
+
if (this.length == 0)
|
|
776
|
+
return true;
|
|
777
|
+
else if (rhs.edits.length == 0)
|
|
778
|
+
return true;
|
|
779
|
+
|
|
780
|
+
return this.finalLength() == rhs.originalLength();
|
|
781
|
+
}
|
|
782
|
+
|
|
773
783
|
performTransformReorder(bForceRetainBeforeInsert: boolean, newA: OTEdits, iBegin: number, iEnd: number): void
|
|
774
784
|
{
|
|
775
785
|
if (iBegin < 0 || iBegin > iEnd) return;
|
|
@@ -835,6 +845,14 @@ export class OTArrayLikeResource extends OT.OTResourceBase
|
|
|
835
845
|
this.edits = newA;
|
|
836
846
|
}
|
|
837
847
|
|
|
848
|
+
tryTransform(prior: OTArrayLikeResource, bPriorIsService: boolean): boolean
|
|
849
|
+
{
|
|
850
|
+
if (this.length == 0 || prior.length == 0)
|
|
851
|
+
return true;
|
|
852
|
+
|
|
853
|
+
return this.originalLength() == prior.originalLength();
|
|
854
|
+
}
|
|
855
|
+
|
|
838
856
|
transform(prior: OTArrayLikeResource, bPriorIsService: boolean): void
|
|
839
857
|
{
|
|
840
858
|
if (this.length == 0 || prior.length == 0)
|
package/lib/ot-js/otcomposite.ts
CHANGED
|
@@ -133,6 +133,21 @@ export class OTCompositeResource extends OT.OTResourceBase
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
tryTransform(rhs: OTCompositeResource, bPriorIsService: boolean): boolean
|
|
137
|
+
{
|
|
138
|
+
let bSucceed = true;
|
|
139
|
+
|
|
140
|
+
for (let i: number = 0; bSucceed && i < rhs.length; i++)
|
|
141
|
+
{
|
|
142
|
+
let rhsEdit: OT.IOTResource = rhs.edits[i];
|
|
143
|
+
let lhsEdit: OT.IOTResource = this.findResource(rhsEdit.resourceName, rhsEdit.underlyingType, false);
|
|
144
|
+
if (lhsEdit)
|
|
145
|
+
bSucceed = lhsEdit.tryTransform(rhsEdit, bPriorIsService);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return bSucceed;
|
|
149
|
+
}
|
|
150
|
+
|
|
136
151
|
// compose two edit actions
|
|
137
152
|
compose(rhs: OTCompositeResource): void // throws on error
|
|
138
153
|
{
|
|
@@ -149,6 +164,21 @@ export class OTCompositeResource extends OT.OTResourceBase
|
|
|
149
164
|
this.clientSequenceNo = rhs.clientSequenceNo;
|
|
150
165
|
}
|
|
151
166
|
|
|
167
|
+
tryCompose(rhs: OTCompositeResource): boolean
|
|
168
|
+
{
|
|
169
|
+
let bSucceed = true;
|
|
170
|
+
for (let i: number = 0; bSucceed && i < rhs.length; i++)
|
|
171
|
+
{
|
|
172
|
+
let rhsEdit: OT.IOTResource = rhs.edits[i];
|
|
173
|
+
|
|
174
|
+
let lhsEdit: OT.IOTResource = this.findResource(rhsEdit.resourceName, rhsEdit.underlyingType, !rhsEdit.isEmpty());
|
|
175
|
+
if (lhsEdit)
|
|
176
|
+
bSucceed = lhsEdit.tryCompose(rhsEdit);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return bSucceed;
|
|
180
|
+
}
|
|
181
|
+
|
|
152
182
|
// apply this edit to an existing value, returning new value (if underlying type is mutable, may modify input)
|
|
153
183
|
// For composite, takes array of values, returns array of results, one for each underlying resource.
|
|
154
184
|
apply(runningValue: any): any
|
|
@@ -245,11 +245,47 @@ export class OTServerEngine extends OTE.OTEngine
|
|
|
245
245
|
for (i++; i < this.logServer.length; i++)
|
|
246
246
|
aPrior.compose(this.logServer[i]);
|
|
247
247
|
|
|
248
|
+
if (! a.tryTransform(aPrior, true))
|
|
249
|
+
{
|
|
250
|
+
console.log('otserverengine: rejecting event on transform failure');
|
|
251
|
+
this.forgetEvents(orig);
|
|
252
|
+
return OTS.EClockReset;
|
|
253
|
+
}
|
|
254
|
+
|
|
248
255
|
a.transform(aPrior, true);
|
|
249
256
|
}
|
|
250
257
|
|
|
258
|
+
let bFail = ! this.stateServer.tryCompose(a);
|
|
259
|
+
if (bFail)
|
|
260
|
+
{
|
|
261
|
+
console.log('otserverengine: rejecting event on compose failure');
|
|
262
|
+
if (this.logServer.length)
|
|
263
|
+
{
|
|
264
|
+
let newState = this.logServer[0].copy();
|
|
265
|
+
for (let i = 1; i < this.logServer.length; i++)
|
|
266
|
+
newState.compose(this.logServer[i]);
|
|
267
|
+
if (newState.tryCompose(a))
|
|
268
|
+
{
|
|
269
|
+
console.log('otserverengine: actually... rejected event would succeed on composed log, so patching');
|
|
270
|
+
this.stateServer = newState;
|
|
271
|
+
bFail = false;
|
|
272
|
+
}
|
|
273
|
+
else
|
|
274
|
+
console.log('otserverengine: and... rejected event also fails on composed log');
|
|
275
|
+
}
|
|
276
|
+
else
|
|
277
|
+
console.log('otserverengine: and... no log to try to patch state with');
|
|
278
|
+
|
|
279
|
+
if (bFail)
|
|
280
|
+
{
|
|
281
|
+
this.forgetEvents(orig);
|
|
282
|
+
return OTS.EClockReset;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
251
286
|
a.clock = this.stateServer.clock + 1;
|
|
252
287
|
this.stateServer.compose(a);
|
|
288
|
+
|
|
253
289
|
this.resetCaches();
|
|
254
290
|
this.emit('state');
|
|
255
291
|
this.logServer.push(a.copy());
|
package/lib/ot-js/ottypes.ts
CHANGED
|
@@ -20,9 +20,14 @@ export interface IOTResource
|
|
|
20
20
|
// Core OT algorithm for this type
|
|
21
21
|
transform(rhs: IOTResource, bPriorIsService: boolean): void; // throws on error
|
|
22
22
|
|
|
23
|
+
tryTransform(rhs: IOTResource, bPriorIsService: boolean): boolean;
|
|
24
|
+
|
|
23
25
|
// compose two edit actions
|
|
24
26
|
compose(rhs: IOTResource): void; // throws on error
|
|
25
27
|
|
|
28
|
+
// tests if compose would succeed, false on failure to prevent throwing during compose and leaving in partial state
|
|
29
|
+
tryCompose(rhs: IOTResource): boolean
|
|
30
|
+
|
|
26
31
|
// apply this edit to an existing value, returning new value (if underlying type is mutable, may modify input)
|
|
27
32
|
apply(startValue: any): any;
|
|
28
33
|
|
|
@@ -79,12 +84,24 @@ export class OTResourceBase implements IOTResource
|
|
|
79
84
|
throw "OTResourceBase.transform must be overridden in subclass";
|
|
80
85
|
}
|
|
81
86
|
|
|
87
|
+
// Test if transform would succeed, false on failure
|
|
88
|
+
tryTransform(rhs: OTResourceBase, bPriorIsServer: boolean): boolean
|
|
89
|
+
{
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
|
|
82
93
|
// compose two edit actions
|
|
83
94
|
compose(rhs: OTResourceBase): void
|
|
84
95
|
{
|
|
85
96
|
throw "OTResourceBase.compose must be overridden in subclass";
|
|
86
97
|
}
|
|
87
98
|
|
|
99
|
+
// test compose
|
|
100
|
+
tryCompose(rhs: OTResourceBase): boolean
|
|
101
|
+
{
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
|
|
88
105
|
// apply this edit to an existing value, returning new value (if underlying type is mutable, may modify input)
|
|
89
106
|
apply(startValue: any): any
|
|
90
107
|
{
|