@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/createElement.js
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import { isSimpText } from '../shared/index.js';
|
|
2
|
+
import { SIMP_ELEMENT_CHILD_FLAG_ELEMENT, SIMP_ELEMENT_CHILD_FLAG_EMPTY, SIMP_ELEMENT_CHILD_FLAG_LIST, SIMP_ELEMENT_CHILD_FLAG_TEXT, SIMP_ELEMENT_CHILD_FLAG_UNKNOWN, SIMP_ELEMENT_FLAG_FC, SIMP_ELEMENT_FLAG_FRAGMENT, SIMP_ELEMENT_FLAG_HOST, SIMP_ELEMENT_FLAG_PORTAL, SIMP_ELEMENT_FLAG_TEXT, } from './flags.js';
|
|
2
3
|
import { Fragment } from './fragment.js';
|
|
3
|
-
export
|
|
4
|
-
export const SIMP_ELEMENT_FLAG_FC = 1 << 1;
|
|
5
|
-
export const SIMP_ELEMENT_FLAG_TEXT = 1 << 2;
|
|
6
|
-
export const SIMP_ELEMENT_FLAG_PORTAL = 1 << 3;
|
|
7
|
-
export const SIMP_ELEMENT_FLAG_FRAGMENT = 1 << 4;
|
|
8
|
-
export const SIMP_ELEMENT_CHILD_FLAG_EMPTY = 1;
|
|
9
|
-
export const SIMP_ELEMENT_CHILD_FLAG_UNKNOWN = 1 << 1;
|
|
10
|
-
export const SIMP_ELEMENT_CHILD_FLAG_ELEMENT = 1 << 2;
|
|
11
|
-
export const SIMP_ELEMENT_CHILD_FLAG_LIST = 1 << 3;
|
|
12
|
-
export const SIMP_ELEMENT_CHILD_FLAG_TEXT = 1 << 4;
|
|
4
|
+
export * from './flags.js';
|
|
13
5
|
export function createElement(type, props) {
|
|
14
6
|
let definedChildren;
|
|
15
7
|
const argLength = arguments.length;
|
|
@@ -38,9 +30,9 @@ export function createElement(type, props) {
|
|
|
38
30
|
type,
|
|
39
31
|
props: props || null,
|
|
40
32
|
children: null,
|
|
41
|
-
className: props?.className
|
|
33
|
+
className: props?.className ?? props?.class ?? null,
|
|
42
34
|
reference: null,
|
|
43
|
-
|
|
35
|
+
hostNamespace: null,
|
|
44
36
|
context: null,
|
|
45
37
|
ref: props?.ref ? { value: props.ref } : null,
|
|
46
38
|
unmounted: null,
|
|
@@ -63,7 +55,7 @@ export function createElement(type, props) {
|
|
|
63
55
|
children: null,
|
|
64
56
|
className: props?.className || null,
|
|
65
57
|
reference: null,
|
|
66
|
-
|
|
58
|
+
hostNamespace: null,
|
|
67
59
|
context: null,
|
|
68
60
|
ref: props?.ref ? { value: props.ref } : null,
|
|
69
61
|
unmounted: null,
|
|
@@ -84,7 +76,7 @@ export function createElement(type, props) {
|
|
|
84
76
|
children: null,
|
|
85
77
|
className: null,
|
|
86
78
|
reference: null,
|
|
87
|
-
|
|
79
|
+
hostNamespace: null,
|
|
88
80
|
context: null,
|
|
89
81
|
ref: null,
|
|
90
82
|
unmounted: null,
|
|
@@ -92,6 +84,9 @@ export function createElement(type, props) {
|
|
|
92
84
|
};
|
|
93
85
|
}
|
|
94
86
|
default: {
|
|
87
|
+
if (type !== Fragment) {
|
|
88
|
+
throw new Error(`Invalid element type: ${String(type)}`);
|
|
89
|
+
}
|
|
95
90
|
return normalizeChildren({
|
|
96
91
|
flag: SIMP_ELEMENT_FLAG_FRAGMENT,
|
|
97
92
|
childFlag: SIMP_ELEMENT_CHILD_FLAG_UNKNOWN,
|
|
@@ -102,7 +97,7 @@ export function createElement(type, props) {
|
|
|
102
97
|
children: null,
|
|
103
98
|
className: null,
|
|
104
99
|
reference: null,
|
|
105
|
-
|
|
100
|
+
hostNamespace: null,
|
|
106
101
|
context: null,
|
|
107
102
|
ref: null,
|
|
108
103
|
unmounted: null,
|
|
@@ -122,7 +117,7 @@ export function createTextElement(text) {
|
|
|
122
117
|
children: text.toString(),
|
|
123
118
|
className: null,
|
|
124
119
|
reference: null,
|
|
125
|
-
|
|
120
|
+
hostNamespace: null,
|
|
126
121
|
context: null,
|
|
127
122
|
ref: null,
|
|
128
123
|
unmounted: null,
|
|
@@ -170,7 +165,9 @@ function normalizeNode(child, result, currentKey = null, skipIgnoredCheck) {
|
|
|
170
165
|
}
|
|
171
166
|
const element = child;
|
|
172
167
|
if (element.key != null) {
|
|
173
|
-
|
|
168
|
+
const prefix = currentKey ?? '';
|
|
169
|
+
const lastDot = prefix.lastIndexOf('.');
|
|
170
|
+
currentKey = lastDot <= 0 ? String(element.key) : `${prefix.slice(0, lastDot)}${element.key}`;
|
|
174
171
|
}
|
|
175
172
|
element.key = currentKey;
|
|
176
173
|
element.index = result.length;
|
package/core/flags.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const SIMP_ELEMENT_FLAG_HOST = 1;
|
|
2
|
+
export const SIMP_ELEMENT_FLAG_FC = 1 << 1;
|
|
3
|
+
export const SIMP_ELEMENT_FLAG_TEXT = 1 << 2;
|
|
4
|
+
export const SIMP_ELEMENT_FLAG_PORTAL = 1 << 3;
|
|
5
|
+
export const SIMP_ELEMENT_FLAG_FRAGMENT = 1 << 4;
|
|
6
|
+
export const SIMP_ELEMENT_CHILD_FLAG_EMPTY = 1;
|
|
7
|
+
export const SIMP_ELEMENT_CHILD_FLAG_UNKNOWN = 1 << 1;
|
|
8
|
+
export const SIMP_ELEMENT_CHILD_FLAG_ELEMENT = 1 << 2;
|
|
9
|
+
export const SIMP_ELEMENT_CHILD_FLAG_LIST = 1 << 3;
|
|
10
|
+
export const SIMP_ELEMENT_CHILD_FLAG_TEXT = 1 << 4;
|
|
11
|
+
export function isFC(element) {
|
|
12
|
+
return (element.flag & SIMP_ELEMENT_FLAG_FC) !== 0;
|
|
13
|
+
}
|
|
14
|
+
export function isFragment(element) {
|
|
15
|
+
return (element.flag & SIMP_ELEMENT_FLAG_FRAGMENT) !== 0;
|
|
16
|
+
}
|
|
17
|
+
export function isHost(element) {
|
|
18
|
+
return (element.flag & SIMP_ELEMENT_FLAG_HOST) !== 0;
|
|
19
|
+
}
|
|
20
|
+
export function isPortal(element) {
|
|
21
|
+
return (element.flag & SIMP_ELEMENT_FLAG_PORTAL) !== 0;
|
|
22
|
+
}
|
|
23
|
+
export function isText(element) {
|
|
24
|
+
return (element.flag & SIMP_ELEMENT_FLAG_TEXT) !== 0;
|
|
25
|
+
}
|
|
26
|
+
export function hasListChildren(element) {
|
|
27
|
+
return element.childFlag === SIMP_ELEMENT_CHILD_FLAG_LIST;
|
|
28
|
+
}
|
|
29
|
+
export function hasElementChild(element) {
|
|
30
|
+
return element.childFlag === SIMP_ELEMENT_CHILD_FLAG_ELEMENT;
|
|
31
|
+
}
|
package/core/hostOperations.js
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export function
|
|
3
|
-
|
|
4
|
-
node: element,
|
|
5
|
-
kind: HOST_OPS_PLACE_ELEMENT_BEFORE_ANCHOR,
|
|
6
|
-
meta,
|
|
7
|
-
});
|
|
1
|
+
import { acquirePlaceFrame, acquireReplaceFrame } from './processStack.js';
|
|
2
|
+
export function pushHostOperationPlaceElement(element, renderRuntime, parentReference, subtreeRightBoundary) {
|
|
3
|
+
renderRuntime.renderStack.push(acquirePlaceFrame(renderRuntime, element, parentReference, subtreeRightBoundary));
|
|
8
4
|
}
|
|
9
|
-
export function
|
|
10
|
-
renderRuntime.renderStack.push(
|
|
11
|
-
node: element,
|
|
12
|
-
kind: HOST_OPS_REPLACE_CHILD,
|
|
13
|
-
meta,
|
|
14
|
-
});
|
|
5
|
+
export function pushHostOperationReplaceElement(element, renderRuntime, parentReference, prevElement) {
|
|
6
|
+
renderRuntime.renderStack.push(acquireReplaceFrame(renderRuntime, element, parentReference, prevElement));
|
|
15
7
|
}
|
package/core/index.d.ts
CHANGED
|
@@ -1,7 +1,35 @@
|
|
|
1
|
-
import type { Nullable, SimpText } from '../shared/index.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { Maybe, Nullable, SimpText } from '../shared/index.js';
|
|
2
|
+
|
|
3
|
+
export interface HostAdapter<HostRef = unknown, HostTextRef = unknown, NS = string> {
|
|
4
|
+
createReference(type: string, namespace?: Maybe<NS>): HostRef;
|
|
5
|
+
createTextReference(text: string): HostTextRef;
|
|
6
|
+
mountProps(reference: HostRef, element: SimpElement, renderRuntime: SimpRenderRuntime, namespace?: Maybe<NS>): void;
|
|
7
|
+
patchProps(
|
|
8
|
+
reference: HostRef,
|
|
9
|
+
prevElement: SimpElement,
|
|
10
|
+
nextElement: SimpElement,
|
|
11
|
+
renderRuntime: SimpRenderRuntime,
|
|
12
|
+
namespace?: Maybe<NS>
|
|
13
|
+
): void;
|
|
14
|
+
unmountProps(reference: HostRef, element: SimpElement, renderRuntime: SimpRenderRuntime): void;
|
|
15
|
+
setClassname(reference: HostRef, className: Maybe<string>, namespace?: Maybe<NS>): void;
|
|
16
|
+
setTextContent(reference: HostRef, text: string, referenceHasOnlyTextElement?: boolean): void;
|
|
17
|
+
removeChild(parent: HostRef, child: HostRef | HostTextRef): void;
|
|
18
|
+
replaceChild(parent: HostRef, replacer: HostRef | HostTextRef, toBeReplaced: HostRef | HostTextRef): void;
|
|
19
|
+
insertOrAppend(parent: HostRef, child: HostRef | HostTextRef, before: Nullable<HostRef | HostTextRef>): void;
|
|
20
|
+
clearNode(reference: HostRef | HostTextRef): void;
|
|
21
|
+
attachElementToReference(
|
|
22
|
+
element: SimpElement,
|
|
23
|
+
reference: HostRef | HostTextRef,
|
|
24
|
+
renderRuntime: SimpRenderRuntime
|
|
25
|
+
): void;
|
|
26
|
+
detachElementFromReference(reference: HostRef | HostTextRef, renderRuntime: SimpRenderRuntime): void;
|
|
27
|
+
getElementFromReference(reference: HostRef | HostTextRef, renderRuntime: SimpRenderRuntime): Nullable<SimpElement>;
|
|
28
|
+
getHostNamespaces(
|
|
29
|
+
element: SimpElement,
|
|
30
|
+
currentNamespace: Maybe<NS>
|
|
31
|
+
): Nullable<{ self: Nullable<NS>; children: Nullable<NS> }>;
|
|
32
|
+
}
|
|
5
33
|
|
|
6
34
|
export type ComponentType<P = {}> = FunctionalComponent<P>;
|
|
7
35
|
|
|
@@ -57,14 +85,16 @@ export declare function memo<P = {}>(
|
|
|
57
85
|
export declare function withSyncRerender(runtime: SimpRenderRuntime, callback: () => void): void;
|
|
58
86
|
|
|
59
87
|
export interface SimpRuntimeFCRenderer {
|
|
60
|
-
(component: FC, element: SimpElement): SimpNode;
|
|
88
|
+
(component: FC, element: SimpElement, renderRuntime: SimpRenderRuntime): SimpNode;
|
|
61
89
|
}
|
|
62
90
|
|
|
63
91
|
export interface SimpRenderRuntime {
|
|
64
92
|
hostAdapter: HostAdapter;
|
|
65
93
|
renderer: SimpRuntimeFCRenderer;
|
|
66
94
|
renderStack: Array<{ node: SimpElement; kind: number; meta: any }>;
|
|
67
|
-
elementToHostMap: Map<unknown, SimpElement>;
|
|
68
|
-
currentRenderingFCElement: Nullable<SimpElement>;
|
|
69
|
-
renderPhase: Nullable<number>;
|
|
70
95
|
}
|
|
96
|
+
|
|
97
|
+
export declare function createRenderRuntime(
|
|
98
|
+
hostAdapter: HostAdapter,
|
|
99
|
+
renderer: SimpRuntimeFCRenderer
|
|
100
|
+
): SimpRenderRuntime;
|
package/core/index.js
CHANGED
|
@@ -3,5 +3,6 @@ import { Fragment } from './fragment.js';
|
|
|
3
3
|
import { memo } from './memo.js';
|
|
4
4
|
import { createPortal } from './portal.js';
|
|
5
5
|
import { withSyncRerender } from './rerender.js';
|
|
6
|
-
|
|
7
|
-
export
|
|
6
|
+
import { createRenderRuntime } from './runtime.js';
|
|
7
|
+
export { createElement, createRenderRuntime, Fragment, memo, createPortal, withSyncRerender };
|
|
8
|
+
export default { createElement, createRenderRuntime, Fragment, memo, createPortal, withSyncRerender };
|
package/core/internal.d.ts
CHANGED
|
@@ -1,16 +1,136 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import type { Many, Maybe, Nullable } from '../shared/index.js';
|
|
2
|
+
|
|
3
|
+
export type FC = (props: any) => SimpNode;
|
|
4
|
+
export type Key = string | number | bigint;
|
|
5
|
+
export type SimpNode = SimpElement | string | number | bigint | boolean | Array<SimpNode> | null | undefined;
|
|
6
|
+
|
|
7
|
+
export interface SimpElement {
|
|
8
|
+
flag: number;
|
|
9
|
+
childFlag: number;
|
|
10
|
+
parent: Nullable<SimpElement>;
|
|
11
|
+
key: Nullable<Key>;
|
|
12
|
+
type: Nullable<string | FC>;
|
|
13
|
+
props: any;
|
|
14
|
+
children: SimpNode;
|
|
15
|
+
className: Nullable<string>;
|
|
16
|
+
reference: unknown;
|
|
17
|
+
hostNamespace: Nullable<string>;
|
|
18
|
+
context: any;
|
|
19
|
+
ref: any;
|
|
20
|
+
unmounted: Nullable<boolean>;
|
|
21
|
+
index: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type RefObject<T> = { current: T };
|
|
25
|
+
|
|
26
|
+
export interface HostAdapter<HostRef = unknown, HostTextRef = unknown, NS = string> {
|
|
27
|
+
createReference(type: string, namespace?: Maybe<NS>): HostRef;
|
|
28
|
+
createTextReference(text: string): HostTextRef;
|
|
29
|
+
mountProps(reference: HostRef, element: SimpElement, renderRuntime: SimpRenderRuntime, namespace?: Maybe<NS>): void;
|
|
30
|
+
patchProps(
|
|
31
|
+
reference: HostRef,
|
|
32
|
+
prevElement: SimpElement,
|
|
33
|
+
nextElement: SimpElement,
|
|
34
|
+
renderRuntime: SimpRenderRuntime,
|
|
35
|
+
namespace?: Maybe<NS>
|
|
36
|
+
): void;
|
|
37
|
+
unmountProps(reference: HostRef, element: SimpElement, renderRuntime: SimpRenderRuntime): void;
|
|
38
|
+
setClassname(reference: HostRef, className: Maybe<string>, namespace?: Maybe<NS>): void;
|
|
39
|
+
setTextContent(reference: HostRef, text: string, referenceHasOnlyTextElement?: boolean): void;
|
|
40
|
+
removeChild(parent: HostRef, child: HostRef | HostTextRef): void;
|
|
41
|
+
replaceChild(parent: HostRef, replacer: HostRef | HostTextRef, toBeReplaced: HostRef | HostTextRef): void;
|
|
42
|
+
insertOrAppend(parent: HostRef, child: HostRef | HostTextRef, before: Nullable<HostRef | HostTextRef>): void;
|
|
43
|
+
clearNode(reference: HostRef | HostTextRef): void;
|
|
44
|
+
attachElementToReference(
|
|
45
|
+
element: SimpElement,
|
|
46
|
+
reference: HostRef | HostTextRef,
|
|
47
|
+
renderRuntime: SimpRenderRuntime
|
|
48
|
+
): void;
|
|
49
|
+
detachElementFromReference(reference: HostRef | HostTextRef, renderRuntime: SimpRenderRuntime): void;
|
|
50
|
+
getElementFromReference(reference: HostRef | HostTextRef, renderRuntime: SimpRenderRuntime): Nullable<SimpElement>;
|
|
51
|
+
getHostNamespaces(
|
|
52
|
+
element: SimpElement,
|
|
53
|
+
currentNamespace: Maybe<NS>
|
|
54
|
+
): Nullable<{ self: Nullable<NS>; children: Nullable<NS> }>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface SimpRuntimeFCRenderer {
|
|
58
|
+
(component: FC, element: SimpElement, renderRuntime: SimpRenderRuntime): SimpNode;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface SimpRenderFrame {
|
|
62
|
+
kind: number;
|
|
63
|
+
node: SimpElement;
|
|
64
|
+
renderRuntime: SimpRenderRuntime;
|
|
65
|
+
parentReference: unknown;
|
|
66
|
+
subtreeRightBoundary: Nullable<SimpElement>;
|
|
67
|
+
context: unknown;
|
|
68
|
+
hostNamespace: Maybe<string>;
|
|
69
|
+
prevElement: SimpElement;
|
|
70
|
+
children: Nullable<Many<SimpElement>>;
|
|
71
|
+
placeHolderElement: Nullable<SimpElement>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface SimpRenderRuntime {
|
|
75
|
+
hostAdapter: HostAdapter;
|
|
76
|
+
renderer: SimpRuntimeFCRenderer;
|
|
77
|
+
renderStack: Array<any>;
|
|
78
|
+
framePool: SimpRenderFrame[];
|
|
79
|
+
activeRenderElement: SimpElement | null;
|
|
80
|
+
pendingRerenderFlag: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export declare function createRenderRuntime(
|
|
84
|
+
hostAdapter: HostAdapter,
|
|
85
|
+
renderer: SimpRuntimeFCRenderer
|
|
86
|
+
): SimpRenderRuntime;
|
|
87
|
+
|
|
88
|
+
export type LifecycleEvent =
|
|
89
|
+
| { type: 'beforeRender'; element: SimpElement; renderRuntime: SimpRenderRuntime }
|
|
90
|
+
| { type: 'afterRender'; element: SimpElement; renderRuntime: SimpRenderRuntime }
|
|
91
|
+
| { type: 'mounted'; element: SimpElement; renderRuntime: SimpRenderRuntime }
|
|
92
|
+
| { type: 'updated'; element: SimpElement; renderRuntime: SimpRenderRuntime }
|
|
93
|
+
| { type: 'unmounted'; element: SimpElement; renderRuntime: SimpRenderRuntime }
|
|
94
|
+
| { type: 'errored'; element: SimpElement; error: any; handled: boolean; renderRuntime: SimpRenderRuntime };
|
|
95
|
+
|
|
96
|
+
export interface LifecycleEventBus {
|
|
97
|
+
publish(event: LifecycleEvent): void;
|
|
98
|
+
subscribe(subscriber: (event: LifecycleEvent) => boolean | void): () => void;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export declare function isFC(element: { flag: number }): boolean;
|
|
102
|
+
export declare function isFragment(element: { flag: number }): boolean;
|
|
103
|
+
export declare function isHost(element: { flag: number }): boolean;
|
|
104
|
+
export declare function isPortal(element: { flag: number }): boolean;
|
|
105
|
+
export declare function isText(element: { flag: number }): boolean;
|
|
106
|
+
export declare function hasListChildren(element: { childFlag: number }): boolean;
|
|
107
|
+
export declare function hasElementChild(element: { childFlag: number }): boolean;
|
|
108
|
+
|
|
109
|
+
export declare function createElement(type: string | FC, props?: any, ...children: SimpNode[]): SimpElement;
|
|
110
|
+
export declare function Fragment(props: { children?: SimpNode }): SimpElement;
|
|
111
|
+
|
|
112
|
+
export declare function registerLifecyclePlugin(plugin: (bus: LifecycleEventBus) => void): void;
|
|
113
|
+
|
|
114
|
+
export declare function mount(
|
|
115
|
+
element: SimpElement,
|
|
116
|
+
parentReference: unknown,
|
|
117
|
+
subtreeRightBoundary: Nullable<SimpElement>,
|
|
118
|
+
context: unknown,
|
|
119
|
+
hostNamespace: Maybe<string>,
|
|
120
|
+
renderRuntime: SimpRenderRuntime
|
|
121
|
+
): void;
|
|
122
|
+
|
|
123
|
+
export declare function patch(
|
|
124
|
+
prevElement: SimpElement,
|
|
125
|
+
nextElement: SimpElement,
|
|
126
|
+
parentReference: unknown,
|
|
127
|
+
subtreeRightBoundary: Nullable<SimpElement>,
|
|
128
|
+
context: unknown,
|
|
129
|
+
hostNamespace: Maybe<string>,
|
|
130
|
+
renderRuntime: SimpRenderRuntime
|
|
131
|
+
): void;
|
|
132
|
+
|
|
133
|
+
export declare function unmount(element: SimpElement, renderRuntime: SimpRenderRuntime): void;
|
|
134
|
+
|
|
135
|
+
export declare function rerender(element: SimpElement, renderRuntime: SimpRenderRuntime): void;
|
|
136
|
+
export declare function withSyncRerender(renderRuntime: SimpRenderRuntime, callback: () => void): void;
|
package/core/internal.js
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export * from './patchingChildren.js';
|
|
10
|
-
export * from './portal.js';
|
|
11
|
-
export * from './processStack.js';
|
|
12
|
-
export * from './ref.js';
|
|
13
|
-
export * from './rerender.js';
|
|
14
|
-
export * from './runtime.js';
|
|
15
|
-
export * from './unmounting.js';
|
|
16
|
-
export * from './unmountingChildren.js';
|
|
1
|
+
export { createElement, hasElementChild, hasListChildren, isFC, isFragment, isHost, isPortal, isText, } from './createElement.js';
|
|
2
|
+
export { Fragment } from './fragment.js';
|
|
3
|
+
export { registerLifecyclePlugin } from './lifecycleEventBus.js';
|
|
4
|
+
export { mount } from './mounting.js';
|
|
5
|
+
export { patch } from './patching.js';
|
|
6
|
+
export { rerender, withSyncRerender } from './rerender.js';
|
|
7
|
+
export { createRenderRuntime } from './runtime.js';
|
|
8
|
+
export { unmount } from './unmounting.js';
|
|
@@ -1,16 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
subscriber
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
subscribers.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
function createBus() {
|
|
2
|
+
const subscribers = [];
|
|
3
|
+
return {
|
|
4
|
+
publish(event) {
|
|
5
|
+
for (const subscriber of subscribers) {
|
|
6
|
+
subscriber(event);
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
subscribe(subscriber) {
|
|
10
|
+
if (subscribers.indexOf(subscriber) === -1) {
|
|
11
|
+
subscribers.push(subscriber);
|
|
12
|
+
}
|
|
13
|
+
return () => {
|
|
14
|
+
const index = subscribers.indexOf(subscriber);
|
|
15
|
+
if (index !== -1)
|
|
16
|
+
subscribers.splice(index, 1);
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const busByRuntime = new WeakMap();
|
|
22
|
+
const plugins = [];
|
|
23
|
+
export function getLifecycleEventBus(runtime) {
|
|
24
|
+
let bus = busByRuntime.get(runtime);
|
|
25
|
+
if (!bus) {
|
|
26
|
+
bus = createBus();
|
|
27
|
+
for (const plugin of plugins)
|
|
28
|
+
plugin(bus);
|
|
29
|
+
busByRuntime.set(runtime, bus);
|
|
30
|
+
}
|
|
31
|
+
return bus;
|
|
32
|
+
}
|
|
33
|
+
export function registerLifecyclePlugin(plugin) {
|
|
34
|
+
plugins.push(plugin);
|
|
35
|
+
}
|
package/core/memo.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { shallowEqual } from '../shared/index.js';
|
|
2
|
+
const MEMO_BRAND = Symbol('memo');
|
|
2
3
|
export function memo(Component, compare = shallowEqual) {
|
|
3
4
|
const Memoized = (props => Component(props));
|
|
4
5
|
Memoized._compare = compare;
|
|
6
|
+
Memoized[MEMO_BRAND] = true;
|
|
7
|
+
Object.defineProperty(Memoized, 'name', { value: Component.name });
|
|
5
8
|
return Memoized;
|
|
6
9
|
}
|
|
7
10
|
export function isMemo(type) {
|
|
8
|
-
return
|
|
11
|
+
return type?.[MEMO_BRAND] === true;
|
|
9
12
|
}
|