-
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathunmount.js
51 lines (45 loc) · 1.38 KB
/
unmount.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { MODE_UNMOUNTING, TYPE_DOM, TYPE_ROOT } from '../constants';
import { unsubscribeFromContext } from '../create-context';
import options from '../options';
import { applyRef } from './refs';
import { ENABLE_CLASSES } from '../component';
/**
* Unmount a virtual node from the tree and apply DOM changes
* @param {import('../internal').Internal} internal The virtual node to unmount
* @param {import('../internal').Internal} topUnmountedInternal The top of the
* subtree that is being unmounted
* @param {number} [skipRemove] Flag that indicates that a parent node of the
* current element is already detached from the DOM.
*/
export function unmount(internal, topUnmountedInternal, skipRemove) {
let r;
if (options.unmount) options.unmount(internal);
internal.flags |= MODE_UNMOUNTING;
if ((r = internal.ref)) {
applyRef(r, null, topUnmountedInternal);
}
if ((r = internal._component)) {
unsubscribeFromContext(internal);
if (ENABLE_CLASSES && r.componentWillUnmount) {
try {
r.componentWillUnmount();
} catch (e) {
options._catchError(e, topUnmountedInternal);
}
}
}
if ((r = internal._child)) {
while (r) {
unmount(
r,
topUnmountedInternal,
skipRemove ? ~internal.flags & TYPE_ROOT : internal.flags & TYPE_DOM
);
r = r._next;
}
}
if (!skipRemove && internal.flags & TYPE_DOM) {
internal.data.remove();
internal.data = null;
}
}