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 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.
This is the opposite method of _mounted_.
+4 -3
View File
@@ -176,8 +176,9 @@ export class Component<
patched() {}
/**
* willUnmount is a hook that is called each time a component is detached from
* the DOM. This is a good place to remove some listeners, for example.
* 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.
*
* Note: this method should not be called manually.
*
@@ -236,7 +237,7 @@ export class Component<
}
}
detach() {
unmount() {
if (this.el) {
this._visitSubTree(w => {
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${
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}.${
keepAlive ? "detach" : "destroy"
keepAlive ? "unmount" : "destroy"
}()},destroy(){w${widgetID}.${
keepAlive ? "detach" : "destroy"
keepAlive ? "unmount" : "destroy"
}()}}; w${widgetID}.__widget__.pvnode = pvnode;});`
);
ctx.addElse();
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}.${
keepAlive ? "detach" : "destroy"
keepAlive ? "unmount" : "destroy"
}()}}}c${ctx.parentNode}[_${dummyID}_index]=vnode;});`
);
ctx.closeIf();
+1 -1
View File
@@ -1268,7 +1268,7 @@ describe("updating environment", () => {
expect(n).toBe(1);
await widget.updateEnv(<any>{ somekey: 5 });
expect(n).toBe(2);
widget.detach();
widget.unmount();
expect(n).toBe(2);
await widget.updateEnv(<any>{ somekey: 5 });
expect(n).toBe(2);