Skip to content

Commit

Permalink
fix(View): preserve bindingContext while unbinding
Browse files Browse the repository at this point in the history
  • Loading branch information
jdanyow committed Mar 24, 2016
1 parent a56b744 commit ae6feed
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/view.js
Expand Up @@ -151,9 +151,6 @@ export class View {
this.isBound = false;
this.resources._invokeHook('beforeUnbind', this);

this.bindingContext = null;
this.overrideContext = null;

if (this.controller !== null) {
this.controller.unbind();
}
Expand All @@ -172,6 +169,9 @@ export class View {
for (i = 0, ii = children.length; i < ii; ++i) {
children[i].unbind();
}

this.bindingContext = null;
this.overrideContext = null;
}
}

Expand Down
33 changes: 33 additions & 0 deletions test/view.spec.js
@@ -0,0 +1,33 @@
import {View} from '../src/view';

describe('View', () => {
it('binds and unbinds', () => {
let view;
let bindingContext = {};
let overrideContext = {};
let viewFactory = { resources: { _invokeHook: jasmine.createSpy('_invokeHook') } };
let fragment = {};
let controllers = [{ bind: jasmine.createSpy('bind'), unbind: jasmine.createSpy('unbind') }];
let bindings = [{
bind: jasmine.createSpy('bind'),
unbind: jasmine.createSpy('unbind').and.callFake(function() {
// the view's bindingContext needs to be preserved while bindings are unbinding.
expect(view.bindingContext).toBe(bindingContext);
expect(view.overrideContext).toBe(overrideContext);
})
}];
let children = [{ bind: jasmine.createSpy('bind'), unbind: jasmine.createSpy('unbind') }];
let contentSelectors = [];
view = new View(viewFactory, fragment, controllers, bindings, children, contentSelectors);
view.bind(bindingContext, overrideContext);
expect(viewFactory.resources._invokeHook).toHaveBeenCalledWith('beforeBind', view);
expect(controllers[0].bind).toHaveBeenCalledWith(view);
expect(bindings[0].bind).toHaveBeenCalledWith(view);
expect(children[0].bind).toHaveBeenCalledWith(bindingContext, overrideContext, true);
view.unbind();
expect(viewFactory.resources._invokeHook).toHaveBeenCalledWith('beforeUnbind', view);
expect(controllers[0].unbind).toHaveBeenCalled();
expect(bindings[0].bind).toHaveBeenCalled();
expect(children[0].bind).toHaveBeenCalled();
});
});

0 comments on commit ae6feed

Please sign in to comment.