From d716975460ca01ba0a20ae39844df96e9cdc6d6c Mon Sep 17 00:00:00 2001 From: ben hockey Date: Fri, 3 Oct 2014 09:41:24 -0500 Subject: [PATCH 1/6] maintain context when wrapping store with notifying --- store/notifying.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/store/notifying.js b/store/notifying.js index 8c5cd49..183cff0 100644 --- a/store/notifying.js +++ b/store/notifying.js @@ -38,9 +38,9 @@ exports.Notifying = function(store, options){ if(originalPut){ store.put= function(object, directives){ if(options && options.revisionProperty){ - object[options.revisionProperty] = (object[options.revisionProperty] || 0) + 1; + object[options.revisionProperty] = (object[options.revisionProperty] || 0) + 1; } - var result = originalPut(object, directives) || object.id; + var result = originalPut.call(this, object, directives) || object.id; if(directives && directives.replicated){ return result; } @@ -57,10 +57,10 @@ exports.Notifying = function(store, options){ var originalAdd = store.add; if(originalAdd){ store.add= function(object, directives){ - var result = originalAdd(object, directives) || object.id; + var result = originalAdd.call(this, object, directives) || object.id; if(directives && directives.replicated){ return result; - } + } return when(result, function(id){ localHub.publish({ channel: id, @@ -74,7 +74,7 @@ exports.Notifying = function(store, options){ var originalDelete = store["delete"]; if(originalDelete){ store["delete"] = function(id, directives){ - var result = originalDelete(id, directives); + var result = originalDelete.call(this, id, directives); if(directives && directives.replicated){ return result; } From 064f28f643186c880aa8c68b30bfb089cc074772 Mon Sep 17 00:00:00 2001 From: ben hockey Date: Thu, 20 Nov 2014 16:25:23 -0600 Subject: [PATCH 2/6] clear partial any time a new object has been saved --- facet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/facet.js b/facet.js index 49949c1..0ff65a7 100644 --- a/facet.js +++ b/facet.js @@ -419,7 +419,6 @@ var SchemaControlled = function(facetSchema, sourceClass, permissive){ mustBeValid(validation); var isNew = partial === NEW; if(isNew && (typeof facetSchema.add === "function")){ // || ) - partial = undefined; id = facetSchema.add(source, directives); } else if(typeof facetSchema.put === "function"){ @@ -446,6 +445,7 @@ var SchemaControlled = function(facetSchema, sourceClass, permissive){ }*/ return when(id, function(id){ if(isNew){ + partial = undefined; if((typeof id == "string" || typeof id == "number") && promiseModule.currentContext){ promiseModule.currentContext.generatedId = id; } From 9cb4fa6bc61d32c7456c4c2f96355f95c8c4c8a5 Mon Sep 17 00:00:00 2001 From: ben hockey Date: Sat, 10 Jan 2015 14:33:14 -0600 Subject: [PATCH 3/6] assign allowedOperators to constructor --- facet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/facet.js b/facet.js index 0ff65a7..6b72f65 100644 --- a/facet.js +++ b/facet.js @@ -98,7 +98,7 @@ function FacetedStore(store, facetSchema){ return this.wrap(facetSchema.query(query, directives), this.transaction); }; - var allowedOperators = constructor.allowedOperators || store.allowedOperators + var allowedOperators = constructor.allowedOperators = store.allowedOperators || { select: true, limit: true, // required From 51ea62c1e171260f429420a5c69f5ecdb0205792 Mon Sep 17 00:00:00 2001 From: ben hockey Date: Sat, 10 Jan 2015 14:39:32 -0600 Subject: [PATCH 4/6] set maxLimit rather than try to read it --- facet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/facet.js b/facet.js index 6b72f65..cf3eac3 100644 --- a/facet.js +++ b/facet.js @@ -111,7 +111,7 @@ function FacetedStore(store, facetSchema){ gt: "indexed", sort: "indexed" }; - var maxLimit = constructor.maxLimit || store.maxLimit || 50; + var maxLimit = constructor.maxLimit = store.maxLimit || 50; constructor.checkQuery = function(query){ var lastLimit; From 0b5a3943b5a3c726b44fae07350e7e6c3cb8d129 Mon Sep 17 00:00:00 2001 From: ben hockey Date: Fri, 7 Nov 2014 16:21:09 -0600 Subject: [PATCH 5/6] use "add" topic for notifying store --- store/notifying.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/store/notifying.js b/store/notifying.js index 183cff0..ec3628b 100644 --- a/store/notifying.js +++ b/store/notifying.js @@ -25,14 +25,14 @@ exports.Notifying = function(store, options){ if(directives && directives['client-id']){ clientHub = hub.fromClient(directives['client-id']); } - return clientHub.subscribe(path, /*directives.body || */["put", "delete"]); + return clientHub.subscribe(path, /*directives.body || */["add", "put", "delete"]); }; store.unsubscribe = function(path, directives){ var clientHub = hub; if(directives && directives['client-id']){ clientHub = hub.fromClient(directives['client-id']); } - return clientHub.unsubscribe(path, ["put", "delete"]); + return clientHub.unsubscribe(path, ["add", "put", "delete"]); }; var originalPut = store.put; if(originalPut){ @@ -48,7 +48,7 @@ exports.Notifying = function(store, options){ localHub.publish({ channel: id, result: object, - type: "put" + type: directives && directives.overwrite === false ? "add" : "put" }); return id; }); @@ -65,7 +65,7 @@ exports.Notifying = function(store, options){ localHub.publish({ channel: id, result: object, - type: "put" + type: "add" }); return id; }); From 6fbf207d739bcf94f8b477f9c64ab5285cfcd12b Mon Sep 17 00:00:00 2001 From: ben hockey Date: Thu, 15 Jan 2015 18:17:11 -0600 Subject: [PATCH 6/6] publish from the client hub to suppress echo --- store/notifying.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/store/notifying.js b/store/notifying.js index ec3628b..443fe69 100644 --- a/store/notifying.js +++ b/store/notifying.js @@ -44,8 +44,14 @@ exports.Notifying = function(store, options){ if(directives && directives.replicated){ return result; } + + var publishHub = localHub; + if(directives && directives['client-id']){ + publishHub = hub.fromClient(directives['client-id']); + } + return when(result, function(id){ - localHub.publish({ + publishHub.publish({ channel: id, result: object, type: directives && directives.overwrite === false ? "add" : "put" @@ -61,8 +67,14 @@ exports.Notifying = function(store, options){ if(directives && directives.replicated){ return result; } + + var publishHub = localHub; + if(directives && directives['client-id']){ + publishHub = hub.fromClient(directives['client-id']); + } + return when(result, function(id){ - localHub.publish({ + publishHub.publish({ channel: id, result: object, type: "add" @@ -78,8 +90,14 @@ exports.Notifying = function(store, options){ if(directives && directives.replicated){ return result; } + + var publishHub = localHub; + if(directives && directives['client-id']){ + publishHub = hub.fromClient(directives['client-id']); + } + return when(result, function(){ - localHub.publish({ + publishHub.publish({ channel: id, type: "delete" });