Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: danski/spah
base: 424f6915d0
...
head fork: danski/spah
compare: a99c4cecb4
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
2  Spah.sublime-project
@@ -17,7 +17,7 @@
{
"name": "Nodeunit",
"working_dir": "$project_path",
- "cmd": ["nodeunit", "src/Spah-edge.js", "test"]
+ "cmd": ["echo", "$project_path"]//, "src/Spah-edge.js", "test"]
}
]
}
View
12 src/Spah.DOM.Blueprint.js
@@ -46,9 +46,15 @@ Spah.classExtend("Spah.DOM.Blueprint", Spah.DOM.Document, {
*
**/
"compile": function(html, done) {
- var jsdom = require('jsdom').jsdom();
- var contextWindow = jsdom.createWindow();
- var $ = require('jQuery').create(contextWindow);
+ try {
+ var jsdom = require('jsdom').jsdom();
+ var contextWindow = jsdom.createWindow();
+ var $ = require('jQuery').create(contextWindow);
+ }
+ catch(e) {
+ return done(e, null);
+ }
+
// Prepare the event chain
var extractedDocType = "";
View
39 src/Spah.SpahQL.QueryResult.js
@@ -119,26 +119,41 @@ Spah.classCreate("Spah.SpahQL.QueryResult", {
},
/**
- * Spah.SpahQL.QueryResult#set(key, value) -> Boolean
- * - key (Integer, String): The key to set on this object
- * - value (Object): The value to attribute to the given key.
+ * Spah.SpahQL.QueryResult#set(keyOrDict, value) -> Boolean
+ * - keyOrDict (Integer, String, Object): The key to set on this object, or a hash of keys and values that you want to set.
+ * - value (Object): The value to attribute to the given key. Ignored if keyOrDict is a hash.
*
* If this result has an array or object value, modified this result
* by setting the given key to the given value. Returns true if the
* key is set successfully and false if the new value is rejected
* because this result isn't enumerable.
**/
- "set": function(key, value) {
- var k = Spah.SpahQL.DataHelper.coerceKeyForObject(key, this.value);
- if(k != null) {
- if(!Spah.SpahQL.DataHelper.eq(value, this.value[k])) {
- var prev = this.value[k];
- this.value[k] = value;
- this.triggerModificationCallbacks(prev, value, "/"+k);
+ "set": function(keyOrDict, value) {
+ var values;
+ if(Spah.SpahQL.DataHelper.objectType(keyOrDict) == "object") {
+ values = keyOrDict;
+ }
+ else {
+ values = {};
+ values[keyOrDict] = value;
+ }
+
+ for(var hKey in values) {
+ var v = values[hKey];
+ var k = Spah.SpahQL.DataHelper.coerceKeyForObject(hKey, this.value);
+
+ if(k != null) {
+ if(!Spah.SpahQL.DataHelper.eq(v, this.value[k])) {
+ var prev = this.value[k];
+ this.value[k] = v;
+ this.triggerModificationCallbacks(prev, v, "/"+k);
+ }
+ }
+ else {
+ return false;
}
- return true;
}
- return false;
+ return true;
},
/**
View
10 src/Spah.SpahQL.QueryResultSet.js
@@ -152,16 +152,16 @@ Spah.classCreate("Spah.SpahQL.QueryResultSet", {
},
/**
- * Spah.SpahQL.QueryResultSet#set(key, value) -> Boolean
- * - key (Integer, String): The that you want to set.
- * - value (String): The value to which you want that key set.
+ * Spah.SpahQL.QueryResultSet#set(keyOrDict[, value]) -> Boolean
+ * - keyOrDict (Integer, String, Object): The key that you want to set, or a hash of keys and values to set.
+ * - value (String): The value to which you want that key set. Ignored if keyOrDict is a hash.
*
* Calls set(key, value) on the first result in this result set and returns
* the boolean response.
**/
- "set": function(key, value) {
+ "set": function(keyOrDict, value) {
var r = this.first();
- return (r)? r.set(key, value) : false;
+ return (r)? r.set(keyOrDict, value) : false;
},
/**
View
28 src/Spah.State.js
@@ -19,29 +19,17 @@ Spah.classExtend("Spah.State", Spah.SpahQL.QueryResult, {
this.value = data || {};
this.sourceData = this.value;
},
-
+
/**
- * Spah.State#update(delta) -> Object hash of path modifications
- * - delta (Object): a hash to be deep-merged into the existing data construct. Deep merging always occurs at the root of the existing state.
- *
- * Deep-merges a hash of state changes into the current state:
- *
- * myState.data //-> {foo: {chicken: "bkawk", cow: "mooo", cat: "meow"}}
- * myState.update({
- * foo: {
- * chicken: "hello i am a chicken nice to meet you",
- * owl: "hoot",
- * cat: null,
- * }
- * })
- * //-> {"/foo": "~", "/foo/chicken": "~", "/foo/owl": "+", "/foo/cat": "-"}
+ * Spah.State#apply(query, ruleFunc) -> Spah.State
+ * query (String): A SpahQL query limiting the results against which the rule will be run.
+ * ruleFunc (Function): A function to be applied to all matching SpahQL results. Takes an individual QueryResult as the only argument.
*
- * During the merge hashes are merged, while strings, arrays and booleans are replaced if re-specified in the delta.
+ * Applies the given function to all matches for the given SpahQL query, leaving this
+ * instance unchanged and returning a new Spah.State instance with the changes applied.
**/
- "update": function(delta) {
- updates = Spah.SpahQL.DataHelper.merge(delta, this.value);
- this.value = updates.data;
- return updates.modifications;
+ "apply": function(query, ruleFunc) {
+
}
});
View
3  src/build.json
@@ -24,6 +24,7 @@
"Spah.SpahQL.Token.KeyName.js",
"Spah.DOM.Modifiers.js",
"Spah.DOM.Document.js",
- "Spah.DOM.Blueprint.js"
+ "Spah.DOM.Blueprint.js",
+ "Spah.State.js"
]
}
View
11 test/Spah.SpahQL.QueryResult.test.js
@@ -84,6 +84,17 @@ exports["Spah.SpahQL.QueryResult"] = {
test.equal(data["stringtest"], "abc");
test.done();
},
+
+ "May set subkey on self using a k/v hash of values to set": function(test) {
+ setup();
+
+ var res = Spah.SpahQL.select("/foo", data).first();
+ test.ok(res.set({"new1": "val1", "new2": "val2"}));
+
+ test.equal(res.select("/new1").first().value, "val1");
+ test.equal(res.select("/new2").first().value, "val2");
+ test.done();
+ },
"May replace own value on the parent": function(test) {
setup();
View
28 test/Spah.State.test.js
@@ -1,4 +1,32 @@
exports["Spah.State"] = {
+ "Initialises as a root-level query result": function(test) {
+ var data = {"foo": "bar"};
+ var state = new Spah.State(data);
+
+ test.equals(state.path, "/");
+ test.ok(Spah.SpahQL.DataHelper.eq(state.value, data));
+ test.done();
+ },
+
+ "May have a query rule applied to it": function(test) {
+ var data = {
+ "foo": {"bar": "baz", "finangle": "patang"},
+ "bar": "baz"
+ };
+ var expected = {
+ "foo": {"bar": "baz2"},
+ "bar": "baz2"
+ };
+
+ var state = new Spah.State(data);
+ var modifiedState = state.apply("//bar", function(result) {
+ result.replace("baz2");
+ });
+
+ test.ok(Spah.SpahQL.DataHelper.eq(data, state.value))
+ test.ok(Spah.SpahQL.DataHelper.eq(expected, modifiedState.value));
+ test.done();
+ }
};

No commit comments for this range

Something went wrong with that request. Please try again.