Skip to content

Commit

Permalink
Merge pull request #10326 from ebryn/simple-bound-appendchild
Browse files Browse the repository at this point in the history
Let `View#appendChild` instantiate `SimpleBoundView`s rather than doing it manually ourselves
  • Loading branch information
ebryn committed Feb 1, 2015
2 parents 7ce0db7 + abeeb77 commit 4b633e2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
4 changes: 4 additions & 0 deletions packages/ember-views/lib/views/core_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,8 @@ var CoreView = EmberObject.extend(Evented, ActionHandler, {
destroyElement: K
});

CoreView.reopenClass({
isViewClass: true
});

export default CoreView;
18 changes: 11 additions & 7 deletions packages/ember-views/lib/views/simple_bound_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ import {

function K() { return this; }

function SimpleBoundView(stream) {
function SimpleBoundView(parentView, renderer, morph, stream) {
this.stream = stream;
this[GUID_KEY] = uuid();
this._lastNormalizedValue = undefined;
this.state = 'preRender';
this.updateId = null;
this._parentView = null;
this._parentView = parentView;
this.buffer = null;
this._morph = null;
this._morph = morph;
this.renderer = renderer;
}

SimpleBoundView.prototype = {
Expand Down Expand Up @@ -90,15 +91,18 @@ SimpleBoundView.prototype = {
}
};

SimpleBoundView.create = function(attrs) {
return new SimpleBoundView(attrs._parentView, attrs.renderer, attrs._morph, attrs.stream);
};

SimpleBoundView.isViewClass = true;

export function appendSimpleBoundView(parentView, morph, stream) {
var view = new SimpleBoundView(stream);
view._morph = morph;
var view = parentView.appendChild(SimpleBoundView, { _morph: morph, stream: stream });

stream.subscribe(parentView._wrapAsScheduled(function() {
run.scheduleOnce('render', view, 'rerender');
}));

parentView.appendChild(view);
}

export default SimpleBoundView;
2 changes: 1 addition & 1 deletion packages/ember-views/lib/views/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ var ViewChildViewsSupport = Mixin.create({
attrs._parentView = this;
attrs.renderer = this.renderer;

if (CoreView.detect(maybeViewClass)) {
if (maybeViewClass.isViewClass) {
attrs.container = this.container;

view = maybeViewClass.create(attrs);
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-views/tests/views/simple_bound_view_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ test('does not render if update is triggered by normalizedValue is the same as t
var lazyValue = new Stream(function() {
return obj.foo;
});
var view = new SimpleBoundView(lazyValue);
view._morph = {
var morph = {
setContent: function(newValue) {
value = newValue;
}
};
var view = new SimpleBoundView(null, null, morph, lazyValue);

equal(value, null);

Expand Down

0 comments on commit 4b633e2

Please sign in to comment.