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

Commit 1a8ace3

Browse files
author
Scott J. Miles
committed
support combining names in observe block (e.g. observe { 'foo bar baz': 'stuffChanged'})
1 parent 1ea451e commit 1a8ace3

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/declaration/properties.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
var properties = {
1111
inferObservers: function(prototype) {
12+
// called before prototype.observe is chained to inherited object
1213
var observe = prototype.observe, property;
1314
for (var n in prototype) {
1415
if (n.slice(-7) === 'Changed') {
@@ -19,13 +20,32 @@
1920
observe[property] = observe[property] || n;
2021
}
2122
}
23+
this.explodeObservers(prototype);
24+
},
25+
explodeObservers: function(prototype) {
26+
// called before prototype.observe is chained to inherited object
27+
var o = prototype.observe;
28+
if (o) {
29+
var exploded = {};
30+
for (var n in o) {
31+
var names = n.split(' ');
32+
for (var i=0, ni; ni=names[i]; i++) {
33+
exploded[ni] = o[n];
34+
}
35+
}
36+
prototype.observe = exploded;
37+
}
2238
},
2339
optimizePropertyMaps: function(prototype) {
2440
if (prototype.observe) {
2541
// construct name list
2642
var a = prototype._observeNames = [];
2743
for (var n in prototype.observe) {
28-
a.push(n);
44+
var names = n.split(' ');
45+
for (var i=0, ni; ni=names[i]; i++) {
46+
a.push(ni);
47+
}
48+
//a.push(n);
2949
}
3050
}
3151
if (prototype.publish) {

src/declaration/prototype.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@
201201
}
202202
};
203203

204+
// implementation of 'chainObject' depends on support for __proto__
204205
if (Object.__proto__) {
205206
prototype.chainObject = function(object, inherited) {
206207
if (object && inherited && object !== inherited) {

0 commit comments

Comments
 (0)