Permalink
Browse files

Data.Graph#set now takes just one parameter, the id is specified as _…

…id and optional. Fixes #18.
  • Loading branch information...
Michael Aufreiter
Michael Aufreiter committed Jun 20, 2011
1 parent d92f5ea commit 7d81ae21598f4d6a578109f9baa7e62ab60fa275
Showing with 52 additions and 21 deletions.
  1. +0 −1 .gitignore
  2. +33 −0 CHANGELOG
  3. +16 −16 data.js
  4. +1 −1 package.json
  5. +2 −3 test/testsuite.js
View
@@ -13,6 +13,5 @@ coverage/*
_Yardoc
.yardoc
tmp/*
-CHANGELOG
README.bak
node_modules
View
@@ -0,0 +1,33 @@
+0.4.0
+=============
+ * Data.Graph#set now takes just one parameter, the id is specified as _id and optional
+
+0.3.1
+=============
+ * Added Data.Hash#range
+ * Fixed an issue with Data.Graph#merge
+
+0.3.0
+=============
+ * Listen for node updates in realtime
+ * Data.Graph#find now accepts an array of queries
+ * Index queries against CouchDB
+ * Completely rewritten CouchAdapter
+
+0.2.2
+=============
+
+ * Updated Data.Graph#fetch
+ - options are now optional
+ - returns a Data.Hash of fetched objects
+ * Added Data.Hash#difference
+ * Added Data.Hash#rest
+ * Data.Graph#merge is now chainable
+
+0.2.1
+=============
+
+ * Added Data.Collection#find
+ * Added Data.Collection#filter
+ * Added ALL-OF operator &=
+ * ANY-OF operator now also works with unique properties
View
32 data.js
@@ -20,7 +20,7 @@
}
// Current version of the library. Keep in sync with `package.json`.
- Data.VERSION = '0.3.0';
+ Data.VERSION = '0.4.0-pre';
// Require Underscore, if we're on the server, and it's not already present.
var _ = this._;
@@ -1001,7 +1001,7 @@
if (!this.data) throw new Error('Object has no data, and cannot be built');
// Pull off _id and _rev properties
- delete this.data._id;
+ // delete this.data._id;
this._rev = this.data._rev; // delete this.data._rev;
this._conflicted = this.data._conflicted;
this._deleted = this.data._deleted; // delete this.data._deleted;
@@ -1027,7 +1027,6 @@
}
});
});
-
if (this.dirty) this.g.trigger('dirty');
},
@@ -1262,28 +1261,29 @@
});
return this;
},
-
- // Set (add) a new node on the graph
- set: function(id, properties) {
- var that = this;
- var types = _.isArray(properties.type) ? properties.type : [properties.type];
- if (arguments.length === 2) {
- id = id ? id : Data.uuid('/' + _.last(_.last(types).split('/')) + '/');
+
+ set: function(node) {
+ var id, that = this;
+
+ // Backward compatibility
+ if (arguments.length === 2) node = _.extend(arguments[1], {_id: arguments[0]});
+
+ var types = _.isArray(node.type) ? node.type : [node.type];
+ if (arguments.length <= 2) {
+ node._id = node._id ? node._id : Data.uuid('/' + _.last(_.last(types).split('/')) + '/');
// Recycle existing object if there is one
- var res = that.get(id) ? that.get(id) : new Data.Object(that, id, properties, true);
- res.data = properties;
+ var res = that.get(node._id) ? that.get(node._id) : new Data.Object(that, node._id, _.clone(node), true);
+ res.data = node;
res.dirty = true;
res.build();
- this.set('objects', id, res);
- return this.get('objects', id);
+ this.set('objects', node._id, res);
+ return res;
} else { // Delegate to Data.Node#set
return Data.Node.prototype.set.call(this, arguments[0], arguments[1], arguments[2]);
}
},
// API method for accessing objects in the graph space
- // TODO: Ask the datastore if the node is not known in the local graph
- // use async method queues for this!
get: function(id) {
if (arguments.length === 1) {
return this.get('objects', id);
View
@@ -8,5 +8,5 @@
"dependencies" : ["underscore", "now"],
"lib" : ".",
"main" : "index",
- "version" : "0.3.0"
+ "version" : "0.4.0-pre"
}
View
@@ -422,7 +422,6 @@ stanford = graph.get('/location/stanford');
newYork = graph.get('/location/new_york');
-
module("Data.Graph", {
setup: function() {
// graph = new Data.Graph(documents_fixture);
@@ -548,8 +547,8 @@ test("Value identity", function() {
// Set new nodes on the graph
test("Set new nodes on the graph", function() {
-
- var substance = graph.set('/document/substance', {
+ var substance = graph.set({
+ "_id": "/document/substance",
"type": "/type/document",
"title": "Substance Introduction",
"authors": ["Michael Aufreiter"],

1 comment on commit 7d81ae2

@nikgraf

This comment has been minimized.

Show comment Hide comment
@nikgraf

nikgraf Jun 20, 2011

like!

like!

Please sign in to comment.