From 1a8ace3d8ad1a98609b9156b77f1c6a25dc53760 Mon Sep 17 00:00:00 2001 From: "Scott J. Miles" Date: Wed, 18 Dec 2013 19:28:36 -0800 Subject: [PATCH] support combining names in observe block (e.g. observe { 'foo bar baz': 'stuffChanged'}) --- src/declaration/properties.js | 22 +++++++++++++++++++++- src/declaration/prototype.js | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/declaration/properties.js b/src/declaration/properties.js index 4345d88..ac5f50c 100644 --- a/src/declaration/properties.js +++ b/src/declaration/properties.js @@ -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') { @@ -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) { diff --git a/src/declaration/prototype.js b/src/declaration/prototype.js index e638d1d..b4a5cb6 100644 --- a/src/declaration/prototype.js +++ b/src/declaration/prototype.js @@ -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) {