This mixin, when applied to an Ember.ContainerView
(and, by extension, a CollectionView
) creates three new methods on the extended view. These methods are called whenever a contained view raises a willInsertElement
, didInsertElement
or willDestroyElement
event.
HauteLook.ChildViewObserver = Ember.Mixin.create({
childViewsWillChange: function(childViews, start, removeCount, addCount) {
this._super.apply(this, arguments);
for(var i=0; i < removeCount; i++) {
var cv = childViews.objectAt(start + i);
cv.off('willInsertElement', this, this.willInsertChildElement);
cv.off('didInsertElement', this, this.didInsertChildElement);
cv.off('willDestroyElement', this, this.willDestroyChildElement);
}
},
childViewsDidChange: function(childViews, start, removeCount, addCount) {
this._super.apply(this, arguments);
for(var i=0; i < addCount; i++) {
var cv = childViews.objectAt(start + i);
cv.on('willInsertElement', this, this.willInsertChildElement);
cv.on('didInsertElement', this, this.didInsertChildElement);
cv.on('willDestroyElement', this, this.willDestroyChildElement);
}
},
willInsertChildElement: Ember.K,
didInsertChildElement: Ember.K,
willDestroyChildElement: Ember.K
});