Skip to content

Commit

Permalink
Merge pull request persvr#24 from kriszyp/master
Browse files Browse the repository at this point in the history
Several fixes
  • Loading branch information
kriszyp committed Mar 12, 2012
2 parents 12653c8 + 321b1e1 commit 0cd34b9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion store/inherited.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ exports.Inherited = function(store, schemaProperty){
}
};
inheritingStore.query = function(query, directives){
query = query + "&" + encodeURIComponent(schemaProperty) + "=(" + subSchemas[id] + ")";
query = query + "&in(" + encodeURIComponent(schemaProperty) + ",(" + subSchemas[id] + "))";
return store.query(query, directives);
};
inheritingStore.put = function(object, directives){
Expand Down
7 changes: 4 additions & 3 deletions store/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ var Memory = exports.Memory = function(options){
// start with the read-only memory store and add write support
var put = store.put = function(object, directives){
directives = directives || {};
var id = object.id = directives.id || object.id || Math.round(Math.random()*10000000000000);
var id = object.id = "id" in object ? object.id :
"id" in directives ? directives.id : Math.round(Math.random()*10000000000000);
var isNew = !(id in store.index);
if("overwrite" in directives){
if(directives.overwrite){
Expand Down Expand Up @@ -222,8 +223,8 @@ var Persistent = exports.Persistent = function(options) {
if(buffer.charAt(0) == '{'){
buffer = '[' + buffer;
}
if(buffer.substring(buffer.length - 2,buffer.length) == ",\n"){
buffer = buffer.substring(0, buffer.length - 2) + "]";
if(buffer.match(/,\r?\n$/)){
buffer = buffer.replace(/,\r?\n$/,']');
}
try{
var data = eval(buffer);
Expand Down
5 changes: 2 additions & 3 deletions util/extend-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ function ErrorConstructor(name, superError){
var e = new Error(message);
e.name = name;
var ee = Object.create(ExtendedError.prototype);
for(var i in e){
ee[i] = e[i];
}
ee.stack = e.stack;
ee.message = e.message;
return ee;
}
ExtendedError.prototype = Object.create(superError.prototype);
Expand Down
11 changes: 6 additions & 5 deletions util/json-ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,16 @@ exports.stringify = ({}).toSource ?

// Is the value an array?

if (Object.prototype.toString.apply(value) === '[object Array]') {
if (value.forEach) {

// The value is an array. Stringify every element. Use null as a placeholder
// The value is an array (or forEach-able). Stringify every element. Use null as a placeholder
// for non-JSON values.

length = value.length;
for (i = 0; i < length; i += 1) {
partial[i] = str(i, value) || 'null';
}
// TODO: properly handle async forEach
value.forEach(function(value, i){
partial[i] = str(i, value) || 'null';
});

// Join all of the elements together, separated with commas, and wrap them in
// brackets.
Expand Down

0 comments on commit 0cd34b9

Please sign in to comment.