ref: rename 'detach' method to 'unmount'

This commit is contained in:
Géry Debongnie
2019-04-09 12:57:34 +02:00
parent 6e0ef0fd5c
commit 94c33af8e9
4 changed files with 9 additions and 8 deletions
+1 -1
View File
@@ -98,7 +98,7 @@ careful at avoiding endless cycles.
### willUnmount ### willUnmount
willUnmount is a hook that is called each time a component is detached from willUnmount is a hook that is called each time just before a component is unmounted from
the DOM. This is a good place to remove some listeners, for example. the DOM. This is a good place to remove some listeners, for example.
This is the opposite method of _mounted_. This is the opposite method of _mounted_.
+4 -3
View File
@@ -176,8 +176,9 @@ export class Component<
patched() {} patched() {}
/** /**
* willUnmount is a hook that is called each time a component is detached from * willUnmount is a hook that is called each time just before a component is
* the DOM. This is a good place to remove some listeners, for example. * unmounted from the DOM. This is a good place to remove some listeners, for
* example.
* *
* Note: this method should not be called manually. * Note: this method should not be called manually.
* *
@@ -236,7 +237,7 @@ export class Component<
} }
} }
detach() { unmount() {
if (this.el) { if (this.el) {
this._visitSubTree(w => { this._visitSubTree(w => {
if (w.__widget__.isMounted) { if (w.__widget__.isMounted) {
+3 -3
View File
@@ -1010,15 +1010,15 @@ const widgetDirective: Directive = {
`def${defID} = def${defID}.then(vnode=>{let pvnode=h(vnode.sel, {key: ${templateID}});c${ `def${defID} = def${defID}.then(vnode=>{let pvnode=h(vnode.sel, {key: ${templateID}});c${
ctx.parentNode ctx.parentNode
}[_${dummyID}_index]=pvnode;pvnode.data.hook = {insert(vn){let nvn=w${widgetID}._mount(vnode, vn.elm);pvnode.elm=nvn.elm},remove(){w${widgetID}.${ }[_${dummyID}_index]=pvnode;pvnode.data.hook = {insert(vn){let nvn=w${widgetID}._mount(vnode, vn.elm);pvnode.elm=nvn.elm},remove(){w${widgetID}.${
keepAlive ? "detach" : "destroy" keepAlive ? "unmount" : "destroy"
}()},destroy(){w${widgetID}.${ }()},destroy(){w${widgetID}.${
keepAlive ? "detach" : "destroy" keepAlive ? "unmount" : "destroy"
}()}}; w${widgetID}.__widget__.pvnode = pvnode;});` }()}}; w${widgetID}.__widget__.pvnode = pvnode;});`
); );
ctx.addElse(); ctx.addElse();
ctx.addLine( ctx.addLine(
`def${defID} = def${defID}.then(()=>{if (w${widgetID}.__widget__.isDestroyed) {return};let vnode;if (!w${widgetID}.__widget__.vnode){vnode=w${widgetID}.__widget__.pvnode} else { vnode=h(w${widgetID}.__widget__.vnode.sel, {key: ${templateID}});vnode.elm=w${widgetID}.el;vnode.data.hook = {insert(a){a.elm.parentNode.replaceChild(w${widgetID}.el,a.elm);a.elm=w${widgetID}.el;w${widgetID}.__mount();},remove(){w${widgetID}.${ `def${defID} = def${defID}.then(()=>{if (w${widgetID}.__widget__.isDestroyed) {return};let vnode;if (!w${widgetID}.__widget__.vnode){vnode=w${widgetID}.__widget__.pvnode} else { vnode=h(w${widgetID}.__widget__.vnode.sel, {key: ${templateID}});vnode.elm=w${widgetID}.el;vnode.data.hook = {insert(a){a.elm.parentNode.replaceChild(w${widgetID}.el,a.elm);a.elm=w${widgetID}.el;w${widgetID}.__mount();},remove(){w${widgetID}.${
keepAlive ? "detach" : "destroy" keepAlive ? "unmount" : "destroy"
}()}}}c${ctx.parentNode}[_${dummyID}_index]=vnode;});` }()}}}c${ctx.parentNode}[_${dummyID}_index]=vnode;});`
); );
ctx.closeIf(); ctx.closeIf();
+1 -1
View File
@@ -1268,7 +1268,7 @@ describe("updating environment", () => {
expect(n).toBe(1); expect(n).toBe(1);
await widget.updateEnv(<any>{ somekey: 5 }); await widget.updateEnv(<any>{ somekey: 5 });
expect(n).toBe(2); expect(n).toBe(2);
widget.detach(); widget.unmount();
expect(n).toBe(2); expect(n).toBe(2);
await widget.updateEnv(<any>{ somekey: 5 }); await widget.updateEnv(<any>{ somekey: 5 });
expect(n).toBe(2); expect(n).toBe(2);