Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions facet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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"){
Expand All @@ -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;
}
Expand Down
42 changes: 30 additions & 12 deletions store/notifying.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,36 @@ 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){
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;
}

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: "put"
type: directives && directives.overwrite === false ? "add" : "put"
});
return id;
});
Expand All @@ -57,15 +63,21 @@ 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;
}
}

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: "put"
type: "add"
});
return id;
});
Expand All @@ -74,12 +86,18 @@ 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;
}

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