Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updates for change filter

  • Loading branch information...
commit d14922c47064579b1e85e5768a9b26a52b806423 1 parent 5892f36
@robrobbins robrobbins authored
View
33 build/debug/sudo-x.js
@@ -1665,23 +1665,40 @@ sudo.delegates.Change = function(data) {
};
// Delegates inherit from Model
sudo.delegates.Change.prototype = Object.create(sudo.Model.prototype);
+// ###addFilter
+// Place an entry into this object's hash of filters
+//
+// `param` {string} `key`
+// `param` {string} `val`
+// `returns` {object} this
+sudo.delegates.Change.prototype.addFilter = function addFilter(key, val) {
+ this.get('filters')[key] = val;
+ return this;
+},
+// ###filter
// Change records are delivered here and filtered, calling any matching
// methods specified in `this.get('filters').
//
// `returns` {Object} a call to the specified _delegator_ method, passing
// a hash containing:
// 1. the `type` of Change
-// 2. the value located at the key/path
-// 3. the `oldValue` of the key if present
-sudo.delegates.Change.prototype.filter = function(change) {
- var filters = this.data.filters, name = change.name, obj = {};
+// 2. the `name` of the changed property
+// 3. the value located at the key/path
+// 4. the `oldValue` of the key if present
+sudo.delegates.Change.prototype.filter = function filter(change) {
+ var filters = this.data.filters, name = change.name,
+ type = change.type, obj = {};
// does my delegator care about this?
if(name in filters && filters.hasOwnProperty(name)) {
// assemble the object to return to the method
- obj.type = change.type;
- obj.value = name.indexOf('.') === -1 ? change.object[change.name] :
- sudo.getPath(name, change.object);
+ obj.type = type;
+ obj.name = name;
obj.oldValue = change.oldValue;
+ // delete operations will not have any value so no need to look
+ if(type !== 'deleted') {
+ obj.value = name.indexOf('.') === -1 ? change.object[change.name] :
+ sudo.getPath(name, change.object);
+ }
return this.delegator[filters[name]].call(this.delegator, obj);
}
};
@@ -1729,7 +1746,7 @@ sudo.delegates.Data.prototype.filter = function(obj) {
// `private`
sudo.delegates.Data.prototype.role = 'data';
-sudo.version = "0.9.3";
+sudo.version = "0.9.4";
window.sudo = sudo;
if(typeof window._ === "undefined") window._ = sudo;
}).call(this, this);
View
2  build/debug/sudo.js
@@ -811,7 +811,7 @@ sudo.extensions.observable = {
return this.deliverChangeRecords();
}
};
-sudo.version = "0.9.3";
+sudo.version = "0.9.4";
window.sudo = sudo;
if(typeof window._ === "undefined") window._ = sudo;
}).call(this, this);
View
31 extras/delegates/change/change.js
@@ -13,23 +13,40 @@ sudo.delegates.Change = function(data) {
};
// Delegates inherit from Model
sudo.delegates.Change.prototype = Object.create(sudo.Model.prototype);
+// ###addFilter
+// Place an entry into this object's hash of filters
+//
+// `param` {string} `key`
+// `param` {string} `val`
+// `returns` {object} this
+sudo.delegates.Change.prototype.addFilter = function addFilter(key, val) {
+ this.get('filters')[key] = val;
+ return this;
+},
+// ###filter
// Change records are delivered here and filtered, calling any matching
// methods specified in `this.get('filters').
//
// `returns` {Object} a call to the specified _delegator_ method, passing
// a hash containing:
// 1. the `type` of Change
-// 2. the value located at the key/path
-// 3. the `oldValue` of the key if present
-sudo.delegates.Change.prototype.filter = function(change) {
- var filters = this.data.filters, name = change.name, obj = {};
+// 2. the `name` of the changed property
+// 3. the value located at the key/path
+// 4. the `oldValue` of the key if present
+sudo.delegates.Change.prototype.filter = function filter(change) {
+ var filters = this.data.filters, name = change.name,
+ type = change.type, obj = {};
// does my delegator care about this?
if(name in filters && filters.hasOwnProperty(name)) {
// assemble the object to return to the method
- obj.type = change.type;
- obj.value = name.indexOf('.') === -1 ? change.object[change.name] :
- sudo.getPath(name, change.object);
+ obj.type = type;
+ obj.name = name;
obj.oldValue = change.oldValue;
+ // delete operations will not have any value so no need to look
+ if(type !== 'deleted') {
+ obj.value = name.indexOf('.') === -1 ? change.object[change.name] :
+ sudo.getPath(name, change.object);
+ }
return this.delegator[filters[name]].call(this.delegator, obj);
}
};
View
7 extras/delegates/change/spec/change.spec.js
@@ -42,6 +42,13 @@ describe('Sudo Change Delegate', function() {
expect(spy).not.toHaveBeenCalled();
});
+ it('observes unset', function() {
+ model.setPath('is.messiah', true);
+ var spy = spyOn(view, 'denyDivinity');
+ model.unsetPath('is.messiah');
+ expect(spy).toHaveBeenCalled();
+ });
+
it('removes a delegate', function() {
var del = view.delegate('change');
view.removeDelegate('change');
Please sign in to comment.
Something went wrong with that request. Please try again.