@@ -160,8 +160,8 @@ export class PatchBuilder {
160
160
* @returns ID of the new operation.
161
161
*/
162
162
public insObj ( obj : ITimestampStruct , data : [ key : string , value : ITimestampStruct ] [ ] ) : ITimestampStruct {
163
- this . pad ( ) ;
164
163
if ( ! data . length ) throw new Error ( 'EMPTY_TUPLES' ) ;
164
+ this . pad ( ) ;
165
165
const id = this . clock . tick ( 1 ) ;
166
166
const op = new operations . InsObjOp ( id , obj , data ) ;
167
167
const span = op . span ( ) ;
@@ -176,8 +176,8 @@ export class PatchBuilder {
176
176
* @returns ID of the new operation.
177
177
*/
178
178
public insVec ( obj : ITimestampStruct , data : [ index : number , value : ITimestampStruct ] [ ] ) : ITimestampStruct {
179
- this . pad ( ) ;
180
179
if ( ! data . length ) throw new Error ( 'EMPTY_TUPLES' ) ;
180
+ this . pad ( ) ;
181
181
const id = this . clock . tick ( 1 ) ;
182
182
const op = new operations . InsVecOp ( id , obj , data ) ;
183
183
const span = op . span ( ) ;
@@ -206,8 +206,8 @@ export class PatchBuilder {
206
206
* @returns ID of the new operation.
207
207
*/
208
208
public insStr ( obj : ITimestampStruct , ref : ITimestampStruct , data : string ) : ITimestampStruct {
209
- this . pad ( ) ;
210
209
if ( ! data . length ) throw new Error ( 'EMPTY_STRING' ) ;
210
+ this . pad ( ) ;
211
211
const id = this . clock . tick ( 1 ) ;
212
212
const op = new operations . InsStrOp ( id , obj , ref , data ) ;
213
213
const span = op . span ( ) ;
@@ -222,8 +222,8 @@ export class PatchBuilder {
222
222
* @returns ID of the new operation.
223
223
*/
224
224
public insBin ( obj : ITimestampStruct , ref : ITimestampStruct , data : Uint8Array ) : ITimestampStruct {
225
- this . pad ( ) ;
226
225
if ( ! data . length ) throw new Error ( 'EMPTY_BINARY' ) ;
226
+ this . pad ( ) ;
227
227
const id = this . clock . tick ( 1 ) ;
228
228
const op = new operations . InsBinOp ( id , obj , ref , data ) ;
229
229
const span = op . span ( ) ;
@@ -247,6 +247,19 @@ export class PatchBuilder {
247
247
return id ;
248
248
}
249
249
250
+ /**
251
+ * Update an element in an "arr" object.
252
+ *
253
+ * @returns ID of the new operation.
254
+ */
255
+ public updArr ( arr : ITimestampStruct , ref : ITimestampStruct , val : ITimestampStruct ) : ITimestampStruct {
256
+ this . pad ( ) ;
257
+ const id = this . clock . tick ( 1 ) ;
258
+ const op = new operations . UpdArrOp ( id , arr , ref , val ) ;
259
+ this . patch . ops . push ( op ) ;
260
+ return id ;
261
+ }
262
+
250
263
/**
251
264
* Delete a span of operations.
252
265
*
0 commit comments