Skip to content

Commit 7b5d698

Browse files
author
Thomas Scholtes
committed
Add testing OT type
The previously failing tests used this type.
1 parent 016406a commit 7b5d698

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
*.swp
22
.DS_Store
3-
test/*.js
4-
test/**/*.js
53
node_modules
64
webclient/*

test/support/ot_number.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Simple OT representing a number.
3+
*
4+
* Snapshots and operations are just integers. Applying an operation to an
5+
* integer corresponds to adding the number. It supports inversion.
6+
*
7+
* It is used mainly for testing
8+
*/
9+
module.exports = {
10+
name: 'simple-number',
11+
uri: 'http://sharejs.org/types/simple-number',
12+
13+
/**
14+
* Creates snapshot with initial data
15+
*
16+
* @param {Number} [initial=0]
17+
* @return {Number}
18+
*/
19+
create: function(initial) {
20+
if (initial == null)
21+
initial = 0;
22+
return initial;
23+
},
24+
25+
/**
26+
* Apply an operation to a snapshot and return new snapshot.
27+
*/
28+
apply: function(snapshot, op) {
29+
return snapshot + op;
30+
},
31+
32+
/**
33+
* Compose operations
34+
*/
35+
transform: function(op1, op2) {
36+
return op1 + op2;
37+
},
38+
39+
invert: function(operation) {
40+
return -operation;
41+
},
42+
43+
/**
44+
* Mixin to manipulate snapshots
45+
*
46+
* The receiver of this mixin must implement getSnapshot() and
47+
* submitOp(operation, [callback]).
48+
*/
49+
api: {
50+
get: function() { return this.getSnapshot() },
51+
add: function(value, callback) {
52+
return this.submitOp(value, callback);
53+
}
54+
}
55+
};
56+

0 commit comments

Comments
 (0)