Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
support combining names in observe block (e.g. observe { 'foo bar baz…
Browse files Browse the repository at this point in the history
…': 'stuffChanged'})
  • Loading branch information
Scott J. Miles committed Dec 19, 2013
1 parent 1ea451e commit 1a8ace3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/declaration/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

var properties = {
inferObservers: function(prototype) {
// called before prototype.observe is chained to inherited object
var observe = prototype.observe, property;
for (var n in prototype) {
if (n.slice(-7) === 'Changed') {
Expand All @@ -19,13 +20,32 @@
observe[property] = observe[property] || n;
}
}
this.explodeObservers(prototype);
},
explodeObservers: function(prototype) {
// called before prototype.observe is chained to inherited object
var o = prototype.observe;
if (o) {
var exploded = {};
for (var n in o) {
var names = n.split(' ');
for (var i=0, ni; ni=names[i]; i++) {
exploded[ni] = o[n];
}
}
prototype.observe = exploded;
}
},
optimizePropertyMaps: function(prototype) {
if (prototype.observe) {
// construct name list
var a = prototype._observeNames = [];
for (var n in prototype.observe) {
a.push(n);
var names = n.split(' ');
for (var i=0, ni; ni=names[i]; i++) {
a.push(ni);
}
//a.push(n);
}
}
if (prototype.publish) {
Expand Down
1 change: 1 addition & 0 deletions src/declaration/prototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
}
};

// implementation of 'chainObject' depends on support for __proto__
if (Object.__proto__) {
prototype.chainObject = function(object, inherited) {
if (object && inherited && object !== inherited) {
Expand Down

0 comments on commit 1a8ace3

Please sign in to comment.