Skip to content

Commit

Permalink
exec -> apply
Browse files Browse the repository at this point in the history
  • Loading branch information
michael committed Jul 9, 2013
1 parent 235938b commit b70def5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 46 deletions.
22 changes: 11 additions & 11 deletions data.js
Expand Up @@ -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
Expand All @@ -329,25 +329,25 @@ 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.
// --------
// 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();

Expand All @@ -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).
Expand All @@ -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) {
Expand Down Expand Up @@ -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]);
}
}

Expand Down Expand Up @@ -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);
};

Expand Down
52 changes: 26 additions & 26 deletions tests/001-data-graph.js
Expand Up @@ -148,39 +148,39 @@ 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",
val: "foo",
arr: ["bla","blupp"]
}));

this.graph.exec(Data.Graph.Create({
this.graph.apply(Data.Graph.Create({
id: "the_numbers",
type: "numbers",
name: "Numbers",
val: 11,
arr: [1,2,3]
}));

this.graph.exec(Data.Graph.Create({
this.graph.apply(Data.Graph.Create({
id: "the_booleans",
type: "booleans",
name: "Booleans",
val: true,
arr: [false, true]
}));

this.graph.exec(Data.Graph.Create({
this.graph.apply(Data.Graph.Create({
id: "the_dates",
type: "dates",
name: "Dates",
val: new Date(1000),
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",
Expand Down Expand Up @@ -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);
Expand All @@ -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);
},

Expand All @@ -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);

Expand All @@ -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));
},

Expand All @@ -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);
},

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -375,23 +375,23 @@ 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);
},

"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);
},

"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);
Expand All @@ -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());
Expand All @@ -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"
Expand All @@ -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);
Expand 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);
Expand Down Expand Up @@ -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));
},

Expand Down Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions tests/002-versioned-graph.js
Expand Up @@ -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);
Expand All @@ -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]);
Expand Down

0 comments on commit b70def5

Please sign in to comment.