@simpreact/simpreact 0.0.6 → 0.0.8
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/context.d.ts +4 -5
- package/compat/context.js +3 -3
- package/compat/core.d.ts +28 -27
- package/compat/core.js +8 -7
- package/compat/dom.d.ts +5 -5
- package/compat/dom.js +5 -5
- package/compat/hooks.d.ts +7 -8
- package/compat/hooks.js +3 -3
- package/compat/index.d.ts +100 -43
- package/compat/index.js +3 -0
- package/compat/jsx-runtime.d.ts +7 -7
- package/compat/jsx-runtime.js +4 -4
- package/compat/renderRuntime.d.ts +4 -0
- package/compat/renderRuntime.js +3 -0
- package/component/index.d.ts +6 -7
- package/context/index.d.ts +5 -5
- package/context/index.js +1 -1
- package/core/index.d.ts +17 -19
- package/core/index.js +3 -2
- package/core/internal.d.ts +2 -0
- package/core/internal.js +2 -0
- package/core/mounting.d.ts +1 -2
- package/core/mounting.js +50 -101
- package/core/mountingChildren.d.ts +4 -0
- package/core/mountingChildren.js +47 -0
- package/core/patching.d.ts +1 -1
- package/core/patching.js +54 -44
- package/core/patchingChildren.d.ts +3 -3
- package/core/patchingChildren.js +104 -91
- package/core/processStack.d.ts +53 -16
- package/core/processStack.js +23 -11
- package/core/unmounting.d.ts +4 -8
- package/core/unmounting.js +45 -85
- package/core/unmountingChildren.d.ts +4 -0
- package/core/unmountingChildren.js +23 -0
- package/core/utils.d.ts +3 -2
- package/core/utils.js +28 -3
- package/dom/index.d.ts +4 -5
- package/dom/props/dangerInnerHTML.d.ts +5 -5
- package/dom/props/dangerInnerHTML.js +10 -16
- package/dom/props/props.js +5 -5
- package/hooks/index.d.ts +12 -10
- package/hooks/index.js +1 -0
- package/package.json +1 -1
- package/shared/index.d.ts +10 -6
package/core/unmounting.js
CHANGED
|
@@ -1,109 +1,69 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { noop } from '../shared/index.js';
|
|
2
2
|
import { lifecycleEventBus } from './lifecycleEventBus.js';
|
|
3
3
|
import { processStack, UNMOUNT_ENTER, UNMOUNT_EXIT } from './processStack.js';
|
|
4
4
|
import { unmountRef } from './ref.js';
|
|
5
|
-
import {
|
|
5
|
+
import { _pushUnmountChildrenFrame } from './unmountingChildren.js';
|
|
6
|
+
import { _clearElementHostReference, bitScanForwardIndex } from './utils.js';
|
|
7
|
+
const unmountHandlers = [
|
|
8
|
+
_unmountHostElement,
|
|
9
|
+
_unmountFunctionalElement,
|
|
10
|
+
noop,
|
|
11
|
+
_unmountPortalElement,
|
|
12
|
+
_unmountFragmentElement,
|
|
13
|
+
];
|
|
6
14
|
export function unmount(element, renderRuntime) {
|
|
7
15
|
if (renderRuntime.renderStack.length !== 0) {
|
|
8
16
|
throw new Error('Cannot unmount while rendering.');
|
|
9
17
|
}
|
|
10
|
-
_pushUnmountEnterFrame(element, renderRuntime);
|
|
18
|
+
_pushUnmountEnterFrame(element, { renderRuntime });
|
|
11
19
|
processStack(renderRuntime);
|
|
12
20
|
}
|
|
13
21
|
export function _unmount(frame) {
|
|
14
|
-
|
|
15
|
-
if (frame.kind === UNMOUNT_EXIT) {
|
|
16
|
-
if ((current.flag & SIMP_ELEMENT_FLAG_FC) !== 0) {
|
|
17
|
-
current.unmounted = true;
|
|
18
|
-
lifecycleEventBus.publish({ type: 'unmounted', element: current, renderRuntime: frame.meta.renderRuntime });
|
|
19
|
-
current.store = null;
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if ((current.flag & SIMP_ELEMENT_FLAG_HOST) !== 0) {
|
|
23
|
-
unmountRef(current);
|
|
24
|
-
frame.meta.renderRuntime.hostAdapter.unmountProps(current.reference, current, frame.meta.renderRuntime);
|
|
25
|
-
frame.meta.renderRuntime.hostAdapter.detachElementFromReference(current.reference, frame.meta.renderRuntime);
|
|
26
|
-
}
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
if ((current.flag & SIMP_ELEMENT_FLAG_FC) !== 0) {
|
|
30
|
-
if (current.unmounted) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
_pushUnmountExitFrame(current, frame.meta.renderRuntime);
|
|
34
|
-
if (current.children) {
|
|
35
|
-
_pushUnmountEnterFrame(current.children, frame.meta.renderRuntime);
|
|
36
|
-
}
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
if ((current.flag & SIMP_ELEMENT_FLAG_TEXT) !== 0) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if ((current.flag & SIMP_ELEMENT_FLAG_PORTAL) !== 0) {
|
|
43
|
-
_remove(current.children, current.ref, frame.meta.renderRuntime);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
if ((current.flag & SIMP_ELEMENT_FLAG_HOST) !== 0) {
|
|
47
|
-
_pushUnmountExitFrame(current, frame.meta.renderRuntime);
|
|
48
|
-
}
|
|
49
|
-
if (current.childFlag === SIMP_ELEMENT_CHILD_FLAG_ELEMENT) {
|
|
50
|
-
_pushUnmountEnterFrame(current.children, frame.meta.renderRuntime);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (current.childFlag === SIMP_ELEMENT_CHILD_FLAG_LIST) {
|
|
54
|
-
_pushUnmountArrayChildrenFrame(current, frame.meta.renderRuntime);
|
|
55
|
-
}
|
|
22
|
+
unmountHandlers[bitScanForwardIndex(frame.node.flag)](frame);
|
|
56
23
|
}
|
|
57
|
-
export function _pushUnmountEnterFrame(element,
|
|
58
|
-
renderRuntime.renderStack.push({
|
|
24
|
+
export function _pushUnmountEnterFrame(element, meta) {
|
|
25
|
+
meta.renderRuntime.renderStack.push({
|
|
59
26
|
node: element,
|
|
60
27
|
kind: UNMOUNT_ENTER,
|
|
61
|
-
meta
|
|
62
|
-
renderRuntime,
|
|
63
|
-
},
|
|
28
|
+
meta,
|
|
64
29
|
});
|
|
65
30
|
}
|
|
66
|
-
export function _pushUnmountExitFrame(element,
|
|
67
|
-
renderRuntime.renderStack.push({
|
|
31
|
+
export function _pushUnmountExitFrame(element, meta) {
|
|
32
|
+
meta.renderRuntime.renderStack.push({
|
|
68
33
|
node: element,
|
|
69
34
|
kind: UNMOUNT_EXIT,
|
|
70
|
-
meta
|
|
71
|
-
renderRuntime,
|
|
72
|
-
},
|
|
35
|
+
meta,
|
|
73
36
|
});
|
|
74
37
|
}
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
38
|
+
function _unmountFunctionalElement(frame) {
|
|
39
|
+
const current = frame.node;
|
|
40
|
+
if (current.unmounted) {
|
|
41
|
+
return;
|
|
79
42
|
}
|
|
43
|
+
if (frame.kind === UNMOUNT_EXIT) {
|
|
44
|
+
current.unmounted = true;
|
|
45
|
+
lifecycleEventBus.publish({ type: 'unmounted', element: current, renderRuntime: frame.meta.renderRuntime });
|
|
46
|
+
current.store = null;
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
_pushUnmountExitFrame(current, frame.meta);
|
|
50
|
+
_pushUnmountChildrenFrame(current, frame.meta);
|
|
80
51
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const childFlag = element.childFlag;
|
|
89
|
-
if ((element.flag & SIMP_ELEMENT_FLAG_FC) !== 0) {
|
|
90
|
-
element = children;
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
if ((element.flag & SIMP_ELEMENT_FLAG_FRAGMENT) !== 0) {
|
|
94
|
-
switch (childFlag) {
|
|
95
|
-
case SIMP_ELEMENT_CHILD_FLAG_LIST:
|
|
96
|
-
for (let i = 0, len = children.length; i < len; ++i) {
|
|
97
|
-
_clearElementHostReference(children[i], parentHostReference, renderRuntime);
|
|
98
|
-
}
|
|
99
|
-
return;
|
|
100
|
-
case SIMP_ELEMENT_CHILD_FLAG_ELEMENT:
|
|
101
|
-
element = children;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
52
|
+
function _unmountHostElement(frame) {
|
|
53
|
+
const current = frame.node;
|
|
54
|
+
if (frame.kind === UNMOUNT_EXIT) {
|
|
55
|
+
unmountRef(current);
|
|
56
|
+
frame.meta.renderRuntime.hostAdapter.unmountProps(current.reference, current, frame.meta.renderRuntime);
|
|
57
|
+
frame.meta.renderRuntime.hostAdapter.detachElementFromReference(current.reference, frame.meta.renderRuntime);
|
|
58
|
+
return;
|
|
104
59
|
}
|
|
60
|
+
_pushUnmountExitFrame(current, frame.meta);
|
|
61
|
+
_pushUnmountChildrenFrame(current, frame.meta);
|
|
62
|
+
}
|
|
63
|
+
function _unmountPortalElement(frame) {
|
|
64
|
+
_clearElementHostReference(frame.node.children, frame.node.ref, frame.meta.renderRuntime);
|
|
65
|
+
_pushUnmountChildrenFrame(frame.node, frame.meta);
|
|
105
66
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
_pushUnmountEnterFrame(element, renderRuntime);
|
|
67
|
+
function _unmountFragmentElement(frame) {
|
|
68
|
+
_pushUnmountChildrenFrame(frame.node, frame.meta);
|
|
109
69
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type SimpElement } from './createElement.js';
|
|
2
|
+
import { type UnmountChildrenFrame, type UnmountFrameMeta } from './processStack.js';
|
|
3
|
+
export declare function _pushUnmountChildrenFrame(parent: SimpElement, meta: UnmountFrameMeta): void;
|
|
4
|
+
export declare function _unmountChildren(frame: UnmountChildrenFrame): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SIMP_ELEMENT_CHILD_FLAG_ELEMENT, SIMP_ELEMENT_CHILD_FLAG_LIST } from './createElement.js';
|
|
2
|
+
import { UNMOUNT_CHILDREN_ENTER } from './processStack.js';
|
|
3
|
+
import { _pushUnmountEnterFrame } from './unmounting.js';
|
|
4
|
+
export function _pushUnmountChildrenFrame(parent, meta) {
|
|
5
|
+
meta.renderRuntime.renderStack.push({
|
|
6
|
+
node: parent,
|
|
7
|
+
kind: UNMOUNT_CHILDREN_ENTER,
|
|
8
|
+
meta,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
export function _unmountChildren(frame) {
|
|
12
|
+
switch (frame.node.childFlag) {
|
|
13
|
+
case SIMP_ELEMENT_CHILD_FLAG_LIST:
|
|
14
|
+
const children = frame.node.children;
|
|
15
|
+
for (let i = children.length - 1; i >= 0; i -= 1) {
|
|
16
|
+
_pushUnmountEnterFrame(children[i], frame.meta);
|
|
17
|
+
}
|
|
18
|
+
break;
|
|
19
|
+
case SIMP_ELEMENT_CHILD_FLAG_ELEMENT:
|
|
20
|
+
_pushUnmountEnterFrame(frame.node.children, frame.meta);
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
}
|
package/core/utils.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { Nullable } from '../shared/index.js';
|
|
1
|
+
import type { Maybe, Nullable } from '../shared/index.js';
|
|
2
2
|
import { type SimpElement } from './createElement.js';
|
|
3
3
|
import type { SimpRenderRuntime } from './runtime.js';
|
|
4
4
|
export declare function bitScanForwardIndex(flag: number): number;
|
|
5
5
|
export declare function isHostLike(flag: number): boolean;
|
|
6
6
|
export declare function findParentReferenceFromElement(element: SimpElement): unknown | null;
|
|
7
7
|
export declare function placeElementBeforeAnchor(element: SimpElement, anchor: unknown, parentReference: unknown, renderRuntime: SimpRenderRuntime): void;
|
|
8
|
-
export declare function resolveAnchorReference(
|
|
8
|
+
export declare function resolveAnchorReference(subtreeRightBoundary: Nullable<SimpElement>): unknown | null;
|
|
9
9
|
export declare function findHostReferenceFromElement(element: Nullable<SimpElement>): unknown | null;
|
|
10
10
|
export declare function getLongestIncreasingSubsequenceIndexes(sequence: Int32Array): Int32Array;
|
|
11
|
+
export declare function _clearElementHostReference(element: Maybe<SimpElement>, parentHostReference: unknown, renderRuntime: SimpRenderRuntime): void;
|
package/core/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SIMP_ELEMENT_CHILD_FLAG_ELEMENT, SIMP_ELEMENT_CHILD_FLAG_LIST, SIMP_ELEMENT_FLAG_HOST, SIMP_ELEMENT_FLAG_PORTAL, SIMP_ELEMENT_FLAG_TEXT, } from './createElement.js';
|
|
1
|
+
import { SIMP_ELEMENT_CHILD_FLAG_ELEMENT, SIMP_ELEMENT_CHILD_FLAG_LIST, SIMP_ELEMENT_FLAG_FC, SIMP_ELEMENT_FLAG_FRAGMENT, SIMP_ELEMENT_FLAG_HOST, SIMP_ELEMENT_FLAG_PORTAL, SIMP_ELEMENT_FLAG_TEXT, } from './createElement.js';
|
|
2
2
|
export function bitScanForwardIndex(flag) {
|
|
3
3
|
const lsb = (flag & -flag) >>> 0;
|
|
4
4
|
return 31 - Math.clz32(lsb);
|
|
@@ -43,8 +43,8 @@ export function placeElementBeforeAnchor(element, anchor, parentReference, rende
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
export function resolveAnchorReference(
|
|
47
|
-
let current =
|
|
46
|
+
export function resolveAnchorReference(subtreeRightBoundary) {
|
|
47
|
+
let current = subtreeRightBoundary;
|
|
48
48
|
while (current != null) {
|
|
49
49
|
const reference = findHostReferenceFromElement(current);
|
|
50
50
|
if (reference != null) {
|
|
@@ -141,3 +141,28 @@ export function getLongestIncreasingSubsequenceIndexes(sequence) {
|
|
|
141
141
|
}
|
|
142
142
|
return indexes;
|
|
143
143
|
}
|
|
144
|
+
export function _clearElementHostReference(element, parentHostReference, renderRuntime) {
|
|
145
|
+
while (element != null) {
|
|
146
|
+
if (isHostLike(element.flag)) {
|
|
147
|
+
renderRuntime.hostAdapter.removeChild(parentHostReference, element.reference);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const children = element.children;
|
|
151
|
+
const childFlag = element.childFlag;
|
|
152
|
+
if ((element.flag & SIMP_ELEMENT_FLAG_FC) !== 0) {
|
|
153
|
+
element = children;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if ((element.flag & SIMP_ELEMENT_FLAG_FRAGMENT) !== 0) {
|
|
157
|
+
switch (childFlag) {
|
|
158
|
+
case SIMP_ELEMENT_CHILD_FLAG_LIST:
|
|
159
|
+
for (let i = 0, len = children.length; i < len; ++i) {
|
|
160
|
+
_clearElementHostReference(children[i], parentHostReference, renderRuntime);
|
|
161
|
+
}
|
|
162
|
+
return;
|
|
163
|
+
case SIMP_ELEMENT_CHILD_FLAG_ELEMENT:
|
|
164
|
+
element = children;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
package/dom/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { RefAttributes, SimpElement, SimpNode, SimpRenderRuntime } from '../core/index.js';
|
|
2
|
-
import type { HostAdapter } from '../core/internal.js';
|
|
1
|
+
import type { HostAdapter, RefAttributes, SimpElement, SimpNode, SimpRenderRuntime } from '../core/index.js';
|
|
3
2
|
import type { Nullable } from '../shared/index.js';
|
|
4
3
|
|
|
5
4
|
import type { PropertiesHyphen } from 'csstype';
|
|
@@ -17,15 +16,15 @@ export interface SimpRoot {
|
|
|
17
16
|
unmount(): void;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
declare function createCreateRoot(
|
|
19
|
+
export declare function createCreateRoot(
|
|
21
20
|
renderRuntime: SimpRenderRuntime
|
|
22
21
|
): (container: Element | DocumentFragment) => SimpRoot;
|
|
23
22
|
|
|
24
|
-
declare function createRenderer(
|
|
23
|
+
export declare function createRenderer(
|
|
25
24
|
renderRuntime: SimpRenderRuntime
|
|
26
25
|
): (element: SimpElement, parentReference: Nullable<HTMLElement>) => void;
|
|
27
26
|
|
|
28
|
-
declare const domAdapter: HostAdapter;
|
|
27
|
+
export declare const domAdapter: HostAdapter;
|
|
29
28
|
|
|
30
29
|
export interface SimpReactHTMLElement<T extends HTMLElement>
|
|
31
30
|
extends DetailedSimpReactHTMLElement<AllHTMLAttributes<T>, T> {}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { SimpElement
|
|
1
|
+
import type { SimpElement } from '../../core/internal.js';
|
|
2
2
|
import type { Maybe } from '../../shared/index.js';
|
|
3
|
-
|
|
3
|
+
type DangerInnerHTMLValue = {
|
|
4
4
|
__html: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
}
|
|
5
|
+
};
|
|
6
|
+
export declare function patchDangerInnerHTML(prevValue: Maybe<DangerInnerHTMLValue>, nextValue: Maybe<DangerInnerHTMLValue>, nextElement: SimpElement, dom: Element): void;
|
|
7
|
+
export {};
|
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const nextHTML = nextValue?.__html || '';
|
|
1
|
+
export function patchDangerInnerHTML(prevValue, nextValue, nextElement, dom) {
|
|
2
|
+
const prevHTML = prevValue?.__html;
|
|
3
|
+
const nextHTML = nextValue?.__html;
|
|
5
4
|
if (nextElement.children) {
|
|
6
|
-
console.warn('Avoid setting both children and props.dangerouslySetInnerHTML at the same time — this
|
|
5
|
+
console.warn('Avoid setting both children and props.dangerouslySetInnerHTML at the same time — this causes unpredictable behavior.');
|
|
7
6
|
}
|
|
8
|
-
if (prevHTML
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
prevElement.children = undefined;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
dom.innerHTML = nextHTML;
|
|
18
|
-
}
|
|
7
|
+
if (prevHTML === nextHTML) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const nextInnerHTML = nextHTML ?? '';
|
|
11
|
+
if (!isSameInnerHTML(dom, nextInnerHTML)) {
|
|
12
|
+
dom.innerHTML = nextInnerHTML;
|
|
19
13
|
}
|
|
20
14
|
}
|
|
21
15
|
function isSameInnerHTML(dom, innerHTML) {
|
package/dom/props/props.js
CHANGED
|
@@ -7,7 +7,7 @@ import { patchStyle } from './style.js';
|
|
|
7
7
|
export function mountProps(dom, element, namespace, renderRuntime) {
|
|
8
8
|
if (!isFormElement(element)) {
|
|
9
9
|
for (const propName in element.props) {
|
|
10
|
-
patchDefaultElementPropAndAttrs(propName, dom,
|
|
10
|
+
patchDefaultElementPropAndAttrs(propName, dom, element, null, element.props[propName], namespace, renderRuntime);
|
|
11
11
|
}
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
@@ -41,12 +41,12 @@ export function patchProps(dom, prevElement, nextElement, namespace, renderRunti
|
|
|
41
41
|
const prevValue = prevProps[propName];
|
|
42
42
|
const nextValue = nextProps[propName];
|
|
43
43
|
if (prevValue !== nextValue) {
|
|
44
|
-
patchDefaultElementPropAndAttrs(propName, dom,
|
|
44
|
+
patchDefaultElementPropAndAttrs(propName, dom, nextElement, prevValue, nextValue, namespace, renderRuntime);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
for (const propName in prevProps) {
|
|
48
48
|
if (nextProps[propName] == null && prevProps[propName] != null) {
|
|
49
|
-
patchDefaultElementPropAndAttrs(propName, dom,
|
|
49
|
+
patchDefaultElementPropAndAttrs(propName, dom, nextElement, prevProps[propName], null, namespace, renderRuntime);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
return;
|
|
@@ -122,7 +122,7 @@ function patchFormElementsPropAndAttrs(propName, dom, element, isControlled, pre
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
function patchDefaultElementPropAndAttrs(propName, dom,
|
|
125
|
+
function patchDefaultElementPropAndAttrs(propName, dom, nextElement, prevValue, nextValue, namespace, renderRuntime) {
|
|
126
126
|
switch (propName) {
|
|
127
127
|
case 'children':
|
|
128
128
|
case 'className':
|
|
@@ -153,7 +153,7 @@ function patchDefaultElementPropAndAttrs(propName, dom, prevElement, nextElement
|
|
|
153
153
|
patchStyle(prevValue, nextValue, dom);
|
|
154
154
|
break;
|
|
155
155
|
case 'dangerouslySetInnerHTML':
|
|
156
|
-
patchDangerInnerHTML(prevValue, nextValue,
|
|
156
|
+
patchDangerInnerHTML(prevValue, nextValue, nextElement, dom);
|
|
157
157
|
break;
|
|
158
158
|
default:
|
|
159
159
|
if (isPropNameEventName(propName)) {
|
package/hooks/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { RefObject, SimpRenderRuntime } from '../core/index.js';
|
|
2
|
-
|
|
3
|
-
export type Cleanup = () => void;
|
|
4
|
-
export type Effect = () => void | Cleanup;
|
|
5
|
-
export type DependencyList = readonly unknown[];
|
|
2
|
+
import type { DependencyList, Effect } from '../shared/index.js';
|
|
6
3
|
|
|
7
4
|
export type Dispatch<A> = (value: A) => void;
|
|
8
5
|
export type SetStateAction<S> = S | ((prevState: S) => S);
|
|
@@ -12,18 +9,23 @@ export interface UseRef {
|
|
|
12
9
|
<T>(initialValue: T | null): RefObject<T | null>;
|
|
13
10
|
<T = undefined>(initialValue?: T): RefObject<T | undefined>;
|
|
14
11
|
}
|
|
15
|
-
declare function createUseRef(renderRuntime: SimpRenderRuntime): UseRef;
|
|
12
|
+
export declare function createUseRef(renderRuntime: SimpRenderRuntime): UseRef;
|
|
16
13
|
|
|
17
|
-
declare function createUseRerender(renderRuntime: SimpRenderRuntime): () => void;
|
|
14
|
+
export declare function createUseRerender(renderRuntime: SimpRenderRuntime): () => void;
|
|
18
15
|
|
|
19
16
|
export interface UseState {
|
|
20
17
|
<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>];
|
|
21
18
|
<S>(): [S | undefined, Dispatch<SetStateAction<S | undefined>>];
|
|
22
19
|
}
|
|
23
|
-
declare function createUseState(renderRuntime: SimpRenderRuntime):
|
|
20
|
+
export declare function createUseState(renderRuntime: SimpRenderRuntime): UseState;
|
|
24
21
|
|
|
25
|
-
declare function createUseEffect(
|
|
22
|
+
export declare function createUseEffect(
|
|
23
|
+
renderRuntime: SimpRenderRuntime
|
|
24
|
+
): (effect: Effect, deps?: DependencyList) => void;
|
|
26
25
|
|
|
27
|
-
declare function createUseCatch(renderRuntime: SimpRenderRuntime): (cb: (error: any) => void) => void;
|
|
26
|
+
export declare function createUseCatch(renderRuntime: SimpRenderRuntime): (cb: (error: any) => void) => void;
|
|
28
27
|
|
|
29
|
-
declare function areDepsEqual(
|
|
28
|
+
export declare function areDepsEqual(
|
|
29
|
+
nextDeps: DependencyList | undefined,
|
|
30
|
+
prevDeps: DependencyList | undefined
|
|
31
|
+
): boolean;
|
package/hooks/index.js
CHANGED
|
@@ -9,6 +9,7 @@ function getHooksSpecificStore(store) {
|
|
|
9
9
|
}
|
|
10
10
|
return hooksSpecificStore;
|
|
11
11
|
}
|
|
12
|
+
window.__SIMP_HOOKS_SPECIFIC_STORE_BY_ELEMENT_STORE__ = hooksSpecificStoreByElementStore;
|
|
12
13
|
lifecycleEventBus.subscribe(event => {
|
|
13
14
|
if ((event.element.flag & SIMP_ELEMENT_FLAG_FC) === 0) {
|
|
14
15
|
return;
|
package/package.json
CHANGED
package/shared/index.d.ts
CHANGED
|
@@ -8,9 +8,9 @@ export type Dict<T = any> = Record<string, T>;
|
|
|
8
8
|
|
|
9
9
|
export type SimpText = string | number | bigint;
|
|
10
10
|
|
|
11
|
-
type Subscriber<Event> = (event: Event) => boolean | void;
|
|
11
|
+
export type Subscriber<Event> = (event: Event) => boolean | void;
|
|
12
12
|
|
|
13
|
-
declare class EventBus<Event = void> {
|
|
13
|
+
export declare class EventBus<Event = void> {
|
|
14
14
|
public publish(event: Event): void;
|
|
15
15
|
|
|
16
16
|
public subscribe(subscriber: Subscriber<Event>): () => void;
|
|
@@ -26,10 +26,14 @@ export interface EffectState {
|
|
|
26
26
|
deps: Nullable<DependencyList>;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
declare function isSimpText(value: unknown): value is SimpText;
|
|
29
|
+
export declare function isSimpText(value: unknown): value is SimpText;
|
|
30
30
|
|
|
31
|
-
declare function noop(): void;
|
|
31
|
+
export declare function noop(): void;
|
|
32
32
|
|
|
33
|
-
declare function callOrGet<T, A extends any[]>(value: T | ((...args: A) => T), ...args: A): T;
|
|
33
|
+
export declare function callOrGet<T, A extends any[]>(value: T | ((...args: A) => T), ...args: A): T;
|
|
34
34
|
|
|
35
|
-
declare function shallowEqual(objA: any, objB: any): boolean;
|
|
35
|
+
export declare function shallowEqual(objA: any, objB: any): boolean;
|
|
36
|
+
|
|
37
|
+
export declare const emptyObject: Readonly<Record<never, never>>;
|
|
38
|
+
export declare const emptyMap: ReadonlyMap<never, never>;
|
|
39
|
+
export declare const emptyArray: ReadonlyArray<never>;
|