Permalink
Browse files

Changing representation of operations to a string where the first cha…

…racter is the operation type
  • Loading branch information...
fitzgen committed Apr 21, 2011
1 parent 30e05ac commit fafde5034c4a3260fe119629b9d3816ad971ee1e
Showing with 16 additions and 5 deletions.
  1. +16 −5 operations.js
View
@@ -14,23 +14,34 @@ define(function () {
// Simple change constructors.
function insert (chars) {
return ["insert", chars];
return "i" + chars;
}
function del (chars) {
return ["delete", chars];
return "d" + chars;
}
function retain (n) {
return ["retain", n];
return "r" + String(n);
}
function type (change) {
return change[0];
switch ( change.charAt(0) ) {
case "r":
return "retain";
case "d":
return "delete";
case "i":
return "insert";
default:
throw new TypeError("Unknown type of change: ", change);
}
}
function val (change) {
return change[1];
return type(change) === "r"
? Number(change.slice(1))
: change.slice(1);
}
// We don't want to copy arrays all the time, aren't mutating lists, and

0 comments on commit fafde50

Please sign in to comment.