Permalink
Browse files

Add testing OT type

The previously failing tests used this type.
  • Loading branch information...
1 parent 016406a commit 7b5d698a1ebd88a4dde4b293570a34bf6daaf344 @geigerzaehler geigerzaehler committed Oct 1, 2013
Showing with 56 additions and 2 deletions.
  1. +0 −2 .gitignore
  2. +56 −0 test/support/ot_number.js
View
@@ -1,6 +1,4 @@
*.swp
.DS_Store
-test/*.js
-test/**/*.js
node_modules
webclient/*
View
@@ -0,0 +1,56 @@
+/**
+ * Simple OT representing a number.
+ *
+ * Snapshots and operations are just integers. Applying an operation to an
+ * integer corresponds to adding the number. It supports inversion.
+ *
+ * It is used mainly for testing
+ */
+module.exports = {
+ name: 'simple-number',
+ uri: 'http://sharejs.org/types/simple-number',
+
+ /**
+ * Creates snapshot with initial data
+ *
+ * @param {Number} [initial=0]
+ * @return {Number}
+ */
+ create: function(initial) {
+ if (initial == null)
+ initial = 0;
+ return initial;
+ },
+
+ /**
+ * Apply an operation to a snapshot and return new snapshot.
+ */
+ apply: function(snapshot, op) {
+ return snapshot + op;
+ },
+
+ /**
+ * Compose operations
+ */
+ transform: function(op1, op2) {
+ return op1 + op2;
+ },
+
+ invert: function(operation) {
+ return -operation;
+ },
+
+ /**
+ * Mixin to manipulate snapshots
+ *
+ * The receiver of this mixin must implement getSnapshot() and
+ * submitOp(operation, [callback]).
+ */
+ api: {
+ get: function() { return this.getSnapshot() },
+ add: function(value, callback) {
+ return this.submitOp(value, callback);
+ }
+ }
+};
+

0 comments on commit 7b5d698

Please sign in to comment.