@simpreact/simpreact 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compat/core.js +101 -15
- package/compat/hooks.js +15 -0
- package/compat/index.d.ts +10 -1
- package/compat/renderRuntime.js +47 -12
- package/component/index.js +96 -94
- package/context/index.js +27 -17
- package/core/createElement.js +14 -17
- package/core/flags.js +31 -0
- package/core/hostOperations.js +5 -13
- package/core/index.d.ts +38 -8
- package/core/index.js +3 -2
- package/core/internal.d.ts +136 -16
- package/core/internal.js +8 -16
- package/core/lifecycleEventBus.js +35 -16
- package/core/memo.js +4 -1
- package/core/mounting.js +70 -150
- package/core/mountingChildren.js +11 -29
- package/core/patching.js +122 -181
- package/core/patchingChildren.js +74 -145
- package/core/portal.js +1 -1
- package/core/processStack.js +115 -45
- package/core/ref.js +1 -0
- package/core/rerender.js +20 -22
- package/core/runtime.js +10 -2
- package/core/unmounting.js +41 -49
- package/core/unmountingChildren.js +9 -12
- package/core/utils.js +38 -16
- package/dom/attach-element-to-dom.js +16 -8
- package/dom/events.js +11 -15
- package/dom/index.d.ts +2 -0
- package/dom/props/attrMaps.js +90 -0
- package/dom/props/controlled/select.js +8 -10
- package/dom/props/props.js +13 -14
- package/hooks/index.d.ts +3 -0
- package/hooks/index.js +107 -84
- package/package.json +10 -5
- package/compat/context.d.ts +0 -7
- package/compat/core.d.ts +0 -48
- package/compat/dom.d.ts +0 -10
- package/compat/hooks.d.ts +0 -26
- package/compat/jsx-runtime.d.ts +0 -10
- package/compat/renderRuntime.d.ts +0 -6
- package/core/createElement.d.ts +0 -39
- package/core/fragment.d.ts +0 -5
- package/core/hostAdapter.d.ts +0 -23
- package/core/hostOperations.d.ts +0 -5
- package/core/lifecycleEventBus.d.ts +0 -39
- package/core/memo.d.ts +0 -8
- package/core/mounting.d.ts +0 -7
- package/core/mountingChildren.d.ts +0 -4
- package/core/patching.d.ts +0 -8
- package/core/patchingChildren.d.ts +0 -6
- package/core/portal.d.ts +0 -2
- package/core/processStack.d.ts +0 -106
- package/core/ref.d.ts +0 -18
- package/core/rerender.d.ts +0 -4
- package/core/runtime.d.ts +0 -17
- package/core/unmounting.d.ts +0 -7
- package/core/unmountingChildren.d.ts +0 -4
- package/core/utils.d.ts +0 -11
- package/dom/attach-element-to-dom.d.ts +0 -5
- package/dom/domAdapter.d.ts +0 -3
- package/dom/events.d.ts +0 -27
- package/dom/namespace.d.ts +0 -2
- package/dom/props/controlled/index.d.ts +0 -7
- package/dom/props/controlled/input.d.ts +0 -7
- package/dom/props/controlled/select.d.ts +0 -6
- package/dom/props/controlled/textarea.d.ts +0 -6
- package/dom/props/dangerInnerHTML.d.ts +0 -7
- package/dom/props/index.d.ts +0 -1
- package/dom/props/props.d.ts +0 -5
- package/dom/props/style.d.ts +0 -1
- package/dom/render.d.ts +0 -8
- package/shared/lang.d.ts +0 -3
- package/shared/utils.d.ts +0 -5
package/core/mounting.js
CHANGED
|
@@ -1,134 +1,92 @@
|
|
|
1
|
+
import { noop } from '../shared/index.js';
|
|
1
2
|
import { createTextElement, normalizeRoot, SIMP_ELEMENT_CHILD_FLAG_TEXT, } from './createElement.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { MOUNT_ENTER, MOUNT_EXIT, processStack } from './processStack.js';
|
|
3
|
+
import { pushHostOperationPlaceElement } from './hostOperations.js';
|
|
4
|
+
import { getLifecycleEventBus } from './lifecycleEventBus.js';
|
|
5
|
+
import { pushMountChildrenFrame } from './mountingChildren.js';
|
|
6
|
+
import { acquireMountFrame, MOUNT_ENTER, MOUNT_EXIT, processStack } from './processStack.js';
|
|
6
7
|
import { applyRef } from './ref.js';
|
|
7
|
-
import { MOUNTING_PHASE } from './runtime.js';
|
|
8
8
|
import { bitScanForwardIndex } from './utils.js';
|
|
9
|
-
const
|
|
9
|
+
const mountEnterHandlers = [mountHostEnter, mountFCEnter, mountTextElement, mountPortalEnter, mountFragment];
|
|
10
|
+
const mountExitHandlers = [mountHostExit, mountFCExit, noop, mountPortalExit, noop];
|
|
10
11
|
export function mount(element, parentReference, subtreeRightBoundary, context, hostNamespace, renderRuntime) {
|
|
11
12
|
if (renderRuntime.renderStack.length !== 0) {
|
|
12
13
|
throw new Error('Cannot mount while rendering.');
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
parentReference,
|
|
16
|
-
subtreeRightBoundary,
|
|
17
|
-
context,
|
|
18
|
-
hostNamespace,
|
|
19
|
-
renderRuntime,
|
|
20
|
-
placeHolderElement: null,
|
|
21
|
-
});
|
|
15
|
+
pushMountEnterFrame(element, renderRuntime, parentReference, subtreeRightBoundary, context, hostNamespace, null);
|
|
22
16
|
processStack(renderRuntime);
|
|
23
17
|
}
|
|
24
|
-
export function
|
|
25
|
-
|
|
18
|
+
export function mountEnter(frame) {
|
|
19
|
+
mountEnterHandlers[bitScanForwardIndex(frame.node.flag)](frame);
|
|
26
20
|
}
|
|
27
|
-
export function
|
|
28
|
-
|
|
29
|
-
node: element,
|
|
30
|
-
kind: MOUNT_ENTER,
|
|
31
|
-
meta,
|
|
32
|
-
});
|
|
21
|
+
export function mountExit(frame) {
|
|
22
|
+
mountExitHandlers[bitScanForwardIndex(frame.node.flag)](frame);
|
|
33
23
|
}
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
24
|
+
export function pushMountEnterFrame(element, renderRuntime, parentReference, subtreeRightBoundary, context, hostNamespace, placeHolderElement) {
|
|
25
|
+
renderRuntime.renderStack.push(acquireMountFrame(renderRuntime, element, MOUNT_ENTER, parentReference, subtreeRightBoundary, context, hostNamespace, placeHolderElement));
|
|
26
|
+
}
|
|
27
|
+
function pushMountExitFrame(element, renderRuntime, parentReference, subtreeRightBoundary, context, hostNamespace, placeHolderElement) {
|
|
28
|
+
renderRuntime.renderStack.push(acquireMountFrame(renderRuntime, element, MOUNT_EXIT, parentReference, subtreeRightBoundary, context, hostNamespace, placeHolderElement));
|
|
40
29
|
}
|
|
41
|
-
function
|
|
30
|
+
function mountHostEnter(frame) {
|
|
42
31
|
const element = frame.node;
|
|
43
|
-
const { parentReference, subtreeRightBoundary, context, hostNamespace, renderRuntime } = frame
|
|
44
|
-
if (frame.kind === MOUNT_EXIT) {
|
|
45
|
-
if (element.childFlag === SIMP_ELEMENT_CHILD_FLAG_TEXT) {
|
|
46
|
-
renderRuntime.hostAdapter.setTextContent(element.reference, element.props.children);
|
|
47
|
-
}
|
|
48
|
-
if (element.props) {
|
|
49
|
-
renderRuntime.hostAdapter.mountProps(element.reference, element, renderRuntime, hostNamespace);
|
|
50
|
-
}
|
|
51
|
-
if (element.className) {
|
|
52
|
-
renderRuntime.hostAdapter.setClassname(element.reference, element.className, hostNamespace);
|
|
53
|
-
}
|
|
54
|
-
if (parentReference) {
|
|
55
|
-
_pushHostOperationPlaceElement(element, {
|
|
56
|
-
renderRuntime,
|
|
57
|
-
subtreeRightBoundary,
|
|
58
|
-
parentReference,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
applyRef(element);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
32
|
+
const { parentReference, subtreeRightBoundary, context, hostNamespace, renderRuntime } = frame;
|
|
64
33
|
const hostNamespaces = renderRuntime.hostAdapter.getHostNamespaces(element, hostNamespace);
|
|
65
34
|
const hostReference = (element.reference = renderRuntime.hostAdapter.createReference(element.type, hostNamespaces?.self));
|
|
66
35
|
renderRuntime.hostAdapter.attachElementToReference(element, hostReference, renderRuntime);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
hostNamespace: hostNamespaces?.self,
|
|
70
|
-
subtreeRightBoundary,
|
|
71
|
-
context,
|
|
72
|
-
parentReference,
|
|
73
|
-
placeHolderElement: null,
|
|
74
|
-
});
|
|
75
|
-
_pushMountChildrenFrame(element, {
|
|
76
|
-
renderRuntime,
|
|
77
|
-
hostNamespace: hostNamespaces?.children,
|
|
78
|
-
subtreeRightBoundary,
|
|
79
|
-
context,
|
|
80
|
-
parentReference: hostReference,
|
|
81
|
-
children: element.children,
|
|
82
|
-
});
|
|
36
|
+
pushMountExitFrame(element, renderRuntime, parentReference, subtreeRightBoundary, context, hostNamespaces?.self, null);
|
|
37
|
+
pushMountChildrenFrame(element, renderRuntime, element.children, hostReference, subtreeRightBoundary, context, hostNamespaces?.children);
|
|
83
38
|
}
|
|
84
|
-
function
|
|
39
|
+
function mountHostExit(frame) {
|
|
85
40
|
const element = frame.node;
|
|
86
|
-
const { parentReference, subtreeRightBoundary,
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
return;
|
|
41
|
+
const { parentReference, subtreeRightBoundary, hostNamespace, renderRuntime } = frame;
|
|
42
|
+
if (element.childFlag === SIMP_ELEMENT_CHILD_FLAG_TEXT) {
|
|
43
|
+
renderRuntime.hostAdapter.setTextContent(element.reference, element.props.children);
|
|
90
44
|
}
|
|
45
|
+
if (element.props) {
|
|
46
|
+
renderRuntime.hostAdapter.mountProps(element.reference, element, renderRuntime, hostNamespace);
|
|
47
|
+
}
|
|
48
|
+
if (element.className) {
|
|
49
|
+
renderRuntime.hostAdapter.setClassname(element.reference, element.className, hostNamespace);
|
|
50
|
+
}
|
|
51
|
+
if (parentReference) {
|
|
52
|
+
pushHostOperationPlaceElement(element, renderRuntime, parentReference, subtreeRightBoundary);
|
|
53
|
+
}
|
|
54
|
+
applyRef(element);
|
|
55
|
+
}
|
|
56
|
+
function mountFCEnter(frame) {
|
|
57
|
+
const element = frame.node;
|
|
58
|
+
const { parentReference, subtreeRightBoundary, context, hostNamespace, renderRuntime } = frame;
|
|
91
59
|
if (context) {
|
|
92
60
|
element.context = context;
|
|
93
61
|
}
|
|
94
62
|
if (element.unmounted) {
|
|
95
63
|
element.unmounted = false;
|
|
96
64
|
}
|
|
97
|
-
element.store = { latestElement: null, hostNamespace: null, forceRerender: false };
|
|
98
|
-
element.store.latestElement = element;
|
|
99
65
|
if (hostNamespace) {
|
|
100
|
-
element.
|
|
66
|
+
element.hostNamespace = hostNamespace;
|
|
101
67
|
}
|
|
102
|
-
// FC element always has Maybe<SimpElement> children due to a normalization process.
|
|
103
68
|
let children;
|
|
104
|
-
let triedToRerenderUnsubscribe;
|
|
105
69
|
try {
|
|
106
|
-
renderRuntime.renderPhase = MOUNTING_PHASE;
|
|
107
|
-
renderRuntime.currentRenderingFCElement = element;
|
|
108
|
-
let triedToRerender = false;
|
|
109
70
|
let rerenderCounter = 0;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
triedToRerender = true;
|
|
113
|
-
}
|
|
114
|
-
});
|
|
71
|
+
renderRuntime.activeRenderElement = element;
|
|
72
|
+
renderRuntime.pendingRerenderFlag = false;
|
|
115
73
|
do {
|
|
116
|
-
|
|
74
|
+
renderRuntime.pendingRerenderFlag = false;
|
|
117
75
|
if (++rerenderCounter >= 25) {
|
|
118
76
|
throw new Error('Too many re-renders.');
|
|
119
77
|
}
|
|
120
|
-
|
|
78
|
+
getLifecycleEventBus(renderRuntime).publish({
|
|
121
79
|
type: 'beforeRender',
|
|
122
80
|
element,
|
|
123
81
|
renderRuntime,
|
|
124
82
|
});
|
|
125
83
|
children = renderRuntime.renderer(element.type, element, renderRuntime);
|
|
126
|
-
|
|
84
|
+
getLifecycleEventBus(renderRuntime).publish({
|
|
127
85
|
type: 'afterRender',
|
|
128
86
|
element,
|
|
129
87
|
renderRuntime,
|
|
130
88
|
});
|
|
131
|
-
} while (
|
|
89
|
+
} while (renderRuntime.pendingRerenderFlag);
|
|
132
90
|
normalizeRoot(element, children, false);
|
|
133
91
|
children = element.children;
|
|
134
92
|
}
|
|
@@ -140,80 +98,42 @@ function _mountFunctionalElement(frame) {
|
|
|
140
98
|
handled: false,
|
|
141
99
|
renderRuntime,
|
|
142
100
|
};
|
|
143
|
-
|
|
101
|
+
getLifecycleEventBus(renderRuntime).publish(event);
|
|
144
102
|
if (!event.handled) {
|
|
145
103
|
throw new Error('Error occurred during rendering a component', { cause: event.error });
|
|
146
104
|
}
|
|
147
105
|
return;
|
|
148
106
|
}
|
|
149
107
|
finally {
|
|
150
|
-
|
|
151
|
-
renderRuntime.renderPhase = null;
|
|
152
|
-
renderRuntime.currentRenderingFCElement = null;
|
|
108
|
+
renderRuntime.activeRenderElement = null;
|
|
153
109
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
_pushMountChildrenFrame(element, {
|
|
163
|
-
renderRuntime,
|
|
164
|
-
hostNamespace,
|
|
165
|
-
children: children,
|
|
166
|
-
context: element.context,
|
|
167
|
-
parentReference,
|
|
168
|
-
subtreeRightBoundary,
|
|
110
|
+
pushMountExitFrame(element, renderRuntime, parentReference, subtreeRightBoundary, context, hostNamespace, null);
|
|
111
|
+
pushMountChildrenFrame(element, renderRuntime, children, parentReference, subtreeRightBoundary, element.context, hostNamespace);
|
|
112
|
+
}
|
|
113
|
+
function mountFCExit(frame) {
|
|
114
|
+
getLifecycleEventBus(frame.renderRuntime).publish({
|
|
115
|
+
type: 'mounted',
|
|
116
|
+
element: frame.node,
|
|
117
|
+
renderRuntime: frame.renderRuntime,
|
|
169
118
|
});
|
|
170
119
|
}
|
|
171
|
-
function
|
|
172
|
-
frame.node.reference = frame.
|
|
173
|
-
|
|
120
|
+
function mountTextElement(frame) {
|
|
121
|
+
frame.node.reference = frame.renderRuntime.hostAdapter.createTextReference(frame.node.children);
|
|
122
|
+
pushHostOperationPlaceElement(frame.node, frame.renderRuntime, frame.parentReference, frame.subtreeRightBoundary);
|
|
174
123
|
}
|
|
175
|
-
function
|
|
124
|
+
function mountPortalEnter(frame) {
|
|
176
125
|
const element = frame.node;
|
|
177
|
-
const { parentReference, subtreeRightBoundary, context, renderRuntime } = frame
|
|
178
|
-
if (frame.kind === MOUNT_EXIT) {
|
|
179
|
-
element.reference = frame.meta.placeHolderElement.reference;
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
126
|
+
const { parentReference, subtreeRightBoundary, context, renderRuntime } = frame;
|
|
182
127
|
const placeHolderElement = createTextElement('');
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
placeHolderElement,
|
|
190
|
-
});
|
|
191
|
-
_pushMountChildrenFrame(element, {
|
|
192
|
-
renderRuntime,
|
|
193
|
-
hostNamespace: renderRuntime.hostAdapter.getHostNamespaces(element.children, undefined)?.self,
|
|
194
|
-
subtreeRightBoundary,
|
|
195
|
-
context,
|
|
196
|
-
parentReference: element.ref,
|
|
197
|
-
children: element.children,
|
|
198
|
-
});
|
|
199
|
-
_pushMountEnterFrame(placeHolderElement, {
|
|
200
|
-
renderRuntime,
|
|
201
|
-
subtreeRightBoundary,
|
|
202
|
-
context: null,
|
|
203
|
-
parentReference,
|
|
204
|
-
hostNamespace: null,
|
|
205
|
-
placeHolderElement: null,
|
|
206
|
-
});
|
|
128
|
+
pushMountExitFrame(element, renderRuntime, null, subtreeRightBoundary, null, null, placeHolderElement);
|
|
129
|
+
pushMountChildrenFrame(element, renderRuntime, element.children, element.ref, subtreeRightBoundary, context, renderRuntime.hostAdapter.getHostNamespaces(element.children, undefined)?.self);
|
|
130
|
+
pushMountEnterFrame(placeHolderElement, renderRuntime, parentReference, subtreeRightBoundary, null, null, null);
|
|
131
|
+
}
|
|
132
|
+
function mountPortalExit(frame) {
|
|
133
|
+
frame.node.reference = frame.placeHolderElement.reference;
|
|
207
134
|
}
|
|
208
|
-
function
|
|
135
|
+
function mountFragment(frame) {
|
|
209
136
|
const element = frame.node;
|
|
210
|
-
const { parentReference, hostNamespace, context, renderRuntime, subtreeRightBoundary } = frame
|
|
211
|
-
|
|
212
|
-
renderRuntime,
|
|
213
|
-
hostNamespace,
|
|
214
|
-
children: element.children,
|
|
215
|
-
parentReference,
|
|
216
|
-
context,
|
|
217
|
-
subtreeRightBoundary: subtreeRightBoundary,
|
|
218
|
-
});
|
|
137
|
+
const { parentReference, hostNamespace, context, renderRuntime, subtreeRightBoundary } = frame;
|
|
138
|
+
pushMountChildrenFrame(element, renderRuntime, element.children, parentReference, subtreeRightBoundary, context, hostNamespace);
|
|
219
139
|
}
|
package/core/mountingChildren.js
CHANGED
|
@@ -1,46 +1,28 @@
|
|
|
1
1
|
import { SIMP_ELEMENT_CHILD_FLAG_ELEMENT, SIMP_ELEMENT_CHILD_FLAG_LIST } from './createElement.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { pushMountEnterFrame } from './mounting.js';
|
|
3
|
+
import { acquireMountChildrenFrame } from './processStack.js';
|
|
4
4
|
import { isHostLike } from './utils.js';
|
|
5
|
-
export function
|
|
6
|
-
|
|
7
|
-
node: parent,
|
|
8
|
-
kind: MOUNT_CHILDREN_ENTER,
|
|
9
|
-
meta,
|
|
10
|
-
});
|
|
5
|
+
export function pushMountChildrenFrame(parent, renderRuntime, children, parentReference, subtreeRightBoundary, context, hostNamespace) {
|
|
6
|
+
renderRuntime.renderStack.push(acquireMountChildrenFrame(renderRuntime, parent, children, parentReference, subtreeRightBoundary, context, hostNamespace));
|
|
11
7
|
}
|
|
12
|
-
export function
|
|
8
|
+
export function mountChildren(frame) {
|
|
13
9
|
const parentElement = frame.node;
|
|
14
|
-
const { parentReference, hostNamespace, renderRuntime, context } = frame
|
|
15
|
-
const subtreeRightBoundary = isHostLike(parentElement.flag) ? null : frame.
|
|
10
|
+
const { parentReference, hostNamespace, renderRuntime, context } = frame;
|
|
11
|
+
const subtreeRightBoundary = isHostLike(parentElement.flag) ? null : frame.subtreeRightBoundary;
|
|
16
12
|
switch (parentElement.childFlag) {
|
|
17
13
|
case SIMP_ELEMENT_CHILD_FLAG_ELEMENT: {
|
|
18
|
-
const children = frame.
|
|
14
|
+
const children = frame.children;
|
|
19
15
|
children.parent = parentElement;
|
|
20
|
-
|
|
21
|
-
renderRuntime,
|
|
22
|
-
hostNamespace,
|
|
23
|
-
subtreeRightBoundary,
|
|
24
|
-
context,
|
|
25
|
-
parentReference,
|
|
26
|
-
placeHolderElement: null,
|
|
27
|
-
});
|
|
16
|
+
pushMountEnterFrame(children, renderRuntime, parentReference, subtreeRightBoundary, context, hostNamespace, null);
|
|
28
17
|
break;
|
|
29
18
|
}
|
|
30
19
|
case SIMP_ELEMENT_CHILD_FLAG_LIST: {
|
|
31
|
-
const children = frame.
|
|
20
|
+
const children = frame.children;
|
|
32
21
|
for (let i = children.length - 1; i >= 0; i--) {
|
|
33
22
|
const child = children[i];
|
|
34
23
|
child.parent = parentElement;
|
|
35
24
|
const rightSibling = children[child.index + 1] || subtreeRightBoundary;
|
|
36
|
-
|
|
37
|
-
renderRuntime,
|
|
38
|
-
parentReference,
|
|
39
|
-
context,
|
|
40
|
-
hostNamespace,
|
|
41
|
-
subtreeRightBoundary: rightSibling,
|
|
42
|
-
placeHolderElement: null,
|
|
43
|
-
});
|
|
25
|
+
pushMountEnterFrame(child, renderRuntime, parentReference, rightSibling, context, hostNamespace, null);
|
|
44
26
|
}
|
|
45
27
|
}
|
|
46
28
|
}
|