Skip to content

Commit

Permalink
Merge pull request coresmart#82 from doo/events_on_add
Browse files Browse the repository at this point in the history
Duplicate events for QueryCollection.prototype.add()
  • Loading branch information
Zef Hemel committed Feb 25, 2012
2 parents 3856057 + 4f01c5c commit 37ad075
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions lib/persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,25 +149,15 @@ persistence.get = function(arg1, arg2) {
}
}

persistence.objectAdded = function(obj) {
persistence.objectChanged(obj, ['add', 'change']);
}

persistence.objectRemoved = function(obj) {
persistence.objectChanged(obj, ['change']);
}

persistence.objectChanged = function(obj, events) {
var entityName = obj._type;
if(this.queryCollectionCache[entityName]) {
var colls = this.queryCollectionCache[entityName];
for(var key in colls) {
if(colls.hasOwnProperty(key)) {
var coll = colls[key];
if(coll._filter.match(obj)) { // matched the filter -> part of collection
for(var i = 0; i < events.length; i++) {
coll.triggerEvent(events[i], coll, obj);
}
if(coll._filter.match(obj)) { // matched the filter -> was part of collection
coll.triggerEvent('change', coll, obj);
}
}
}
Expand Down Expand Up @@ -272,7 +262,6 @@ persistence.get = function(arg1, arg2) {
if (!this.trackedObjects[obj.id]) {
this.trackedObjects[obj.id] = obj;
if(obj._new) {
this.objectAdded(obj);
for(var p in obj._data) {
if(obj._data.hasOwnProperty(p)) {
this.propertyChanged(obj, p, undefined, obj._data[p]);
Expand Down

0 comments on commit 37ad075

Please sign in to comment.