Skip to content

Commit 684725a

Browse files
committed
Update docs
1 parent eb3cea2 commit 684725a

File tree

4 files changed

+51
-37
lines changed

4 files changed

+51
-37
lines changed

README.md

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,6 @@ Unique document ID
246246
`doc.data` _(Object)_
247247
Document contents. Available after document is fetched or subscribed to.
248248

249-
`doc.undoLimit` _(Number, read-write, default=100)_
250-
The max number of operations to keep on the undo stack.
251-
252-
`doc.undoComposeTimeout` _(Number, read-write, default=1000)_
253-
The max time difference between operations in milliseconds,
254-
which still allows "UNDOABLE" operations to be composed on the undo stack.
255-
256249
`doc.fetch(function(err) {...})`
257250
Populate the fields on `doc` with a snapshot of the document from the server.
258251

@@ -273,11 +266,11 @@ same time as callbacks to `fetch` and `subscribe`.
273266
`doc.on('create', function(source) {...})`
274267
The document was created. Technically, this means it has a type. `source` will be `false` for ops received from the server and defaults to `true` for ops generated locally.
275268

276-
`doc.on('before op'), function(op, source, operationType) {...})`
277-
An operation is about to be applied to the data. Params are the same as for the `op` event below.
269+
`doc.on('before op'), function(op, source) {...})`
270+
An operation is about to be applied to the data. `source` will be `false` for ops received from the server and defaults to `true` for ops generated locally.
278271

279-
`doc.on('op', function(op, source, operationType) {...})`
280-
An operation was applied to the data. `source` will be `false` for ops received from the server and defaults to `true` for ops generated locally. `operationType` is one of the following: `"UNDOABLE"` _(local operation that can be undone)_, `"FIXED"` _(local or remote operation that can't be undone nor redone)_, `"UNDO"` _(local undo operation that can be redone)_ and `"REDO"` _(local redo operation that can be undone)_.
272+
`doc.on('op', function(op, source) {...})`
273+
An operation was applied to the data. `source` will be `false` for ops received from the server and defaults to `true` for ops generated locally.
281274

282275
`doc.on('del', function(data, source) {...})`
283276
The document was deleted. Document contents before deletion are passed in as an argument. `source` will be `false` for ops received from the server and defaults to `true` for ops generated locally.
@@ -302,19 +295,17 @@ Apply operation to document and send it to the server.
302295
Call this after you've either fetched or subscribed to the document.
303296
* `options.source` Argument passed to the `'op'` event locally. This is not sent to the server or other clients. Defaults to `true`.
304297
* `options.skipNoop` Should processing be skipped entirely, if `op` is a no-op. Defaults to `false`.
305-
* `options.undoable` Should it be possible to undo this operation, default=false.
306-
* `options.fixUpUndoStack` Determines how a non-undoable operation affects the undo stack. If `false` (default), the operation transforms the undo stack, otherwise it is inverted and composed into the last operation on the undo stack.
307-
* `options.fixUpRedoStack` Determines how a non-undoable operation affects the redo stack. If `false` (default), the operation transforms the redo stack, otherwise it is inverted and composed into the last operation on the redo stack.
298+
* `options.undoable` Should it be possible to undo this operation. Defaults to `false`.
299+
* `options.fixUp` If true, this operation is meant to fix the current invalid state of the snapshot. It also updates UndoManagers accordingly. This feature requires the OT type to implement `compose`.
308300

309301
`doc.submitSnapshot(snapshot[, options][, function(err) {...}])`
310302
Diff the current and the provided snapshots to generate an operation, apply the operation to the document and send it to the server.
311303
`snapshot` structure depends on the document type.
312304
Call this after you've either fetched or subscribed to the document.
313305
* `options.source` Argument passed to the `'op'` event locally. This is not sent to the server or other clients. Defaults to `true`.
314-
* `options.skipNoop` Should processing be skipped entirely, if the generated operation is a no-op. Defaults to `false`.
315-
* `options.undoable` Should it be possible to undo this operation, default=false.
316-
* `options.fixUpUndoStack` Determines how a non-undoable operation affects the undo stack. If `false` (default), the operation transforms the undo stack, otherwise it is inverted and composed into the last operation on the undo stack.
317-
* `options.fixUpRedoStack` Determines how a non-undoable operation affects the redo stack. If `false` (default), the operation transforms the redo stack, otherwise it is inverted and composed into the last operation on the redo stack.
306+
* `options.skipNoop` Should processing be skipped entirely, if `op` is a no-op. Defaults to `false`.
307+
* `options.undoable` Should it be possible to undo this operation. Defaults to `false`.
308+
* `options.fixUp` If true, this operation is meant to fix the current invalid state of the snapshot. It also updates UndoManagers accordingly. This feature requires the OT type to implement `compose`.
318309
* `options.diffHint` A hint passed into the `diff`/`diffX` functions defined by the document type.
319310

320311
`doc.del([options][, function(err) {...}])`
@@ -330,20 +321,6 @@ Invokes the given callback function after
330321

331322
Note that `whenNothingPending` does NOT wait for pending `model.query()` calls.
332323

333-
`doc.canUndo()`
334-
Return `true`, if there's an operation on the undo stack that can be undone, otherwise `false`.
335-
336-
`doc.undo([options][, function(err) {...}])`
337-
Undo a previously applied "UNDOABLE" or "REDO" operation.
338-
* `options.source` Argument passed to the `'op'` event locally. This is not sent to the server or other clients. Defaults to `true`.
339-
340-
`doc.canRedo()`
341-
Return `true`, if there's an operation on the redo stack that can be undone, otherwise `false`.
342-
343-
`doc.redo([options][, function(err) {...}])`
344-
Redo a previously applied "UNDO" operation.
345-
* `options.source` Argument passed to the `'op'` event locally. This is not sent to the server or other clients. Defaults to `true`.
346-
347324
### Class: `ShareDB.Query`
348325

349326
`query.ready` _(Boolean)_
@@ -381,6 +358,28 @@ after a sequence of diffs are handled.
381358
`query.on('extra', function() {...}))`
382359
(Only fires on subscription queries) `query.extra` changed.
383360

361+
### Class: `ShareDB.UndoManager`
362+
363+
`undoManager.canUndo()`
364+
Return `true`, if there's an operation on the undo stack that can be undone, otherwise `false`.
365+
366+
`undoManager.undo([options][, function(err) {...}])`
367+
Undo a previously applied undoable or redo operation.
368+
* `options.source` Argument passed to the `'op'` event locally. This is not sent to the server or other clients. Defaults to `true`.
369+
370+
`undoManager.canRedo()`
371+
Return `true`, if there's an operation on the redo stack that can be undone, otherwise `false`.
372+
373+
`undoManager.redo([options][, function(err) {...}])`
374+
Redo a previously applied undo operation.
375+
* `options.source` Argument passed to the `'op'` event locally. This is not sent to the server or other clients. Defaults to `true`.
376+
377+
`undoManager.clear(doc)`
378+
Remove operations from the undo and redo stacks.
379+
* `doc` if specified, only the operations on that doc are removed, otherwise all operations are removed.
380+
381+
`undoManager.destroy()`
382+
Remove all operations from the undo and redo stacks, and stop recording new operations.
384383

385384
## Error codes
386385

lib/client/doc.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,7 @@ Doc.prototype._submit = function(op, options, callback) {
680680
if (callback) return callback(err);
681681
return this.emit('error', err);
682682
}
683-
var undoable = options && options.undoable;
684-
var fixUp = options && options.fixUp;
685-
var needsUndoOp = undoable || fixUp || op.needsUndoOp;
683+
var needsUndoOp = options.undoable || options.fixUp || op.needsUndoOp;
686684
if (needsUndoOp && !this.type.invert && !this.type.applyAndInvert) {
687685
var err = new ShareDBError(4025, 'Cannot submit op. OT type does not support invert not applyAndInvert. ' + this.collection + '.' + this.id);
688686
if (callback) return callback(err);

test/client/submit.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ describe('client submit', function() {
598598
});
599599
});
600600

