From 637367c99079a9042b059f06d40f356449313879 Mon Sep 17 00:00:00 2001 From: Scott J Miles Date: Wed, 26 Aug 2015 16:29:37 -0700 Subject: [PATCH] move the mixing-in of behaviors so that it happens before `register` behaviors are invoked --- src/micro/behaviors.html | 52 +++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/src/micro/behaviors.html b/src/micro/behaviors.html index 1db6d40fee..f0e55800ec 100644 --- a/src/micro/behaviors.html +++ b/src/micro/behaviors.html @@ -60,10 +60,23 @@ _desugarBehaviors: function() { if (this.behaviors.length) { - this.behaviors = this._flattenBehaviorsList(this.behaviors); + this.behaviors = this._desugarSomeBehaviors(this.behaviors); } }, + _desugarSomeBehaviors: function(behaviors) { + // iteration 1 + behaviors = this._flattenBehaviorsList(behaviors); + // iteration 2 + // traverse the behaviors in _reverse_ order (youngest first) because + // `_mixinBehavior` has _first property wins_ behavior, this is done + // to optimize # of calls to `_copyOwnProperty` + for (var i=behaviors.length-1; i>=0; i--) { + this._mixinBehavior(behaviors[i]); + } + return behaviors; + }, + _flattenBehaviorsList: function(behaviors) { var flat = []; behaviors.forEach(function(b) { @@ -80,28 +93,8 @@ return flat; }, - _prepBehaviors: function() { - this._prepFlattenedBehaviors(this.behaviors); - }, - - _prepFlattenedBehaviors: function(behaviors) { - // traverse the behaviors in _reverse_ order (youngest first) because - // `_mixinBehavior` has _first property wins_ behavior, this is done - // to optimize # of calls to `_copyOwnProperty` - for (var i=behaviors.length-1; i>=0; i--) { - this._mixinBehavior(behaviors[i]); - } - // we iterate a second time so that `_prepBehavior` goes in natural order - // otherwise, it's a tricky detail for implementors of `_prepBehavior` - for (var i=0, l=behaviors.length; i