isomorfeus-preact 10.8.2 → 22.9.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +14 -3
- data/README.md +23 -39
- data/lib/browser/delegate_native.rb +94 -72
- data/lib/browser/document.rb +38 -0
- data/lib/browser/element.rb +160 -176
- data/lib/browser/event.rb +99 -94
- data/lib/browser/history.rb +40 -20
- data/lib/browser/location.rb +59 -0
- data/lib/browser/window.rb +58 -0
- data/lib/data_uri/open_uri.rb +18 -0
- data/lib/data_uri/uri.rb +61 -0
- data/lib/data_uri.rb +4 -0
- data/lib/isomorfeus/preact/config.rb +42 -54
- data/lib/isomorfeus/preact/imports.rb +5 -20
- data/lib/isomorfeus/preact/ssr.rb +34 -0
- data/lib/isomorfeus/preact/thread_local_component_cache.rb +9 -11
- data/lib/isomorfeus/preact/version.rb +5 -0
- data/lib/isomorfeus/preact/view_helper.rb +72 -0
- data/lib/isomorfeus/props/validator.rb +19 -11
- data/lib/isomorfeus/top_level.rb +55 -33
- data/lib/isomorfeus-preact.rb +78 -103
- data/lib/link.rb +52 -0
- data/lib/lucid_app.rb +117 -0
- data/lib/lucid_component.rb +154 -0
- data/lib/nano_css.rb +282 -465
- data/lib/preact/component.rb +222 -0
- data/lib/preact/component_resolution.rb +49 -83
- data/lib/preact/context.rb +68 -0
- data/lib/preact/elements.rb +2 -9
- data/lib/preact/module_component_resolution.rb +50 -0
- data/lib/preact/prop_declaration_mixin.rb +73 -0
- data/lib/preact.rb +1548 -257
- data/lib/redirect.rb +34 -0
- data/lib/route.rb +15 -0
- data/lib/router.rb +145 -0
- data/lib/switch.rb +70 -0
- metadata +42 -309
- data/lib/isomorfeus/preact/memcached_component_cache.rb +0 -19
- data/lib/isomorfeus/preact/redis_component_cache.rb +0 -19
- data/lib/isomorfeus/preact/ssr/history.rb +0 -23
- data/lib/isomorfeus/preact/ssr/render_core.rb +0 -117
- data/lib/isomorfeus/preact/ssr/top_level.rb +0 -37
- data/lib/isomorfeus/preact_view_helper.rb +0 -129
- data/lib/isomorfeus_preact/lucid_app/api.rb +0 -38
- data/lib/isomorfeus_preact/lucid_app/base.rb +0 -7
- data/lib/isomorfeus_preact/lucid_app/mixin.rb +0 -14
- data/lib/isomorfeus_preact/lucid_app/native_component_constructor.rb +0 -101
- data/lib/isomorfeus_preact/lucid_component/api.rb +0 -123
- data/lib/isomorfeus_preact/lucid_component/app_store_proxy.rb +0 -32
- data/lib/isomorfeus_preact/lucid_component/base.rb +0 -7
- data/lib/isomorfeus_preact/lucid_component/class_store_proxy.rb +0 -37
- data/lib/isomorfeus_preact/lucid_component/initializer.rb +0 -9
- data/lib/isomorfeus_preact/lucid_component/mixin.rb +0 -13
- data/lib/isomorfeus_preact/lucid_component/native_component_constructor.rb +0 -87
- data/lib/isomorfeus_preact/lucid_component/styles_wrapper.rb +0 -40
- data/lib/isomorfeus_preact/lucid_func/base.rb +0 -7
- data/lib/isomorfeus_preact/lucid_func/initializer.rb +0 -8
- data/lib/isomorfeus_preact/lucid_func/mixin.rb +0 -10
- data/lib/isomorfeus_preact/lucid_func/native_component_constructor.rb +0 -56
- data/lib/isomorfeus_preact/preact/function_component/api.rb +0 -140
- data/lib/isomorfeus_preact/preact/function_component/base.rb +0 -7
- data/lib/isomorfeus_preact/preact/function_component/initializer.rb +0 -6
- data/lib/isomorfeus_preact/preact/function_component/mixin.rb +0 -8
- data/lib/isomorfeus_preact/preact/function_component/native_component_constructor.rb +0 -47
- data/lib/lucid_app/context.rb +0 -24
- data/lib/lucid_prop_declaration/mixin.rb +0 -126
- data/lib/preact/component/api.rb +0 -137
- data/lib/preact/component/base.rb +0 -7
- data/lib/preact/component/callbacks.rb +0 -111
- data/lib/preact/component/initializer.rb +0 -7
- data/lib/preact/component/mixin.rb +0 -11
- data/lib/preact/component/native_component_constructor.rb +0 -77
- data/lib/preact/context_wrapper.rb +0 -48
- data/lib/preact/native_constant_wrapper.rb +0 -29
- data/lib/preact/option_hooks.rb +0 -98
- data/lib/preact/params.rb +0 -16
- data/lib/preact/props.rb +0 -69
- data/lib/preact/ref.rb +0 -17
- data/lib/preact/state.rb +0 -87
- data/lib/preact/version.rb +0 -3
- data/node_modules/.package-lock.json +0 -38
- data/node_modules/preact/LICENSE +0 -21
- data/node_modules/preact/README.md +0 -188
- data/node_modules/preact/compat/LICENSE +0 -21
- data/node_modules/preact/compat/client.js +0 -19
- data/node_modules/preact/compat/client.mjs +0 -17
- data/node_modules/preact/compat/dist/compat.js +0 -2
- data/node_modules/preact/compat/dist/compat.js.map +0 -1
- data/node_modules/preact/compat/dist/compat.mjs +0 -2
- data/node_modules/preact/compat/dist/compat.module.js +0 -2
- data/node_modules/preact/compat/dist/compat.module.js.map +0 -1
- data/node_modules/preact/compat/dist/compat.umd.js +0 -2
- data/node_modules/preact/compat/dist/compat.umd.js.map +0 -1
- data/node_modules/preact/compat/jsx-dev-runtime.js +0 -3
- data/node_modules/preact/compat/jsx-dev-runtime.mjs +0 -3
- data/node_modules/preact/compat/jsx-runtime.js +0 -3
- data/node_modules/preact/compat/jsx-runtime.mjs +0 -3
- data/node_modules/preact/compat/package.json +0 -49
- data/node_modules/preact/compat/scheduler.js +0 -15
- data/node_modules/preact/compat/scheduler.mjs +0 -23
- data/node_modules/preact/compat/server.browser.js +0 -4
- data/node_modules/preact/compat/server.js +0 -15
- data/node_modules/preact/compat/server.mjs +0 -4
- data/node_modules/preact/compat/src/Children.js +0 -21
- data/node_modules/preact/compat/src/PureComponent.js +0 -15
- data/node_modules/preact/compat/src/forwardRef.js +0 -44
- data/node_modules/preact/compat/src/index.d.ts +0 -155
- data/node_modules/preact/compat/src/index.js +0 -187
- data/node_modules/preact/compat/src/internal.d.ts +0 -47
- data/node_modules/preact/compat/src/memo.js +0 -34
- data/node_modules/preact/compat/src/portals.js +0 -82
- data/node_modules/preact/compat/src/render.js +0 -238
- data/node_modules/preact/compat/src/suspense-list.d.ts +0 -14
- data/node_modules/preact/compat/src/suspense-list.js +0 -126
- data/node_modules/preact/compat/src/suspense.d.ts +0 -15
- data/node_modules/preact/compat/src/suspense.js +0 -270
- data/node_modules/preact/compat/src/util.js +0 -28
- data/node_modules/preact/compat/test-utils.js +0 -1
- data/node_modules/preact/debug/LICENSE +0 -21
- data/node_modules/preact/debug/dist/debug.js +0 -2
- data/node_modules/preact/debug/dist/debug.js.map +0 -1
- data/node_modules/preact/debug/dist/debug.mjs +0 -2
- data/node_modules/preact/debug/dist/debug.module.js +0 -2
- data/node_modules/preact/debug/dist/debug.module.js.map +0 -1
- data/node_modules/preact/debug/dist/debug.umd.js +0 -2
- data/node_modules/preact/debug/dist/debug.umd.js.map +0 -1
- data/node_modules/preact/debug/package.json +0 -26
- data/node_modules/preact/debug/src/check-props.js +0 -54
- data/node_modules/preact/debug/src/component-stack.js +0 -146
- data/node_modules/preact/debug/src/constants.js +0 -3
- data/node_modules/preact/debug/src/debug.js +0 -437
- data/node_modules/preact/debug/src/index.js +0 -6
- data/node_modules/preact/debug/src/internal.d.ts +0 -82
- data/node_modules/preact/debug/src/util.js +0 -11
- data/node_modules/preact/devtools/LICENSE +0 -21
- data/node_modules/preact/devtools/dist/devtools.js +0 -2
- data/node_modules/preact/devtools/dist/devtools.js.map +0 -1
- data/node_modules/preact/devtools/dist/devtools.mjs +0 -2
- data/node_modules/preact/devtools/dist/devtools.module.js +0 -2
- data/node_modules/preact/devtools/dist/devtools.module.js.map +0 -1
- data/node_modules/preact/devtools/dist/devtools.umd.js +0 -2
- data/node_modules/preact/devtools/dist/devtools.umd.js.map +0 -1
- data/node_modules/preact/devtools/package.json +0 -25
- data/node_modules/preact/devtools/src/devtools.js +0 -10
- data/node_modules/preact/devtools/src/index.d.ts +0 -8
- data/node_modules/preact/devtools/src/index.js +0 -15
- data/node_modules/preact/dist/preact.js +0 -2
- data/node_modules/preact/dist/preact.js.map +0 -1
- data/node_modules/preact/dist/preact.min.js +0 -2
- data/node_modules/preact/dist/preact.min.js.map +0 -1
- data/node_modules/preact/dist/preact.mjs +0 -2
- data/node_modules/preact/dist/preact.module.js +0 -2
- data/node_modules/preact/dist/preact.module.js.map +0 -1
- data/node_modules/preact/dist/preact.umd.js +0 -2
- data/node_modules/preact/dist/preact.umd.js.map +0 -1
- data/node_modules/preact/hooks/LICENSE +0 -21
- data/node_modules/preact/hooks/dist/hooks.js +0 -2
- data/node_modules/preact/hooks/dist/hooks.js.map +0 -1
- data/node_modules/preact/hooks/dist/hooks.mjs +0 -2
- data/node_modules/preact/hooks/dist/hooks.module.js +0 -2
- data/node_modules/preact/hooks/dist/hooks.module.js.map +0 -1
- data/node_modules/preact/hooks/dist/hooks.umd.js +0 -2
- data/node_modules/preact/hooks/dist/hooks.umd.js.map +0 -1
- data/node_modules/preact/hooks/package.json +0 -35
- data/node_modules/preact/hooks/src/index.d.ts +0 -139
- data/node_modules/preact/hooks/src/index.js +0 -417
- data/node_modules/preact/hooks/src/internal.d.ts +0 -78
- data/node_modules/preact/jsx-runtime/LICENSE +0 -21
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js +0 -2
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js.map +0 -1
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.mjs +0 -2
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js +0 -2
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js.map +0 -1
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js +0 -2
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js.map +0 -1
- data/node_modules/preact/jsx-runtime/package.json +0 -28
- data/node_modules/preact/jsx-runtime/src/index.d.ts +0 -50
- data/node_modules/preact/jsx-runtime/src/index.js +0 -77
- data/node_modules/preact/package.json +0 -304
- data/node_modules/preact/src/cjs.js +0 -3
- data/node_modules/preact/src/clone-element.js +0 -34
- data/node_modules/preact/src/component.js +0 -225
- data/node_modules/preact/src/constants.js +0 -3
- data/node_modules/preact/src/create-context.js +0 -68
- data/node_modules/preact/src/create-element.js +0 -98
- data/node_modules/preact/src/diff/catch-error.js +0 -40
- data/node_modules/preact/src/diff/children.js +0 -335
- data/node_modules/preact/src/diff/index.js +0 -533
- data/node_modules/preact/src/diff/props.js +0 -158
- data/node_modules/preact/src/index.d.ts +0 -317
- data/node_modules/preact/src/index.js +0 -13
- data/node_modules/preact/src/internal.d.ts +0 -155
- data/node_modules/preact/src/jsx.d.ts +0 -1013
- data/node_modules/preact/src/options.js +0 -16
- data/node_modules/preact/src/render.js +0 -75
- data/node_modules/preact/src/util.js +0 -27
- data/node_modules/preact/test-utils/dist/testUtils.js +0 -2
- data/node_modules/preact/test-utils/dist/testUtils.js.map +0 -1
- data/node_modules/preact/test-utils/dist/testUtils.mjs +0 -2
- data/node_modules/preact/test-utils/dist/testUtils.module.js +0 -2
- data/node_modules/preact/test-utils/dist/testUtils.module.js.map +0 -1
- data/node_modules/preact/test-utils/dist/testUtils.umd.js +0 -2
- data/node_modules/preact/test-utils/dist/testUtils.umd.js.map +0 -1
- data/node_modules/preact/test-utils/package.json +0 -28
- data/node_modules/preact/test-utils/src/index.d.ts +0 -3
- data/node_modules/preact/test-utils/src/index.js +0 -118
- data/node_modules/preact-render-to-string/LICENSE +0 -21
- data/node_modules/preact-render-to-string/README.md +0 -102
- data/node_modules/preact-render-to-string/dist/commonjs.js +0 -2
- data/node_modules/preact-render-to-string/dist/commonjs.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/index.d.ts +0 -16
- data/node_modules/preact-render-to-string/dist/index.js +0 -1
- data/node_modules/preact-render-to-string/dist/index.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/index.mjs +0 -2
- data/node_modules/preact-render-to-string/dist/index.module.js +0 -2
- data/node_modules/preact-render-to-string/dist/index.module.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/jsx-entry.js +0 -2
- data/node_modules/preact-render-to-string/dist/jsx-entry.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/jsx.d.ts +0 -13
- data/node_modules/preact-render-to-string/dist/jsx.js +0 -1
- data/node_modules/preact-render-to-string/dist/jsx.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/jsx.mjs +0 -2
- data/node_modules/preact-render-to-string/dist/jsx.modern.js +0 -2
- data/node_modules/preact-render-to-string/dist/jsx.modern.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/jsx.module.js +0 -2
- data/node_modules/preact-render-to-string/dist/jsx.module.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/preact-render-to-string-tests.d.ts +0 -1
- data/node_modules/preact-render-to-string/jsx.js +0 -1
- data/node_modules/preact-render-to-string/package.json +0 -142
- data/node_modules/preact-render-to-string/src/index.d.ts +0 -16
- data/node_modules/preact-render-to-string/src/index.js +0 -462
- data/node_modules/preact-render-to-string/src/jsx.d.ts +0 -13
- data/node_modules/preact-render-to-string/src/jsx.js +0 -76
- data/node_modules/preact-render-to-string/src/polyfills.js +0 -8
- data/node_modules/preact-render-to-string/src/preact-render-to-string-tests.d.ts +0 -1
- data/node_modules/preact-render-to-string/src/util.js +0 -78
- data/node_modules/preact-render-to-string/typings.json +0 -5
- data/node_modules/pretty-format/.npmignore +0 -3
- data/node_modules/pretty-format/LICENSE.md +0 -15
- data/node_modules/pretty-format/README.md +0 -94
- data/node_modules/pretty-format/index.js +0 -343
- data/node_modules/pretty-format/package.json +0 -26
- data/node_modules/pretty-format/plugins/ReactElement.js +0 -74
- data/node_modules/pretty-format/plugins/ReactTestComponent.js +0 -58
- data/node_modules/pretty-format/printString.js +0 -7
- data/node_modules/wouter-preact/cjs/index.js +0 -180
- data/node_modules/wouter-preact/cjs/matcher.js +0 -72
- data/node_modules/wouter-preact/cjs/package.json +0 -1
- data/node_modules/wouter-preact/cjs/react-deps.js +0 -75
- data/node_modules/wouter-preact/cjs/static-location.js +0 -21
- data/node_modules/wouter-preact/cjs/use-location.js +0 -94
- data/node_modules/wouter-preact/index.d.ts +0 -110
- data/node_modules/wouter-preact/index.js +0 -178
- data/node_modules/wouter-preact/matcher.d.ts +0 -30
- data/node_modules/wouter-preact/matcher.js +0 -66
- data/node_modules/wouter-preact/package.json +0 -33
- data/node_modules/wouter-preact/react-deps.js +0 -15
- data/node_modules/wouter-preact/static-location.d.ts +0 -16
- data/node_modules/wouter-preact/static-location.js +0 -17
- data/node_modules/wouter-preact/use-location.d.ts +0 -43
- data/node_modules/wouter-preact/use-location.js +0 -86
- data/package.json +0 -8
@@ -1,335 +0,0 @@
|
|
1
|
-
import { diff, unmount, applyRef } from './index';
|
2
|
-
import { createVNode, Fragment } from '../create-element';
|
3
|
-
import { EMPTY_OBJ, EMPTY_ARR } from '../constants';
|
4
|
-
import { getDomSibling } from '../component';
|
5
|
-
|
6
|
-
/**
|
7
|
-
* Diff the children of a virtual node
|
8
|
-
* @param {import('../internal').PreactElement} parentDom The DOM element whose
|
9
|
-
* children are being diffed
|
10
|
-
* @param {import('../internal').ComponentChildren[]} renderResult
|
11
|
-
* @param {import('../internal').VNode} newParentVNode The new virtual
|
12
|
-
* node whose children should be diff'ed against oldParentVNode
|
13
|
-
* @param {import('../internal').VNode} oldParentVNode The old virtual
|
14
|
-
* node whose children should be diff'ed against newParentVNode
|
15
|
-
* @param {object} globalContext The current context object - modified by getChildContext
|
16
|
-
* @param {boolean} isSvg Whether or not this DOM node is an SVG node
|
17
|
-
* @param {Array<import('../internal').PreactElement>} excessDomChildren
|
18
|
-
* @param {Array<import('../internal').Component>} commitQueue List of components
|
19
|
-
* which have callbacks to invoke in commitRoot
|
20
|
-
* @param {import('../internal').PreactElement} oldDom The current attached DOM
|
21
|
-
* element any new dom elements should be placed around. Likely `null` on first
|
22
|
-
* render (except when hydrating). Can be a sibling DOM element when diffing
|
23
|
-
* Fragments that have siblings. In most cases, it starts out as `oldChildren[0]._dom`.
|
24
|
-
* @param {boolean} isHydrating Whether or not we are in hydration
|
25
|
-
*/
|
26
|
-
export function diffChildren(
|
27
|
-
parentDom,
|
28
|
-
renderResult,
|
29
|
-
newParentVNode,
|
30
|
-
oldParentVNode,
|
31
|
-
globalContext,
|
32
|
-
isSvg,
|
33
|
-
excessDomChildren,
|
34
|
-
commitQueue,
|
35
|
-
oldDom,
|
36
|
-
isHydrating
|
37
|
-
) {
|
38
|
-
let i, j, oldVNode, childVNode, newDom, firstChildDom, refs;
|
39
|
-
|
40
|
-
// This is a compression of oldParentVNode!=null && oldParentVNode != EMPTY_OBJ && oldParentVNode._children || EMPTY_ARR
|
41
|
-
// as EMPTY_OBJ._children should be `undefined`.
|
42
|
-
let oldChildren = (oldParentVNode && oldParentVNode._children) || EMPTY_ARR;
|
43
|
-
|
44
|
-
let oldChildrenLength = oldChildren.length;
|
45
|
-
|
46
|
-
newParentVNode._children = [];
|
47
|
-
for (i = 0; i < renderResult.length; i++) {
|
48
|
-
childVNode = renderResult[i];
|
49
|
-
|
50
|
-
if (childVNode == null || typeof childVNode == 'boolean') {
|
51
|
-
childVNode = newParentVNode._children[i] = null;
|
52
|
-
}
|
53
|
-
// If this newVNode is being reused (e.g. <div>{reuse}{reuse}</div>) in the same diff,
|
54
|
-
// or we are rendering a component (e.g. setState) copy the oldVNodes so it can have
|
55
|
-
// it's own DOM & etc. pointers
|
56
|
-
else if (
|
57
|
-
typeof childVNode == 'string' ||
|
58
|
-
typeof childVNode == 'number' ||
|
59
|
-
// eslint-disable-next-line valid-typeof
|
60
|
-
typeof childVNode == 'bigint'
|
61
|
-
) {
|
62
|
-
childVNode = newParentVNode._children[i] = createVNode(
|
63
|
-
null,
|
64
|
-
childVNode,
|
65
|
-
null,
|
66
|
-
null,
|
67
|
-
childVNode
|
68
|
-
);
|
69
|
-
} else if (Array.isArray(childVNode)) {
|
70
|
-
childVNode = newParentVNode._children[i] = createVNode(
|
71
|
-
Fragment,
|
72
|
-
{ children: childVNode },
|
73
|
-
null,
|
74
|
-
null,
|
75
|
-
null
|
76
|
-
);
|
77
|
-
} else if (childVNode._depth > 0) {
|
78
|
-
// VNode is already in use, clone it. This can happen in the following
|
79
|
-
// scenario:
|
80
|
-
// const reuse = <div />
|
81
|
-
// <div>{reuse}<span />{reuse}</div>
|
82
|
-
childVNode = newParentVNode._children[i] = createVNode(
|
83
|
-
childVNode.type,
|
84
|
-
childVNode.props,
|
85
|
-
childVNode.key,
|
86
|
-
null,
|
87
|
-
childVNode._original
|
88
|
-
);
|
89
|
-
} else {
|
90
|
-
childVNode = newParentVNode._children[i] = childVNode;
|
91
|
-
}
|
92
|
-
|
93
|
-
// Terser removes the `continue` here and wraps the loop body
|
94
|
-
// in a `if (childVNode) { ... } condition
|
95
|
-
if (childVNode == null) {
|
96
|
-
continue;
|
97
|
-
}
|
98
|
-
|
99
|
-
childVNode._parent = newParentVNode;
|
100
|
-
childVNode._depth = newParentVNode._depth + 1;
|
101
|
-
|
102
|
-
// Check if we find a corresponding element in oldChildren.
|
103
|
-
// If found, delete the array item by setting to `undefined`.
|
104
|
-
// We use `undefined`, as `null` is reserved for empty placeholders
|
105
|
-
// (holes).
|
106
|
-
oldVNode = oldChildren[i];
|
107
|
-
|
108
|
-
if (
|
109
|
-
oldVNode === null ||
|
110
|
-
(oldVNode &&
|
111
|
-
childVNode.key == oldVNode.key &&
|
112
|
-
childVNode.type === oldVNode.type)
|
113
|
-
) {
|
114
|
-
oldChildren[i] = undefined;
|
115
|
-
} else {
|
116
|
-
// Either oldVNode === undefined or oldChildrenLength > 0,
|
117
|
-
// so after this loop oldVNode == null or oldVNode is a valid value.
|
118
|
-
for (j = 0; j < oldChildrenLength; j++) {
|
119
|
-
oldVNode = oldChildren[j];
|
120
|
-
// If childVNode is unkeyed, we only match similarly unkeyed nodes, otherwise we match by key.
|
121
|
-
// We always match by type (in either case).
|
122
|
-
if (
|
123
|
-
oldVNode &&
|
124
|
-
childVNode.key == oldVNode.key &&
|
125
|
-
childVNode.type === oldVNode.type
|
126
|
-
) {
|
127
|
-
oldChildren[j] = undefined;
|
128
|
-
break;
|
129
|
-
}
|
130
|
-
oldVNode = null;
|
131
|
-
}
|
132
|
-
}
|
133
|
-
|
134
|
-
oldVNode = oldVNode || EMPTY_OBJ;
|
135
|
-
|
136
|
-
// Morph the old element into the new one, but don't append it to the dom yet
|
137
|
-
diff(
|
138
|
-
parentDom,
|
139
|
-
childVNode,
|
140
|
-
oldVNode,
|
141
|
-
globalContext,
|
142
|
-
isSvg,
|
143
|
-
excessDomChildren,
|
144
|
-
commitQueue,
|
145
|
-
oldDom,
|
146
|
-
isHydrating
|
147
|
-
);
|
148
|
-
|
149
|
-
newDom = childVNode._dom;
|
150
|
-
|
151
|
-
if ((j = childVNode.ref) && oldVNode.ref != j) {
|
152
|
-
if (!refs) refs = [];
|
153
|
-
if (oldVNode.ref) refs.push(oldVNode.ref, null, childVNode);
|
154
|
-
refs.push(j, childVNode._component || newDom, childVNode);
|
155
|
-
}
|
156
|
-
|
157
|
-
if (newDom != null) {
|
158
|
-
if (firstChildDom == null) {
|
159
|
-
firstChildDom = newDom;
|
160
|
-
}
|
161
|
-
|
162
|
-
if (
|
163
|
-
typeof childVNode.type == 'function' &&
|
164
|
-
childVNode._children === oldVNode._children
|
165
|
-
) {
|
166
|
-
childVNode._nextDom = oldDom = reorderChildren(
|
167
|
-
childVNode,
|
168
|
-
oldDom,
|
169
|
-
parentDom
|
170
|
-
);
|
171
|
-
} else {
|
172
|
-
oldDom = placeChild(
|
173
|
-
parentDom,
|
174
|
-
childVNode,
|
175
|
-
oldVNode,
|
176
|
-
oldChildren,
|
177
|
-
newDom,
|
178
|
-
oldDom
|
179
|
-
);
|
180
|
-
}
|
181
|
-
|
182
|
-
if (typeof newParentVNode.type == 'function') {
|
183
|
-
// Because the newParentVNode is Fragment-like, we need to set it's
|
184
|
-
// _nextDom property to the nextSibling of its last child DOM node.
|
185
|
-
//
|
186
|
-
// `oldDom` contains the correct value here because if the last child
|
187
|
-
// is a Fragment-like, then oldDom has already been set to that child's _nextDom.
|
188
|
-
// If the last child is a DOM VNode, then oldDom will be set to that DOM
|
189
|
-
// node's nextSibling.
|
190
|
-
newParentVNode._nextDom = oldDom;
|
191
|
-
}
|
192
|
-
} else if (
|
193
|
-
oldDom &&
|
194
|
-
oldVNode._dom == oldDom &&
|
195
|
-
oldDom.parentNode != parentDom
|
196
|
-
) {
|
197
|
-
// The above condition is to handle null placeholders. See test in placeholder.test.js:
|
198
|
-
// `efficiently replace null placeholders in parent rerenders`
|
199
|
-
oldDom = getDomSibling(oldVNode);
|
200
|
-
}
|
201
|
-
}
|
202
|
-
|
203
|
-
newParentVNode._dom = firstChildDom;
|
204
|
-
|
205
|
-
// Remove remaining oldChildren if there are any.
|
206
|
-
for (i = oldChildrenLength; i--; ) {
|
207
|
-
if (oldChildren[i] != null) {
|
208
|
-
if (
|
209
|
-
typeof newParentVNode.type == 'function' &&
|
210
|
-
oldChildren[i]._dom != null &&
|
211
|
-
oldChildren[i]._dom == newParentVNode._nextDom
|
212
|
-
) {
|
213
|
-
// If the newParentVNode.__nextDom points to a dom node that is about to
|
214
|
-
// be unmounted, then get the next sibling of that vnode and set
|
215
|
-
// _nextDom to it
|
216
|
-
newParentVNode._nextDom = getDomSibling(oldParentVNode, i + 1);
|
217
|
-
}
|
218
|
-
|
219
|
-
unmount(oldChildren[i], oldChildren[i]);
|
220
|
-
}
|
221
|
-
}
|
222
|
-
|
223
|
-
// Set refs only after unmount
|
224
|
-
if (refs) {
|
225
|
-
for (i = 0; i < refs.length; i++) {
|
226
|
-
applyRef(refs[i], refs[++i], refs[++i]);
|
227
|
-
}
|
228
|
-
}
|
229
|
-
}
|
230
|
-
|
231
|
-
function reorderChildren(childVNode, oldDom, parentDom) {
|
232
|
-
// Note: VNodes in nested suspended trees may be missing _children.
|
233
|
-
let c = childVNode._children;
|
234
|
-
let tmp = 0;
|
235
|
-
for (; c && tmp < c.length; tmp++) {
|
236
|
-
let vnode = c[tmp];
|
237
|
-
if (vnode) {
|
238
|
-
// We typically enter this code path on sCU bailout, where we copy
|
239
|
-
// oldVNode._children to newVNode._children. If that is the case, we need
|
240
|
-
// to update the old children's _parent pointer to point to the newVNode
|
241
|
-
// (childVNode here).
|
242
|
-
vnode._parent = childVNode;
|
243
|
-
|
244
|
-
if (typeof vnode.type == 'function') {
|
245
|
-
oldDom = reorderChildren(vnode, oldDom, parentDom);
|
246
|
-
} else {
|
247
|
-
oldDom = placeChild(
|
248
|
-
parentDom,
|
249
|
-
vnode,
|
250
|
-
vnode,
|
251
|
-
c,
|
252
|
-
vnode._dom,
|
253
|
-
oldDom
|
254
|
-
);
|
255
|
-
}
|
256
|
-
}
|
257
|
-
}
|
258
|
-
|
259
|
-
return oldDom;
|
260
|
-
}
|
261
|
-
|
262
|
-
/**
|
263
|
-
* Flatten and loop through the children of a virtual node
|
264
|
-
* @param {import('../index').ComponentChildren} children The unflattened
|
265
|
-
* children of a virtual node
|
266
|
-
* @returns {import('../internal').VNode[]}
|
267
|
-
*/
|
268
|
-
export function toChildArray(children, out) {
|
269
|
-
out = out || [];
|
270
|
-
if (children == null || typeof children == 'boolean') {
|
271
|
-
} else if (Array.isArray(children)) {
|
272
|
-
children.some(child => {
|
273
|
-
toChildArray(child, out);
|
274
|
-
});
|
275
|
-
} else {
|
276
|
-
out.push(children);
|
277
|
-
}
|
278
|
-
return out;
|
279
|
-
}
|
280
|
-
|
281
|
-
function placeChild(
|
282
|
-
parentDom,
|
283
|
-
childVNode,
|
284
|
-
oldVNode,
|
285
|
-
oldChildren,
|
286
|
-
newDom,
|
287
|
-
oldDom
|
288
|
-
) {
|
289
|
-
let nextDom;
|
290
|
-
if (childVNode._nextDom !== undefined) {
|
291
|
-
// Only Fragments or components that return Fragment like VNodes will
|
292
|
-
// have a non-undefined _nextDom. Continue the diff from the sibling
|
293
|
-
// of last DOM child of this child VNode
|
294
|
-
nextDom = childVNode._nextDom;
|
295
|
-
|
296
|
-
// Eagerly cleanup _nextDom. We don't need to persist the value because
|
297
|
-
// it is only used by `diffChildren` to determine where to resume the diff after
|
298
|
-
// diffing Components and Fragments. Once we store it the nextDOM local var, we
|
299
|
-
// can clean up the property
|
300
|
-
childVNode._nextDom = undefined;
|
301
|
-
} else if (
|
302
|
-
oldVNode == null ||
|
303
|
-
newDom != oldDom ||
|
304
|
-
newDom.parentNode == null
|
305
|
-
) {
|
306
|
-
outer: if (oldDom == null || oldDom.parentNode !== parentDom) {
|
307
|
-
parentDom.appendChild(newDom);
|
308
|
-
nextDom = null;
|
309
|
-
} else {
|
310
|
-
// `j<oldChildrenLength; j+=2` is an alternative to `j++<oldChildrenLength/2`
|
311
|
-
for (
|
312
|
-
let sibDom = oldDom, j = 0;
|
313
|
-
(sibDom = sibDom.nextSibling) && j < oldChildren.length;
|
314
|
-
j += 2
|
315
|
-
) {
|
316
|
-
if (sibDom == newDom) {
|
317
|
-
break outer;
|
318
|
-
}
|
319
|
-
}
|
320
|
-
parentDom.insertBefore(newDom, oldDom);
|
321
|
-
nextDom = oldDom;
|
322
|
-
}
|
323
|
-
}
|
324
|
-
|
325
|
-
// If we have pre-calculated the nextDOM node, use it. Else calculate it now
|
326
|
-
// Strictly check for `undefined` here cuz `null` is a valid value of `nextDom`.
|
327
|
-
// See more detail in create-element.js:createVNode
|
328
|
-
if (nextDom !== undefined) {
|
329
|
-
oldDom = nextDom;
|
330
|
-
} else {
|
331
|
-
oldDom = newDom.nextSibling;
|
332
|
-
}
|
333
|
-
|
334
|
-
return oldDom;
|
335
|
-
}
|