601-
it('transforming pending op by server delete emits error', function(done) {
601+
it('transforming pending op by server delete returns error', function(done) {
602602
var doc = this.backend.connect().get('dogs', 'fido');
603603
var doc2 = this.backend.connect().get('dogs', 'fido');
604604
doc.create({age: 3}, function(err) {
@@ -626,7 +626,7 @@ describe('client submit', function() {
626626
});
627627
});
628628

629-
it('transforming pending op by server create emits error', function(done) {
629+
it('transforming pending op by server create returns error', function(done) {
630630
var doc = this.backend.connect().get('dogs', 'fido');
631631
var doc2 = this.backend.connect().get('dogs', 'fido');
632632
doc.create({age: 3}, function(err) {
@@ -645,6 +645,7 @@ describe('client submit', function() {
645645
});
646646
doc.create({age: 9}, function(err) {
647647
expect(err).ok();
648+
expect(err.code).to.equal(4018);
648649
expect(doc.version).equal(3);
649650
expect(doc.data).eql({age: 5});
650651
calledBack = true;

test/client/undo-redo.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,22 @@ describe('client undo/redo', function() {
12231223
expect(undoManager.canRedo()).to.equal(false);
12241224
});
12251225

1226+
it('destroys UndoManager twice', function() {
1227+
var undoManager = this.connection.createUndoManager({ composeInterval: -1 });
1228+
this.doc.create({ test: 5 });
1229+
this.doc.submitOp([ { p: [ 'test' ], 'na': 2 } ], { undoable: true });
1230+
this.doc.submitOp([ { p: [ 'test' ], 'na': 2 } ], { undoable: true });
1231+
undoManager.undo();
1232+
expect(undoManager.canUndo()).to.equal(true);
1233+
expect(undoManager.canRedo()).to.equal(true);
1234+
undoManager.destroy();
1235+
expect(undoManager.canUndo()).to.equal(false);
1236+
expect(undoManager.canRedo()).to.equal(false);
1237+
undoManager.destroy();
1238+
expect(undoManager.canUndo()).to.equal(false);
1239+
expect(undoManager.canRedo()).to.equal(false);
1240+
});
1241+
12261242
describe('UndoManager.clear', function() {
12271243
it('clears the stacks', function() {
12281244
var undoManager = this.connection.createUndoManager({ composeInterval: -1 });

0 commit comments

Comments
 (0)