Permalink
Browse files

fix(if): nested ifs don't work properly

fixes #328, #327, #326, #322, #317, #315
  • Loading branch information...
jods4 committed Oct 25, 2017
1 parent b8cba60 commit 9548e16bc9ea574bd2e69b65cc5772c341de653a
Showing with 15 additions and 4 deletions.
  1. +4 −1 src/else.js
  2. +6 −1 src/if-core.js
  3. +3 −0 src/if.js
  4. +2 −2 test/if.spec.js
View
@@ -14,7 +14,10 @@ export class Else extends IfCore {
bind(bindingContext, overrideContext) {
super.bind(bindingContext, overrideContext);
// Render on initial
if (!this.ifVm.condition) {
if (this.ifVm.condition) {
this._hide();
}
else {
this._show();
}
}
View
@@ -31,7 +31,6 @@ export class IfCore {
// For example a view could be returned to the cache and reused while it's still
// attached to the DOM and animated.
if (!this.viewFactory.isCaching) {
this.showing = false;
return;
}
@@ -47,6 +46,12 @@ export class IfCore {
_show() {
if (this.showing) {
// Ensures the view is bound.
// It might not be the case when the if was unbound but not detached, then rebound.
// Typical case where this happens is nested ifs
if (!this.view.isBound) {
this.view.bind(this.bindingContext, this.overrideContext);
}
return;
}
View
@@ -23,6 +23,9 @@ export class If extends IfCore {
if (this.condition) {
this._show();
}
else {
this._hide();
}
}
/**
View
@@ -75,7 +75,7 @@ describe('if', () => {
sut.unbind();
taskQueue.flushMicroTaskQueue();
expect(sut.showing).toBeFalsy();
expect(sut.showing).toBeTruthy();
expect(view.unbind).toHaveBeenCalled();
expect(viewSlot.remove).not.toHaveBeenCalled();
expect(view.returnToCache).not.toHaveBeenCalled();
@@ -189,7 +189,7 @@ describe('if', () => {
expect(viewSlot.children.length).toEqual(1);
})
.then(() => done())
})
});
});
});

0 comments on commit 9548e16

Please sign in to comment.