From b70def5e86c9a826ec88a57e38528ab6392efe55 Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 9 Jul 2013 21:42:21 +0200 Subject: [PATCH] exec -> apply --- data.js | 22 +++++++-------- tests/001-data-graph.js | 52 ++++++++++++++++++------------------ tests/002-versioned-graph.js | 18 ++++++------- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/data.js b/data.js index e3de9ed..ac3510e 100644 --- a/data.js +++ b/data.js @@ -313,7 +313,7 @@ Data.Graph.__prototype__ = function() { // Only properties that are specified in the schema are taken. this.create = function(node) { - this.exec(Data.Graph.Create(node)); + this.apply(Data.Graph.Create(node)); }; // Removes a node with given id @@ -329,7 +329,7 @@ Data.Graph.__prototype__ = function() { fullPath = fullPath.concat(path).concat(key); } - return this.exec(fullPath); + return this.apply(fullPath); }; // Updates the property with a given operation. @@ -337,17 +337,17 @@ Data.Graph.__prototype__ = function() { // Note: the diff has to be given as an appropriate operation. this.update = function(path, diff) { - this.exec(Data.Graph.Update(path, diff)); + this.apply(Data.Graph.Update(path, diff)); }; // Sets the property to a given value // -------- this.set = function(path, value) { - this.exec(Data.Graph.Set(path, value)); + this.apply(Data.Graph.Set(path, value)); }; - this.__exec__ = function(op) { + this.__apply__ = function(op) { op.apply(this.objectAdapter); this.updated_at = new Date(); @@ -357,10 +357,10 @@ Data.Graph.__prototype__ = function() { this.trigger('graph:changed', op, this); }; - // Executes a graph command + // Applies a graph command // -------- - this.exec = function(command) { + this.apply = function(command) { // Note: all Graph commands are converted to ObjectOperations // which get applied on this graph instance (via ObjectAdapter). @@ -372,7 +372,7 @@ Data.Graph.__prototype__ = function() { op = command; } - this.__exec__(op); + this.__apply__(op); // do not record changes during initialization if (!this.__is_initializing__ && this.isVersioned) { @@ -453,7 +453,7 @@ Data.Graph.__prototype__ = function() { if (this.__seed__) { for (var idx = 0; idx < this.__seed__.length; idx++) { - this.exec(this.__seed__[idx]); + this.apply(this.__seed__[idx]); } } @@ -1174,10 +1174,10 @@ var ChronicleAdapter = function(graph) { ChronicleAdapter.__prototype__ = function() { this.apply = function(op) { - // Note: we call the Graph.exec intentionally, as the chronicled change + // Note: we call the Graph.apply intentionally, as the chronicled change // should be an ObjectOperation //console.log("ChronicleAdapter.apply, op=", op); - this.graph.__exec__(op); + this.graph.__apply__(op); this.graph.updated_at = new Date(op.timestamp); }; diff --git a/tests/001-data-graph.js b/tests/001-data-graph.js index d944d8f..4c71ae8 100644 --- a/tests/001-data-graph.js +++ b/tests/001-data-graph.js @@ -148,7 +148,7 @@ test.fixture2 = function() { test.fixture3 = function() { this.fixture2(); - this.graph.exec(Data.Graph.Create({ + this.graph.apply(Data.Graph.Create({ id: "the_strings", type: "strings", name: "Strings", @@ -156,7 +156,7 @@ test.fixture3 = function() { arr: ["bla","blupp"] })); - this.graph.exec(Data.Graph.Create({ + this.graph.apply(Data.Graph.Create({ id: "the_numbers", type: "numbers", name: "Numbers", @@ -164,7 +164,7 @@ test.fixture3 = function() { arr: [1,2,3] })); - this.graph.exec(Data.Graph.Create({ + this.graph.apply(Data.Graph.Create({ id: "the_booleans", type: "booleans", name: "Booleans", @@ -172,7 +172,7 @@ test.fixture3 = function() { arr: [false, true] })); - this.graph.exec(Data.Graph.Create({ + this.graph.apply(Data.Graph.Create({ id: "the_dates", type: "dates", name: "Dates", @@ -180,7 +180,7 @@ test.fixture3 = function() { arr: [new Date(1000),new Date(2000)] })); - this.graph.exec(Data.Graph.Create({ + this.graph.apply(Data.Graph.Create({ id: "the_custom", type: "custom", name: "Custom", @@ -275,7 +275,7 @@ test.actions = [ arr: [1,2,3] }; var op = Data.Graph.Create(node); - this.graph.exec(op); + this.graph.apply(op); // the node should be accessible via id now var newNode = this.graph.get(node.id); @@ -300,14 +300,14 @@ test.actions = [ "Graph: create - 'id' and 'type' are mandatory", function() { var op = Data.Graph.Create({}); assert.exception(function() { - this.graph.exec(op); + this.graph.apply(op); }, this); }, "Graph: create - 'type' must be defined in schema", function() { var op = Data.Graph.Create({id: "aaa", type: "unknown_type"}); assert.exception(function() { - this.graph.exec(op); + this.graph.apply(op); }, this); }, @@ -317,7 +317,7 @@ test.actions = [ type: "numbers", }; var op = Data.Graph.Create(node); - this.graph.exec(op); + this.graph.apply(op); var newNode = this.graph.get(node.id); @@ -329,7 +329,7 @@ test.actions = [ "Graph: delete", function() { var id = "n1"; var op = Data.Graph.Delete(this.graph.get(id)); - this.graph.exec(op); + this.graph.apply(op); assert.isUndefined(this.graph.get(id)); }, @@ -340,8 +340,8 @@ test.actions = [ }; var op = Data.Graph.Create(node); assert.exception(function() { - this.graph.exec(op); - this.graph.exec(op); + this.graph.apply(op); + this.graph.apply(op); }, this); }, @@ -357,7 +357,7 @@ test.actions = [ var valueUpdate = Operator.TextOperation.fromOT("bar", [1, -1, "e", 1, "ry"]); var propertyUpdate = Operator.ObjectOperation.Update(["a", "foo"], valueUpdate); var nodeUpdate = Data.Graph.Update(["the_custom", "val"], propertyUpdate); - this.graph.exec(nodeUpdate); + this.graph.apply(nodeUpdate); var custom = this.graph.get("the_custom"); assert.isEqual("berry", custom.val.a.foo); @@ -366,7 +366,7 @@ test.actions = [ "Graph: update 'array'", function() { var propertyUpdate = Operator.ArrayOperation.Insert(3, 4); var nodeUpdate = Data.Graph.Update(["the_numbers", "arr"], propertyUpdate); - this.graph.exec(nodeUpdate); + this.graph.apply(nodeUpdate); var numbers = this.graph.get("the_numbers"); assert.isArrayEqual([1,2,3,4], numbers.arr); @@ -375,7 +375,7 @@ test.actions = [ "Graph: update 'string'", function() { var propertyUpdate = Operator.TextOperation.fromOT("foo", [3, "tball"]); var nodeUpdate = Data.Graph.Update(["the_strings", "val"], propertyUpdate); - this.graph.exec(nodeUpdate); + this.graph.apply(nodeUpdate); var strings = this.graph.get("the_strings"); assert.isEqual("football", strings.val); @@ -383,7 +383,7 @@ test.actions = [ "Graph: update 'number'", function() { var nodeUpdate = Data.Graph.Set(["the_numbers", "val"], 42); - this.graph.exec(nodeUpdate); + this.graph.apply(nodeUpdate); var numbers = this.graph.get("the_numbers"); assert.isEqual(42, numbers.val); @@ -391,7 +391,7 @@ test.actions = [ "Graph: update 'boolean'", function() { var nodeUpdate = Data.Graph.Set(["the_booleans", "val"], false); - this.graph.exec(nodeUpdate); + this.graph.apply(nodeUpdate); var booleans = this.graph.get("the_booleans"); assert.isEqual(false, booleans.val); @@ -400,7 +400,7 @@ test.actions = [ "Graph: update 'date'", function() { var date = new Date(1111); var nodeUpdate = Data.Graph.Set(["the_dates", "val"], date); - this.graph.exec(nodeUpdate); + this.graph.apply(nodeUpdate); var dates = this.graph.get("the_dates"); assert.isEqual(date.getTime(), dates.val.getTime()); @@ -411,12 +411,12 @@ test.actions = [ }, "Indexes: created nodes should be added to indexes", function() { - this.graph.exec(Data.Graph.Create({ + this.graph.apply(Data.Graph.Create({ id: "foo1", type: "foo", category: "bla" })); - this.graph.exec(Data.Graph.Create({ + this.graph.apply(Data.Graph.Create({ id: "bar1", type: "bar", category: "blupp" @@ -439,7 +439,7 @@ test.actions = [ }, "Indexes: deleted nodes should be removed from indexes", function() { - this.graph.exec(Data.Graph.Delete(this.graph.get("foo1"))); + this.graph.apply(Data.Graph.Delete(this.graph.get("foo1"))); var all = getIds(this.graph.find("all")); assert.isArrayEqual(["bar1"], all); @@ -458,7 +458,7 @@ test.actions = [ }, "Indexes: updates of indexed properties should update indexes", function() { - this.graph.exec(Data.Graph.Set(["bar1", "category"], "bla")); + this.graph.apply(Data.Graph.Set(["bar1", "category"], "bla")); assert.isArrayEqual(["bar1"], this.graph.indexes.all); assert.isArrayEqual([], this.graph.indexes.foos); assert.isArrayEqual(["bar1"], this.graph.indexes.bars); @@ -498,19 +498,19 @@ test.actions = [ var path = ["c1", "items"]; this.graph.delete(path, "i2"); assert.isArrayEqual(["i1", "i3"], this.graph.get(path)); - this.graph.exec(["delete"].concat(path).concat("i3")); + this.graph.apply(["delete"].concat(path).concat("i3")); assert.isArrayEqual(["i1"], this.graph.get(path)); }, "Data.Array.Push: ", function() { var path = ["c1", "items"]; - this.graph.exec(["push", "c1", "items", "i2"]); + this.graph.apply(["push", "c1", "items", "i2"]); assert.isArrayEqual(["i1", "i2"], this.graph.get(path)); }, "Data.Array.Pop: ", function() { var path = ["c1", "items"]; - this.graph.exec(["pop", "c1", "items"]); + this.graph.apply(["pop", "c1", "items"]); assert.isArrayEqual(["i1"], this.graph.get(path)); }, @@ -579,7 +579,7 @@ test.actions = [ Data.Graph.Set(["the_strings", "val"], "bla"), Data.Graph.Update(["the_strings", "val"], Operator.TextOperation.Insert(0, "bla")), ]; - this.graph.exec(Data.Graph.Compound(this.graph, ops)); + this.graph.apply(Data.Graph.Compound(this.graph, ops)); assert.isEqual(1, called_set); assert.isEqual(1, called_update); diff --git a/tests/002-versioned-graph.js b/tests/002-versioned-graph.js index 236c95e..b7d2fd8 100644 --- a/tests/002-versioned-graph.js +++ b/tests/002-versioned-graph.js @@ -216,49 +216,49 @@ test.actions = [ this.CHECKS["ROOT"](); - this.graph.exec(OP1); + this.graph.apply(OP1); this.ID.push(this.chronicle.getState()); this.CHECKS[_.last(this.ID)] = check = function() { assert.isArrayEqual(["content", "figures"], self.graph.get("document").views); }; check(); - this.graph.exec(OP2); + this.graph.apply(OP2); this.ID.push(this.chronicle.getState()); this.CHECKS[_.last(this.ID)] = check = function() { assert.isArrayEqual([], self.graph.get("content").nodes); }; check(); - this.graph.exec(OP3); + this.graph.apply(OP3); this.ID.push(this.chronicle.getState()); this.CHECKS[_.last(this.ID)] = check = function() { assert.isEqual("Heading 1", self.graph.get("h1").content); }; check(); - this.graph.exec(OP4); + this.graph.apply(OP4); this.ID.push(this.chronicle.getState()); this.CHECKS[_.last(this.ID)] = check = function() { assert.isArrayEqual(["h1"], self.graph.get("content").nodes); }; check(); - this.graph.exec(OP5); + this.graph.apply(OP5); this.ID.push(this.chronicle.getState()); this.CHECKS[_.last(this.ID)] = check = function() { assert.isEqual("This is text1.", self.graph.get("text1").content); }; check(); - this.graph.exec(OP6); + this.graph.apply(OP6); this.ID.push(this.chronicle.getState()); this.CHECKS[_.last(this.ID)] = check = function() { assert.isArrayEqual(["h1", "text1"], self.graph.get("content").nodes); }; check(); - this.graph.exec(OP7); + this.graph.apply(OP7); this.ID.push(this.chronicle.getState()); this.CHECKS[_.last(this.ID)] = check = function() { assert.isArrayEqual(["text1", "h1"], self.graph.get("content").nodes); @@ -279,9 +279,9 @@ test.actions = [ "Merge", function() { this.chronicle.open(this.ID[4]); - this.graph.exec(OP8); + this.graph.apply(OP8); this.ID.push(this.chronicle.getState()); - this.graph.exec(OP9); + this.graph.apply(OP9); this.ID.push(this.chronicle.getState()); this.chronicle.open(this.ID[7]);