count.coffee 684 B

12345678910111213141516171819202122
  1. # This is a simple type used for testing other OT code. Each op is [expectedSnapshot, increment]
  2. exports.name = 'count'
  3. exports.create = -> 1
  4. exports.apply = (snapshot, op) ->
  5. [v, inc] = op
  6. throw new Error "Op #{v} != snapshot #{snapshot}" unless snapshot == v
  7. snapshot + inc
  8. # transform op1 by op2. Return transformed version of op1.
  9. exports.transform = (op1, op2) ->
  10. throw new Error "Op1 #{op1[0]} != op2 #{op2[0]}" unless op1[0] == op2[0]
  11. [op1[0] + op2[1], op1[1]]
  12. exports.compose = (op1, op2) ->
  13. throw new Error "Op1 #{op1} + 1 != op2 #{op2}" unless op1[0] + op1[1] == op2[0]
  14. [op1[0], op1[1] + op2[1]]
  15. exports.generateRandomOp = (doc) ->
  16. [[doc, 1], doc + 1]