Skip to content

Commit

Permalink
fix(portal): use view slot life cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
bigopon committed Jan 17, 2018
1 parent 2183e12 commit dd6feb2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class Portal {

public detached() {
this.isAttached = false;
this.view.detached();
this.viewSlot!.detached();
}

public unbind() {
Expand All @@ -114,10 +114,8 @@ export class Portal {
const target = this.getTarget();
const oldViewSlot = this.viewSlot;
if (oldViewSlot) {
oldViewSlot.removeAt(0, false, false);
if (this.isAttached) {
view.detached();
}
oldViewSlot.remove(view);
this.viewSlot = null;
}
if (this.isAttached) {
const viewSlot = this.viewSlot = new ViewSlot(target!, true);
Expand Down
14 changes: 14 additions & 0 deletions test/unit/portal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ describe('Portal attribute', () => {
expect(document.querySelector('.square3 form')).not.toBeFalsy();
});

it('does not render when not attached', () => {
portal.bind(bindingContext, overrideContext);

portal.targetChanged();

expect(document.querySelector('form')).toBe(null);
expect((portal as any).viewSlot).toBe(undefined);

portal.attached();
expect(document.querySelector('form')).not.toBeFalsy();

portal.detached();
});

it('throws in strict mode', () => {
portal.strict = true;
portal.target = '.square4';
Expand Down

0 comments on commit dd6feb2

Please sign in to comment.