frosty 0.0.13 → 0.0.14
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/dist/_native.js +3 -4
- package/dist/_native.js.map +1 -1
- package/dist/_native.mjs +2 -3
- package/dist/_native.mjs.map +1 -1
- package/dist/dom.js +3 -4
- package/dist/dom.js.map +1 -1
- package/dist/dom.mjs +3 -4
- package/dist/dom.mjs.map +1 -1
- package/dist/index.d.ts +307 -6
- package/dist/index.js +668 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +639 -6
- package/dist/index.mjs.map +1 -1
- package/dist/internals/{common-CEjwzc0j.js → common-FG7T3c2f.js} +2 -2
- package/dist/internals/{common-CEjwzc0j.js.map → common-FG7T3c2f.js.map} +1 -1
- package/dist/internals/{common-CQOkvSXp.mjs → common-KSKXTzR8.mjs} +2 -2
- package/dist/internals/{common-CQOkvSXp.mjs.map → common-KSKXTzR8.mjs.map} +1 -1
- package/dist/internals/{renderer-CTxeL82F.mjs → renderer-GTnF-hYa.mjs} +2 -3
- package/dist/internals/{renderer-CTxeL82F.mjs.map → renderer-GTnF-hYa.mjs.map} +1 -1
- package/dist/internals/{renderer-BL3b1IbL.js → renderer-jjw2FwKT.js} +8 -9
- package/dist/internals/{renderer-BL3b1IbL.js.map → renderer-jjw2FwKT.js.map} +1 -1
- package/dist/internals/{sync-Cq3pCYO3.mjs → sync-B9zfuWYQ.mjs} +60 -60
- package/dist/internals/sync-B9zfuWYQ.mjs.map +1 -0
- package/dist/internals/{sync-CSxmMfGm.js → sync-BIbWmXEq.js} +74 -74
- package/dist/internals/sync-BIbWmXEq.js.map +1 -0
- package/dist/internals/{state-BiYNImPF.mjs → utils-BJL3yvTI.mjs} +61 -48
- package/dist/internals/utils-BJL3yvTI.mjs.map +1 -0
- package/dist/internals/{state-DH_D-jro.js → utils-Bipfwp1R.js} +61 -47
- package/dist/internals/utils-Bipfwp1R.js.map +1 -0
- package/dist/jsx-runtime.js +29 -2
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/jsx-runtime.mjs +29 -2
- package/dist/jsx-runtime.mjs.map +1 -1
- package/dist/server-dom.js +3 -4
- package/dist/server-dom.js.map +1 -1
- package/dist/server-dom.mjs +3 -4
- package/dist/server-dom.mjs.map +1 -1
- package/dist/web.d.ts +2 -2
- package/dist/web.js +30 -15
- package/dist/web.js.map +1 -1
- package/dist/web.mjs +26 -11
- package/dist/web.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/hooks.d.ts +0 -301
- package/dist/hooks.d.ts.map +0 -1
- package/dist/hooks.js +0 -456
- package/dist/hooks.js.map +0 -1
- package/dist/hooks.mjs +0 -447
- package/dist/hooks.mjs.map +0 -1
- package/dist/internals/fragment-B0rB4qEp.js +0 -32
- package/dist/internals/fragment-B0rB4qEp.js.map +0 -1
- package/dist/internals/fragment-DPs1AriN.mjs +0 -30
- package/dist/internals/fragment-DPs1AriN.mjs.map +0 -1
- package/dist/internals/state-0jEjYdYV.js +0 -203
- package/dist/internals/state-0jEjYdYV.js.map +0 -1
- package/dist/internals/state-BiYNImPF.mjs.map +0 -1
- package/dist/internals/state-DH_D-jro.js.map +0 -1
- package/dist/internals/state-zydBhS8M.mjs +0 -197
- package/dist/internals/state-zydBhS8M.mjs.map +0 -1
- package/dist/internals/sync-CSxmMfGm.js.map +0 -1
- package/dist/internals/sync-Cq3pCYO3.mjs.map +0 -1
- package/dist/internals/utils-DAEKakog.mjs +0 -42
- package/dist/internals/utils-DAEKakog.mjs.map +0 -1
- package/dist/internals/utils-Dc66ARNS.js +0 -44
- package/dist/internals/utils-Dc66ARNS.js.map +0 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
|
-
import { r as reconciler, V as VNode, e as equalDeps } from './
|
|
2
|
+
import { r as reconciler, m as mergeRefs, V as VNode, e as equalDeps } from './utils-BJL3yvTI.mjs';
|
|
3
3
|
import { N as NativeElementType } from './component-tyF62qKh.mjs';
|
|
4
4
|
import nextick from 'nextick';
|
|
5
|
-
import { m as mergeRefs } from './utils-DAEKakog.mjs';
|
|
6
5
|
|
|
7
6
|
//
|
|
8
7
|
// renderer.ts
|
|
@@ -158,4 +157,4 @@ class _Renderer {
|
|
|
158
157
|
}
|
|
159
158
|
|
|
160
159
|
export { _Renderer as _ };
|
|
161
|
-
//# sourceMappingURL=renderer-
|
|
160
|
+
//# sourceMappingURL=renderer-GTnF-hYa.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer-CTxeL82F.mjs","sources":["../../../src/core/renderer.ts"],"sourcesContent":["//\n// renderer.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { VNode } from './reconciler/vnode';\nimport { ComponentNode, NativeElementType } from './types/component';\nimport { reconciler } from './reconciler/state';\nimport nextick from 'nextick';\nimport { mergeRefs } from './utils';\nimport { equalDeps } from './reconciler/utils';\n\nexport abstract class _Renderer<T> {\n\n protected abstract _beforeUpdate(): void;\n\n protected abstract _afterUpdate(): void;\n\n protected abstract _createElement(node: VNode, stack: VNode[]): T;\n\n protected abstract _updateElement(node: VNode, element: T, stack: VNode[]): void;\n\n protected abstract _destroyElement(node: VNode, element: T): void;\n\n protected abstract _replaceChildren(node: VNode, element: T, children: (T | string)[]): void;\n\n abstract get _server(): boolean;\n\n private _createRoot(\n root: T | null,\n component: ComponentNode,\n options?: {\n skipMount?: boolean;\n },\n ) {\n\n const runtime = reconciler.buildVNodes(component, this);\n\n type _State = {\n hook: string;\n deps: any;\n unmount?: () => void;\n };\n\n const mountState = new Map<VNode, _State[]>();\n\n const children = (node: VNode, elements: Map<VNode, T>): (string | T)[] => {\n return _.flatMap(node.children, x => _.isString(x) ? x : elements.get(x) ?? children(x, elements));\n };\n\n const commit = (elements: Map<VNode, T>) => {\n\n const _mount = (\n node: VNode,\n ) => {\n const element = elements.get(node);\n if (element) {\n mergeRefs(node.props.ref)(element);\n this._replaceChildren(node, element, children(node, elements));\n }\n for (const item of node.children) {\n if (item instanceof VNode) _mount(item);\n }\n const state: _State[] = [];\n const prevState = mountState.get(node) ?? [];\n const curState = node.state;\n for (const i of _.range(Math.max(prevState.length, curState.length))) {\n const unmount = prevState[i]?.unmount;\n if (unmount &&\n (prevState[i].hook !== curState[i]?.hook || !equalDeps(prevState[i].deps, curState[i]?.deps))\n ) unmount();\n state.push({\n hook: curState[i].hook,\n deps: curState[i].deps,\n unmount: options?.skipMount ? undefined : curState[i].mount?.(),\n });\n }\n mountState.set(node, state);\n };\n\n for (const [node, state] of mountState) {\n if (elements.has(node)) continue;\n for (const { unmount } of state) unmount?.();\n mountState.delete(node);\n }\n if (root) this._replaceChildren(runtime.node, root, _.castArray(elements.get(runtime.node) ?? children(runtime.node, elements)));\n _mount(runtime.node);\n };\n\n const update = (elements?: Map<VNode, T>) => {\n this._beforeUpdate();\n const map = new Map<VNode, T>();\n for (const { node, stack, updated } of runtime.excute()) {\n if (node.error) continue;\n if (_.isFunction(node.type) && !(node.type.prototype instanceof NativeElementType)) continue;\n if (updated) {\n let elem = elements?.get(node);\n if (elem) {\n this._updateElement(node, elem, stack);\n } else {\n elem = this._createElement(node, stack);\n }\n map.set(node, elem);\n } else {\n map.set(node, elements?.get(node) ?? this._createElement(node, stack));\n }\n }\n commit(map);\n if (elements) {\n for (const [node, element] of elements) {\n if (map.has(node)) continue;\n this._destroyElement(node, element);\n }\n }\n this._afterUpdate();\n return map;\n };\n\n let update_count = 0;\n let render_count = 0;\n let destroyed = false;\n let elements = update();\n\n const listener = runtime.event.register('onchange', () => {\n if (render_count !== update_count++) return;\n nextick(() => {\n if (destroyed) return;\n render_count = update_count;\n elements = update(elements);\n });\n });\n\n return {\n get root() {\n if (root) return root;\n const elems = _.castArray(elements.get(runtime.node) ?? children(runtime.node, elements));\n const nodes = _.filter(elems, x => !_.isString(x)) as T[];\n return nodes.length === 1 ? nodes[0] : nodes;\n },\n destroy: () => {\n if (root) this._replaceChildren(runtime.node, root, []);\n destroyed = true;\n listener.remove();\n for (const state of mountState.values()) {\n for (const { unmount } of state) unmount?.();\n }\n },\n };\n }\n\n createRoot(root?: T) {\n let state: ReturnType<typeof this._createRoot> | undefined;\n return {\n get root() {\n return state?.root;\n },\n mount: (\n component: ComponentNode,\n options?: {\n skipMount?: boolean;\n },\n ) => {\n state = this._createRoot(root ?? null, component, options);\n },\n unmount: () => {\n state?.destroy();\n state = undefined;\n },\n };\n }\n}"],"names":[],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MAUsB,SAAS,CAAA;AAgBrB,IAAA,WAAW,CACjB,IAAc,EACd,SAAwB,EACxB,OAEC,EAAA;QAGD,MAAM,OAAO,GAAG,UAAU,CAAC,WAAW,CAAC,SAAS,EAAE,IAAI,CAAC;AAQ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E,IAAI;aACnB;AACD,YAAA,KAAK,EAAE,CACL,SAAwB,EACxB,OAEC,KACC;AACF,gBAAA,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC;aAC3D;YACD,OAAO,EAAE,MAAK;gBACZ,KAAK,EAAE,OAAO,EAAE;gBAChB,KAAK,GAAG,SAAS;aAClB;SACF;;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"renderer-GTnF-hYa.mjs","sources":["../../../src/core/renderer.ts"],"sourcesContent":["//\n// renderer.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { VNode } from './reconciler/vnode';\nimport { ComponentNode, NativeElementType } from './types/component';\nimport { reconciler } from './reconciler/state';\nimport nextick from 'nextick';\nimport { mergeRefs } from './utils';\nimport { equalDeps } from './reconciler/utils';\n\nexport abstract class _Renderer<T> {\n\n protected abstract _beforeUpdate(): void;\n\n protected abstract _afterUpdate(): void;\n\n protected abstract _createElement(node: VNode, stack: VNode[]): T;\n\n protected abstract _updateElement(node: VNode, element: T, stack: VNode[]): void;\n\n protected abstract _destroyElement(node: VNode, element: T): void;\n\n protected abstract _replaceChildren(node: VNode, element: T, children: (T | string)[]): void;\n\n abstract get _server(): boolean;\n\n private _createRoot(\n root: T | null,\n component: ComponentNode,\n options?: {\n skipMount?: boolean;\n },\n ) {\n\n const runtime = reconciler.buildVNodes(component, this);\n\n type _State = {\n hook: string;\n deps: any;\n unmount?: () => void;\n };\n\n const mountState = new Map<VNode, _State[]>();\n\n const children = (node: VNode, elements: Map<VNode, T>): (string | T)[] => {\n return _.flatMap(node.children, x => _.isString(x) ? x : elements.get(x) ?? children(x, elements));\n };\n\n const commit = (elements: Map<VNode, T>) => {\n\n const _mount = (\n node: VNode,\n ) => {\n const element = elements.get(node);\n if (element) {\n mergeRefs(node.props.ref)(element);\n this._replaceChildren(node, element, children(node, elements));\n }\n for (const item of node.children) {\n if (item instanceof VNode) _mount(item);\n }\n const state: _State[] = [];\n const prevState = mountState.get(node) ?? [];\n const curState = node.state;\n for (const i of _.range(Math.max(prevState.length, curState.length))) {\n const unmount = prevState[i]?.unmount;\n if (unmount &&\n (prevState[i].hook !== curState[i]?.hook || !equalDeps(prevState[i].deps, curState[i]?.deps))\n ) unmount();\n state.push({\n hook: curState[i].hook,\n deps: curState[i].deps,\n unmount: options?.skipMount ? undefined : curState[i].mount?.(),\n });\n }\n mountState.set(node, state);\n };\n\n for (const [node, state] of mountState) {\n if (elements.has(node)) continue;\n for (const { unmount } of state) unmount?.();\n mountState.delete(node);\n }\n if (root) this._replaceChildren(runtime.node, root, _.castArray(elements.get(runtime.node) ?? children(runtime.node, elements)));\n _mount(runtime.node);\n };\n\n const update = (elements?: Map<VNode, T>) => {\n this._beforeUpdate();\n const map = new Map<VNode, T>();\n for (const { node, stack, updated } of runtime.excute()) {\n if (node.error) continue;\n if (_.isFunction(node.type) && !(node.type.prototype instanceof NativeElementType)) continue;\n if (updated) {\n let elem = elements?.get(node);\n if (elem) {\n this._updateElement(node, elem, stack);\n } else {\n elem = this._createElement(node, stack);\n }\n map.set(node, elem);\n } else {\n map.set(node, elements?.get(node) ?? this._createElement(node, stack));\n }\n }\n commit(map);\n if (elements) {\n for (const [node, element] of elements) {\n if (map.has(node)) continue;\n this._destroyElement(node, element);\n }\n }\n this._afterUpdate();\n return map;\n };\n\n let update_count = 0;\n let render_count = 0;\n let destroyed = false;\n let elements = update();\n\n const listener = runtime.event.register('onchange', () => {\n if (render_count !== update_count++) return;\n nextick(() => {\n if (destroyed) return;\n render_count = update_count;\n elements = update(elements);\n });\n });\n\n return {\n get root() {\n if (root) return root;\n const elems = _.castArray(elements.get(runtime.node) ?? children(runtime.node, elements));\n const nodes = _.filter(elems, x => !_.isString(x)) as T[];\n return nodes.length === 1 ? nodes[0] : nodes;\n },\n destroy: () => {\n if (root) this._replaceChildren(runtime.node, root, []);\n destroyed = true;\n listener.remove();\n for (const state of mountState.values()) {\n for (const { unmount } of state) unmount?.();\n }\n },\n };\n }\n\n createRoot(root?: T) {\n let state: ReturnType<typeof this._createRoot> | undefined;\n return {\n get root() {\n return state?.root;\n },\n mount: (\n component: ComponentNode,\n options?: {\n skipMount?: boolean;\n },\n ) => {\n state = this._createRoot(root ?? null, component, options);\n },\n unmount: () => {\n state?.destroy();\n state = undefined;\n },\n };\n }\n}"],"names":[],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MAUsB,SAAS,CAAA;AAgBrB,IAAA,WAAW,CACjB,IAAc,EACd,SAAwB,EACxB,OAEC,EAAA;QAGD,MAAM,OAAO,GAAG,UAAU,CAAC,WAAW,CAAC,SAAS,EAAE,IAAI,CAAC;AAQvD,QAAA,MAAM,UAAU,GAAG,I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K,EAAE,CACL,SAAwB,EACxB,OAEC,KACC;AACF,gBAAA,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC;aAC3D;YACD,OAAO,EAAE,MAAK;gBACZ,KAAK,EAAE,OAAO,EAAE;gBAChB,KAAK,GAAG,SAAS;aAClB;SACF;;AAEJ;;;;"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var _ = require('lodash');
|
|
4
|
-
var
|
|
4
|
+
var utils = require('./utils-Bipfwp1R.js');
|
|
5
5
|
var component = require('./component-DJsXAx2C.js');
|
|
6
6
|
var nextick = require('nextick');
|
|
7
|
-
var utils = require('./utils-Dc66ARNS.js');
|
|
8
7
|
|
|
9
8
|
//
|
|
10
9
|
// renderer.ts
|
|
@@ -32,7 +31,7 @@ var utils = require('./utils-Dc66ARNS.js');
|
|
|
32
31
|
//
|
|
33
32
|
class _Renderer {
|
|
34
33
|
_createRoot(root, component$1, options) {
|
|
35
|
-
const runtime =
|
|
34
|
+
const runtime = utils.reconciler.buildVNodes(component$1, this);
|
|
36
35
|
const mountState = new Map();
|
|
37
36
|
const children = (node, elements) => {
|
|
38
37
|
return _.flatMap(node.children, x => _.isString(x) ? x : elements.get(x) ?? children(x, elements));
|
|
@@ -45,24 +44,24 @@ class _Renderer {
|
|
|
45
44
|
this._replaceChildren(node, element, children(node, elements));
|
|
46
45
|
}
|
|
47
46
|
for (const item of node.children) {
|
|
48
|
-
if (item instanceof
|
|
47
|
+
if (item instanceof utils.VNode)
|
|
49
48
|
_mount(item);
|
|
50
49
|
}
|
|
51
|
-
const state
|
|
50
|
+
const state = [];
|
|
52
51
|
const prevState = mountState.get(node) ?? [];
|
|
53
52
|
const curState = node.state;
|
|
54
53
|
for (const i of _.range(Math.max(prevState.length, curState.length))) {
|
|
55
54
|
const unmount = prevState[i]?.unmount;
|
|
56
55
|
if (unmount &&
|
|
57
|
-
(prevState[i].hook !== curState[i]?.hook || !
|
|
56
|
+
(prevState[i].hook !== curState[i]?.hook || !utils.equalDeps(prevState[i].deps, curState[i]?.deps)))
|
|
58
57
|
unmount();
|
|
59
|
-
state
|
|
58
|
+
state.push({
|
|
60
59
|
hook: curState[i].hook,
|
|
61
60
|
deps: curState[i].deps,
|
|
62
61
|
unmount: options?.skipMount ? undefined : curState[i].mount?.(),
|
|
63
62
|
});
|
|
64
63
|
}
|
|
65
|
-
mountState.set(node, state
|
|
64
|
+
mountState.set(node, state);
|
|
66
65
|
};
|
|
67
66
|
for (const [node, state] of mountState) {
|
|
68
67
|
if (elements.has(node))
|
|
@@ -160,4 +159,4 @@ class _Renderer {
|
|
|
160
159
|
}
|
|
161
160
|
|
|
162
161
|
exports._Renderer = _Renderer;
|
|
163
|
-
//# sourceMappingURL=renderer-
|
|
162
|
+
//# sourceMappingURL=renderer-jjw2FwKT.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer-BL3b1IbL.js","sources":["../../../src/core/renderer.ts"],"sourcesContent":["//\n// renderer.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { VNode } from './reconciler/vnode';\nimport { ComponentNode, NativeElementType } from './types/component';\nimport { reconciler } from './reconciler/state';\nimport nextick from 'nextick';\nimport { mergeRefs } from './utils';\nimport { equalDeps } from './reconciler/utils';\n\nexport abstract class _Renderer<T> {\n\n protected abstract _beforeUpdate(): void;\n\n protected abstract _afterUpdate(): void;\n\n protected abstract _createElement(node: VNode, stack: VNode[]): T;\n\n protected abstract _updateElement(node: VNode, element: T, stack: VNode[]): void;\n\n protected abstract _destroyElement(node: VNode, element: T): void;\n\n protected abstract _replaceChildren(node: VNode, element: T, children: (T | string)[]): void;\n\n abstract get _server(): boolean;\n\n private _createRoot(\n root: T | null,\n component: ComponentNode,\n options?: {\n skipMount?: boolean;\n },\n ) {\n\n const runtime = reconciler.buildVNodes(component, this);\n\n type _State = {\n hook: string;\n deps: any;\n unmount?: () => void;\n };\n\n const mountState = new Map<VNode, _State[]>();\n\n const children = (node: VNode, elements: Map<VNode, T>): (string | T)[] => {\n return _.flatMap(node.children, x => _.isString(x) ? x : elements.get(x) ?? children(x, elements));\n };\n\n const commit = (elements: Map<VNode, T>) => {\n\n const _mount = (\n node: VNode,\n ) => {\n const element = elements.get(node);\n if (element) {\n mergeRefs(node.props.ref)(element);\n this._replaceChildren(node, element, children(node, elements));\n }\n for (const item of node.children) {\n if (item instanceof VNode) _mount(item);\n }\n const state: _State[] = [];\n const prevState = mountState.get(node) ?? [];\n const curState = node.state;\n for (const i of _.range(Math.max(prevState.length, curState.length))) {\n const unmount = prevState[i]?.unmount;\n if (unmount &&\n (prevState[i].hook !== curState[i]?.hook || !equalDeps(prevState[i].deps, curState[i]?.deps))\n ) unmount();\n state.push({\n hook: curState[i].hook,\n deps: curState[i].deps,\n unmount: options?.skipMount ? undefined : curState[i].mount?.(),\n });\n }\n mountState.set(node, state);\n };\n\n for (const [node, state] of mountState) {\n if (elements.has(node)) continue;\n for (const { unmount } of state) unmount?.();\n mountState.delete(node);\n }\n if (root) this._replaceChildren(runtime.node, root, _.castArray(elements.get(runtime.node) ?? children(runtime.node, elements)));\n _mount(runtime.node);\n };\n\n const update = (elements?: Map<VNode, T>) => {\n this._beforeUpdate();\n const map = new Map<VNode, T>();\n for (const { node, stack, updated } of runtime.excute()) {\n if (node.error) continue;\n if (_.isFunction(node.type) && !(node.type.prototype instanceof NativeElementType)) continue;\n if (updated) {\n let elem = elements?.get(node);\n if (elem) {\n this._updateElement(node, elem, stack);\n } else {\n elem = this._createElement(node, stack);\n }\n map.set(node, elem);\n } else {\n map.set(node, elements?.get(node) ?? this._createElement(node, stack));\n }\n }\n commit(map);\n if (elements) {\n for (const [node, element] of elements) {\n if (map.has(node)) continue;\n this._destroyElement(node, element);\n }\n }\n this._afterUpdate();\n return map;\n };\n\n let update_count = 0;\n let render_count = 0;\n let destroyed = false;\n let elements = update();\n\n const listener = runtime.event.register('onchange', () => {\n if (render_count !== update_count++) return;\n nextick(() => {\n if (destroyed) return;\n render_count = update_count;\n elements = update(elements);\n });\n });\n\n return {\n get root() {\n if (root) return root;\n const elems = _.castArray(elements.get(runtime.node) ?? children(runtime.node, elements));\n const nodes = _.filter(elems, x => !_.isString(x)) as T[];\n return nodes.length === 1 ? nodes[0] : nodes;\n },\n destroy: () => {\n if (root) this._replaceChildren(runtime.node, root, []);\n destroyed = true;\n listener.remove();\n for (const state of mountState.values()) {\n for (const { unmount } of state) unmount?.();\n }\n },\n };\n }\n\n createRoot(root?: T) {\n let state: ReturnType<typeof this._createRoot> | undefined;\n return {\n get root() {\n return state?.root;\n },\n mount: (\n component: ComponentNode,\n options?: {\n skipMount?: boolean;\n },\n ) => {\n state = this._createRoot(root ?? null, component, options);\n },\n unmount: () => {\n state?.destroy();\n state = undefined;\n },\n };\n }\n}"],"names":["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,CAAC;gBACvD,SAAS,GAAG,IAAI;gBAChB,QAAQ,CAAC,MAAM,EAAE;gBACjB,KAAK,MAAM,KAAK,IAAI,UAAU,CAAC,MAAM,EAAE,EAAE;AACvC,oBAAA,KAAK,MAAM,EAAE,OAAO,EAAE,IAAI,KAAK;wBAAE,OAAO,IAAI;;aAE/C;SACF;;AAGH,IAAA,UAAU,CAAC,IAAQ,EAAA;AACjB,QAAA,IAAI,KAAsD;QAC1D,OAAO;AACL,YAAA,IAAI,IAAI,GAAA;gBACN,OAAO,KAAK,EAAE,IAAI;aACnB;AACD,YAAA,KAAK,EAAE,CACL,SAAwB,EACxB,OAEC,KACC;AACF,gBAAA,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC;aAC3D;YACD,OAAO,EAAE,MAAK;gBACZ,KAAK,EAAE,OAAO,EAAE;gBAChB,KAAK,GAAG,SAAS;aAClB;SACF;;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"renderer-jjw2FwKT.js","sources":["../../../src/core/renderer.ts"],"sourcesContent":["//\n// renderer.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { VNode } from './reconciler/vnode';\nimport { ComponentNode, NativeElementType } from './types/component';\nimport { reconciler } from './reconciler/state';\nimport nextick from 'nextick';\nimport { mergeRefs } from './utils';\nimport { equalDeps } from './reconciler/utils';\n\nexport abstract class _Renderer<T> {\n\n protected abstract _beforeUpdate(): void;\n\n protected abstract _afterUpdate(): void;\n\n protected abstract _createElement(node: VNode, stack: VNode[]): T;\n\n protected abstract _updateElement(node: VNode, element: T, stack: VNode[]): void;\n\n protected abstract _destroyElement(node: VNode, element: T): void;\n\n protected abstract _replaceChildren(node: VNode, element: T, children: (T | string)[]): void;\n\n abstract get _server(): boolean;\n\n private _createRoot(\n root: T | null,\n component: ComponentNode,\n options?: {\n skipMount?: boolean;\n },\n ) {\n\n const runtime = reconciler.buildVNodes(component, this);\n\n type _State = {\n hook: string;\n deps: any;\n unmount?: () => void;\n };\n\n const mountState = new Map<VNode, _State[]>();\n\n const children = (node: VNode, elements: Map<VNode, T>): (string | T)[] => {\n return _.flatMap(node.children, x => _.isString(x) ? x : elements.get(x) ?? children(x, elements));\n };\n\n const commit = (elements: Map<VNode, T>) => {\n\n const _mount = (\n node: VNode,\n ) => {\n const element = elements.get(node);\n if (element) {\n mergeRefs(node.props.ref)(element);\n this._replaceChildren(node, element, children(node, elements));\n }\n for (const item of node.children) {\n if (item instanceof VNode) _mount(item);\n }\n const state: _State[] = [];\n const prevState = mountState.get(node) ?? [];\n const curState = node.state;\n for (const i of _.range(Math.max(prevState.length, curState.length))) {\n const unmount = prevState[i]?.unmount;\n if (unmount &&\n (prevState[i].hook !== curState[i]?.hook || !equalDeps(prevState[i].deps, curState[i]?.deps))\n ) unmount();\n state.push({\n hook: curState[i].hook,\n deps: curState[i].deps,\n unmount: options?.skipMount ? undefined : curState[i].mount?.(),\n });\n }\n mountState.set(node, state);\n };\n\n for (const [node, state] of mountState) {\n if (elements.has(node)) continue;\n for (const { unmount } of state) unmount?.();\n mountState.delete(node);\n }\n if (root) this._replaceChildren(runtime.node, root, _.castArray(elements.get(runtime.node) ?? children(runtime.node, elements)));\n _mount(runtime.node);\n };\n\n const update = (elements?: Map<VNode, T>) => {\n this._beforeUpdate();\n const map = new Map<VNode, T>();\n for (const { node, stack, updated } of runtime.excute()) {\n if (node.error) continue;\n if (_.isFunction(node.type) && !(node.type.prototype instanceof NativeElementType)) continue;\n if (updated) {\n let elem = elements?.get(node);\n if (elem) {\n this._updateElement(node, elem, stack);\n } else {\n elem = this._createElement(node, stack);\n }\n map.set(node, elem);\n } else {\n map.set(node, elements?.get(node) ?? this._createElement(node, stack));\n }\n }\n commit(map);\n if (elements) {\n for (const [node, element] of elements) {\n if (map.has(node)) continue;\n this._destroyElement(node, element);\n }\n }\n this._afterUpdate();\n return map;\n };\n\n let update_count = 0;\n let render_count = 0;\n let destroyed = false;\n let elements = update();\n\n const listener = runtime.event.register('onchange', () => {\n if (render_count !== update_count++) return;\n nextick(() => {\n if (destroyed) return;\n render_count = update_count;\n elements = update(elements);\n });\n });\n\n return {\n get root() {\n if (root) return root;\n const elems = _.castArray(elements.get(runtime.node) ?? children(runtime.node, elements));\n const nodes = _.filter(elems, x => !_.isString(x)) as T[];\n return nodes.length === 1 ? nodes[0] : nodes;\n },\n destroy: () => {\n if (root) this._replaceChildren(runtime.node, root, []);\n destroyed = true;\n listener.remove();\n for (const state of mountState.values()) {\n for (const { unmount } of state) unmount?.();\n }\n },\n };\n }\n\n createRoot(root?: T) {\n let state: ReturnType<typeof this._createRoot> | undefined;\n return {\n get root() {\n return state?.root;\n },\n mount: (\n component: ComponentNode,\n options?: {\n skipMount?: boolean;\n },\n ) => {\n state = this._createRoot(root ?? null, component, options);\n },\n unmount: () => {\n state?.destroy();\n state = undefined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AAI,EAAE,EAAE,CAAC;gBACvD,SAAS,GAAG,IAAI;gBAChB,QAAQ,CAAC,MAAM,EAAE;gBACjB,KAAK,MAAM,KAAK,IAAI,UAAU,CAAC,MAAM,EAAE,EAAE;AACvC,oBAAA,KAAK,MAAM,EAAE,OAAO,EAAE,IAAI,KAAK;wBAAE,OAAO,IAAI;;aAE/C;SACF;;AAGH,IAAA,UAAU,CAAC,IAAQ,EAAA;AACjB,QAAA,IAAI,KAAsD;QAC1D,OAAO;AACL,YAAA,IAAI,IAAI,GAAA;gBACN,OAAO,KAAK,EAAE,IAAI;aACnB;AACD,YAAA,KAAK,EAAE,CACL,SAAwB,EACxB,OAEC,KACC;AACF,gBAAA,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC;aAC3D;YACD,OAAO,EAAE,MAAK;gBACZ,KAAK,EAAE,OAAO,EAAE;gBAChB,KAAK,GAAG,SAAS;aAClB;SACF;;AAEJ;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
|
-
import { e as equalDeps, r as reconciler } from './
|
|
2
|
+
import { e as equalDeps, r as reconciler } from './utils-BJL3yvTI.mjs';
|
|
3
3
|
|
|
4
4
|
//
|
|
5
5
|
// index.ts
|
|
@@ -78,6 +78,62 @@ const _useMemo = (hook, factory, deps) => {
|
|
|
78
78
|
return data;
|
|
79
79
|
};
|
|
80
80
|
|
|
81
|
+
//
|
|
82
|
+
// memo.ts
|
|
83
|
+
//
|
|
84
|
+
// The MIT License
|
|
85
|
+
// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
|
|
86
|
+
//
|
|
87
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
88
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
89
|
+
// in the Software without restriction, including without limitation the rights
|
|
90
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
91
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
92
|
+
// furnished to do so, subject to the following conditions:
|
|
93
|
+
//
|
|
94
|
+
// The above copyright notice and this permission notice shall be included in
|
|
95
|
+
// all copies or substantial portions of the Software.
|
|
96
|
+
//
|
|
97
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
98
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
99
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
100
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
101
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
102
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
103
|
+
// THE SOFTWARE.
|
|
104
|
+
//
|
|
105
|
+
/**
|
|
106
|
+
* A hook that memoizes a callback function, ensuring that it only changes
|
|
107
|
+
* if its dependencies change. This is useful for optimizing performance by preventing
|
|
108
|
+
* unnecessary re-creations of functions.
|
|
109
|
+
*
|
|
110
|
+
* @template T - The type of the callback function.
|
|
111
|
+
* @param callback - The callback function to be memoized.
|
|
112
|
+
* @param deps - An optional dependencies. If provided, the callback
|
|
113
|
+
* will only be updated when one of these dependencies changes.
|
|
114
|
+
* If not provided, the callback will remain stable.
|
|
115
|
+
* @returns - A stable version of the callback function that will not change unless
|
|
116
|
+
* its dependencies change.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* const memoizedCallback = useCallback(() => {
|
|
120
|
+
* console.log('This function is memoized!');
|
|
121
|
+
* }, [dependency]);
|
|
122
|
+
*/
|
|
123
|
+
const useCallback = (callback, deps) => {
|
|
124
|
+
if (!_.isUndefined(deps))
|
|
125
|
+
return _useMemo('useCallback', callback, deps);
|
|
126
|
+
const store = _useMemo('useCallback', () => {
|
|
127
|
+
const store = {
|
|
128
|
+
current: callback,
|
|
129
|
+
stable: (...args) => store.current(...args),
|
|
130
|
+
};
|
|
131
|
+
return store;
|
|
132
|
+
}, null);
|
|
133
|
+
store.current = callback;
|
|
134
|
+
return store.stable;
|
|
135
|
+
};
|
|
136
|
+
|
|
81
137
|
//
|
|
82
138
|
// effect.ts
|
|
83
139
|
//
|
|
@@ -111,7 +167,7 @@ const _useMemo = (hook, factory, deps) => {
|
|
|
111
167
|
* It can optionally return a cleanup function or a promise that resolves to a cleanup function.
|
|
112
168
|
*
|
|
113
169
|
* @param deps -
|
|
114
|
-
* An optional
|
|
170
|
+
* An optional dependencies that determines when the effect should be re-executed.
|
|
115
171
|
*
|
|
116
172
|
* @example
|
|
117
173
|
* useEffect((signal) => {
|
|
@@ -190,62 +246,6 @@ const useEffect = (effect, deps) => _useEffect('useEffect', () => {
|
|
|
190
246
|
*/
|
|
191
247
|
const useMemo = (factory, deps) => _useMemo('useMemo', factory, deps);
|
|
192
248
|
|
|
193
|
-
//
|
|
194
|
-
// memo.ts
|
|
195
|
-
//
|
|
196
|
-
// The MIT License
|
|
197
|
-
// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
|
|
198
|
-
//
|
|
199
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
200
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
201
|
-
// in the Software without restriction, including without limitation the rights
|
|
202
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
203
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
204
|
-
// furnished to do so, subject to the following conditions:
|
|
205
|
-
//
|
|
206
|
-
// The above copyright notice and this permission notice shall be included in
|
|
207
|
-
// all copies or substantial portions of the Software.
|
|
208
|
-
//
|
|
209
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
210
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
211
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
212
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
213
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
214
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
215
|
-
// THE SOFTWARE.
|
|
216
|
-
//
|
|
217
|
-
/**
|
|
218
|
-
* A hook that memoizes a callback function, ensuring that it only changes
|
|
219
|
-
* if its dependencies change. This is useful for optimizing performance by preventing
|
|
220
|
-
* unnecessary re-creations of functions.
|
|
221
|
-
*
|
|
222
|
-
* @template T - The type of the callback function.
|
|
223
|
-
* @param callback - The callback function to be memoized.
|
|
224
|
-
* @param deps - An optional array of dependencies. If provided, the callback
|
|
225
|
-
* will only be updated when one of these dependencies changes.
|
|
226
|
-
* If not provided, the callback will remain stable.
|
|
227
|
-
* @returns - A stable version of the callback function that will not change unless
|
|
228
|
-
* its dependencies change.
|
|
229
|
-
*
|
|
230
|
-
* @example
|
|
231
|
-
* const memoizedCallback = useCallback(() => {
|
|
232
|
-
* console.log('This function is memoized!');
|
|
233
|
-
* }, [dependency]);
|
|
234
|
-
*/
|
|
235
|
-
const useCallback = (callback, deps) => {
|
|
236
|
-
if (!_.isUndefined(deps))
|
|
237
|
-
return _useMemo('useCallback', callback, deps);
|
|
238
|
-
const store = _useMemo('useCallback', () => {
|
|
239
|
-
const store = {
|
|
240
|
-
current: callback,
|
|
241
|
-
stable: (...args) => store.current(...args),
|
|
242
|
-
};
|
|
243
|
-
return store;
|
|
244
|
-
}, null);
|
|
245
|
-
store.current = callback;
|
|
246
|
-
return store.stable;
|
|
247
|
-
};
|
|
248
|
-
|
|
249
249
|
//
|
|
250
250
|
// sync.ts
|
|
251
251
|
//
|
|
@@ -318,5 +318,5 @@ const useSyncExternalStore = (subscribe, getSnapshot, getServerSnapshot) => {
|
|
|
318
318
|
return getSnapshot();
|
|
319
319
|
};
|
|
320
320
|
|
|
321
|
-
export {
|
|
322
|
-
//# sourceMappingURL=sync-
|
|
321
|
+
export { _useEffect as _, _useMemo as a, useMemo as b, useEffect as c, useSyncExternalStore as d, useCallback as u };
|
|
322
|
+
//# sourceMappingURL=sync-B9zfuWYQ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-B9zfuWYQ.mjs","sources":["../../../src/core/reconciler/hooks.ts","../../../src/core/hooks/callback.ts","../../../src/core/hooks/effect.ts","../../../src/core/hooks/memo.ts","../../../src/core/hooks/sync.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { reconciler } from './state';\nimport { equalDeps } from './utils';\n\nconst _useHookState = (hook: string) => {\n const state = reconciler.currentHookState;\n if (!state) throw Error(`${hook} must be used within a render function.`);\n const { prevState, state: newState } = state;\n if (prevState && prevState[newState.length]?.hook !== hook) {\n console.warn([\n `Hook \"${hook}\" is called conditionally.`,\n 'Hooks must be called in the exact same order in every component render.',\n 'Did you accidentally call a hook after an early return?'\n ].join(' '));\n }\n return state;\n};\n\nexport const _useEffect = (\n hook: string,\n effect: (state: ReturnType<typeof _useHookState>) => () => void,\n deps?: any\n) => {\n const state = _useHookState(hook);\n const { prevState, state: newState } = state;\n const idx = newState.length;\n if (\n prevState?.[idx]?.hook === hook &&\n equalDeps(prevState[idx].deps, deps)\n ) {\n newState.push({\n ...prevState[idx],\n deps,\n });\n return;\n }\n newState.push({\n deps,\n mount: () => effect(state),\n hook,\n });\n};\n\nexport const _useMemo = <T>(\n hook: string,\n factory: (state: ReturnType<typeof _useHookState>) => T,\n deps?: any\n): T => {\n const state = _useHookState(hook);\n const { prevState, state: newState } = state;\n const idx = newState.length;\n if (\n prevState?.[idx]?.hook === hook &&\n equalDeps(prevState[idx].deps, deps)\n ) {\n newState.push({\n ...prevState[idx],\n deps,\n });\n return prevState[idx].data;\n }\n const data = factory(state);\n newState.push({\n deps,\n hook,\n data\n });\n return data;\n};\n","//\n// memo.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { _useMemo } from '../reconciler/hooks';\n\n/**\n * A hook that memoizes a callback function, ensuring that it only changes\n * if its dependencies change. This is useful for optimizing performance by preventing\n * unnecessary re-creations of functions.\n *\n * @template T - The type of the callback function.\n * @param callback - The callback function to be memoized.\n * @param deps - An optional dependencies. If provided, the callback\n * will only be updated when one of these dependencies changes.\n * If not provided, the callback will remain stable.\n * @returns - A stable version of the callback function that will not change unless\n * its dependencies change.\n *\n * @example\n * const memoizedCallback = useCallback(() => {\n * console.log('This function is memoized!');\n * }, [dependency]);\n */\nexport const useCallback = <T extends (...args: any) => any>(\n callback: T,\n deps?: any\n): T => {\n if (!_.isUndefined(deps)) return _useMemo('useCallback', callback, deps);\n const store = _useMemo('useCallback', () => {\n const store = {\n current: callback,\n stable: (...args: Parameters<T>): ReturnType<T> => store.current(...args),\n };\n return store;\n }, null);\n store.current = callback;\n return store.stable as T;\n}\n","//\n// effect.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { Awaitable } from '@o2ter/utils-js';\nimport { _useEffect } from '../reconciler/hooks';\n\n/**\n * A hook that manages side effects with support for an `AbortSignal`.\n * It ensures proper cleanup logic and handles asynchronous operations effectively.\n *\n * @param effect - \n * A function that receives an `AbortSignal` and performs side effects. \n * It can optionally return a cleanup function or a promise that resolves to a cleanup function.\n *\n * @param deps - \n * An optional dependencies that determines when the effect should be re-executed.\n *\n * @example\n * useEffect((signal) => {\n * fetch('/api/data', { signal })\n * .then(response => response.json())\n * .then(data => console.log(data))\n * .catch(err => {\n * if (err.name === 'AbortError') {\n * console.log('Fetch aborted');\n * } else {\n * console.error(err);\n * }\n * });\n * \n * return () => {\n * console.log('Cleanup logic here');\n * };\n * }, []);\n */\nexport const useEffect = (\n effect: (\n signal: AbortSignal,\n ) => Awaitable<void | (() => Awaitable<void>)>,\n deps?: any,\n) => _useEffect('useEffect', () => {\n const abort = new AbortController();\n try {\n const destructor = effect(abort.signal);\n return () => {\n abort.abort();\n (async () => {\n try {\n const _destructor = await destructor;\n if (_.isFunction(_destructor)) _destructor();\n } catch (e) {\n console.error(e);\n }\n })();\n };\n } catch (e) {\n console.error(e);\n return () => abort.abort();\n }\n}, deps);","//\n// memo.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { _useMemo } from '../reconciler/hooks';\n\n/**\n * A utility function that memoizes the result of a factory function.\n * \n * @template T The type of the value returned by the factory function.\n * @param factory A function that produces a value to be memoized.\n * @param deps An optional dependency array. The memoized value is recalculated \n * only when the dependencies change.\n * @returns The memoized value produced by the factory function.\n */\nexport const useMemo = <T>(\n factory: () => T,\n deps?: any,\n) => _useMemo('useMemo', factory, deps);\n","//\n// sync.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { Awaitable } from '@o2ter/utils-js';\nimport { _useEffect } from '../reconciler/hooks';\nimport { reconciler } from '../reconciler/state';\n\n/**\n * A hook utility for synchronizing with an external store.\n *\n * @template Snapshot - The type of the snapshot returned by the store.\n * @param subscribe - A function that sets up a subscription to the external store.\n * - `onStoreChange`: A callback to invoke when the store changes.\n * - `signal`: An `AbortSignal` to handle cleanup when the subscription is no longer needed.\n * - Returns an optional cleanup function or a promise resolving to one.\n * @param getSnapshot - A function that retrieves the current snapshot of the store.\n * @param getServerSnapshot - (Optional) A function that retrieves the snapshot of the store\n * in a server environment.\n * @returns The current snapshot of the store.\n *\n * @throws Will throw an error if used outside of a valid render context.\n */\nexport const useSyncExternalStore = <Snapshot>(\n subscribe: (\n onStoreChange: () => void,\n signal: AbortSignal,\n ) => Awaitable<void | (() => Awaitable<void>)>,\n getSnapshot: () => Snapshot,\n getServerSnapshot?: () => Snapshot,\n) => {\n const state = reconciler.currentHookState;\n if (!state) throw Error('useSyncExternalStore must be used within a render function.');\n _useEffect('useSyncExternalStore', ({ node }) => {\n const abort = new AbortController();\n try {\n const destructor = subscribe(() => { node?._setDirty(); }, abort.signal);\n return () => {\n abort.abort();\n (async () => {\n try {\n const _destructor = await destructor;\n if (_.isFunction(_destructor)) _destructor();\n } catch (e) {\n console.error(e);\n }\n })();\n };\n } catch (e) {\n console.error(e);\n return () => abort.abort();\n }\n }, null);\n if (getServerSnapshot && state.renderer._server) {\n return getServerS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|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var _ = require('lodash');
|
|
4
|
-
var
|
|
4
|
+
var utils = require('./utils-Bipfwp1R.js');
|
|
5
5
|
|
|
6
6
|
//
|
|
7
7
|
// index.ts
|
|
@@ -28,10 +28,10 @@ var state = require('./state-DH_D-jro.js');
|
|
|
28
28
|
// THE SOFTWARE.
|
|
29
29
|
//
|
|
30
30
|
const _useHookState = (hook) => {
|
|
31
|
-
const state
|
|
32
|
-
if (!state
|
|
31
|
+
const state = utils.reconciler.currentHookState;
|
|
32
|
+
if (!state)
|
|
33
33
|
throw Error(`${hook} must be used within a render function.`);
|
|
34
|
-
const { prevState, state: newState } = state
|
|
34
|
+
const { prevState, state: newState } = state;
|
|
35
35
|
if (prevState && prevState[newState.length]?.hook !== hook) {
|
|
36
36
|
console.warn([
|
|
37
37
|
`Hook "${hook}" is called conditionally.`,
|
|
@@ -39,14 +39,14 @@ const _useHookState = (hook) => {
|
|
|
39
39
|
'Did you accidentally call a hook after an early return?'
|
|
40
40
|
].join(' '));
|
|
41
41
|
}
|
|
42
|
-
return state
|
|
42
|
+
return state;
|
|
43
43
|
};
|
|
44
44
|
const _useEffect = (hook, effect, deps) => {
|
|
45
|
-
const state
|
|
46
|
-
const { prevState, state: newState } = state
|
|
45
|
+
const state = _useHookState(hook);
|
|
46
|
+
const { prevState, state: newState } = state;
|
|
47
47
|
const idx = newState.length;
|
|
48
48
|
if (prevState?.[idx]?.hook === hook &&
|
|
49
|
-
|
|
49
|
+
utils.equalDeps(prevState[idx].deps, deps)) {
|
|
50
50
|
newState.push({
|
|
51
51
|
...prevState[idx],
|
|
52
52
|
deps,
|
|
@@ -55,23 +55,23 @@ const _useEffect = (hook, effect, deps) => {
|
|
|
55
55
|
}
|
|
56
56
|
newState.push({
|
|
57
57
|
deps,
|
|
58
|
-
mount: () => effect(state
|
|
58
|
+
mount: () => effect(state),
|
|
59
59
|
hook,
|
|
60
60
|
});
|
|
61
61
|
};
|
|
62
62
|
const _useMemo = (hook, factory, deps) => {
|
|
63
|
-
const state
|
|
64
|
-
const { prevState, state: newState } = state
|
|
63
|
+
const state = _useHookState(hook);
|
|
64
|
+
const { prevState, state: newState } = state;
|
|
65
65
|
const idx = newState.length;
|
|
66
66
|
if (prevState?.[idx]?.hook === hook &&
|
|
67
|
-
|
|
67
|
+
utils.equalDeps(prevState[idx].deps, deps)) {
|
|
68
68
|
newState.push({
|
|
69
69
|
...prevState[idx],
|
|
70
70
|
deps,
|
|
71
71
|
});
|
|
72
72
|
return prevState[idx].data;
|
|
73
73
|
}
|
|
74
|
-
const data = factory(state
|
|
74
|
+
const data = factory(state);
|
|
75
75
|
newState.push({
|
|
76
76
|
deps,
|
|
77
77
|
hook,
|
|
@@ -80,6 +80,62 @@ const _useMemo = (hook, factory, deps) => {
|
|
|
80
80
|
return data;
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
+
//
|
|
84
|
+
// memo.ts
|
|
85
|
+
//
|
|
86
|
+
// The MIT License
|
|
87
|
+
// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
|
|
88
|
+
//
|
|
89
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
90
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
91
|
+
// in the Software without restriction, including without limitation the rights
|
|
92
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
93
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
94
|
+
// furnished to do so, subject to the following conditions:
|
|
95
|
+
//
|
|
96
|
+
// The above copyright notice and this permission notice shall be included in
|
|
97
|
+
// all copies or substantial portions of the Software.
|
|
98
|
+
//
|
|
99
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
100
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
101
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
102
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
103
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
104
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
105
|
+
// THE SOFTWARE.
|
|
106
|
+
//
|
|
107
|
+
/**
|
|
108
|
+
* A hook that memoizes a callback function, ensuring that it only changes
|
|
109
|
+
* if its dependencies change. This is useful for optimizing performance by preventing
|
|
110
|
+
* unnecessary re-creations of functions.
|
|
111
|
+
*
|
|
112
|
+
* @template T - The type of the callback function.
|
|
113
|
+
* @param callback - The callback function to be memoized.
|
|
114
|
+
* @param deps - An optional dependencies. If provided, the callback
|
|
115
|
+
* will only be updated when one of these dependencies changes.
|
|
116
|
+
* If not provided, the callback will remain stable.
|
|
117
|
+
* @returns - A stable version of the callback function that will not change unless
|
|
118
|
+
* its dependencies change.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* const memoizedCallback = useCallback(() => {
|
|
122
|
+
* console.log('This function is memoized!');
|
|
123
|
+
* }, [dependency]);
|
|
124
|
+
*/
|
|
125
|
+
const useCallback = (callback, deps) => {
|
|
126
|
+
if (!_.isUndefined(deps))
|
|
127
|
+
return _useMemo('useCallback', callback, deps);
|
|
128
|
+
const store = _useMemo('useCallback', () => {
|
|
129
|
+
const store = {
|
|
130
|
+
current: callback,
|
|
131
|
+
stable: (...args) => store.current(...args),
|
|
132
|
+
};
|
|
133
|
+
return store;
|
|
134
|
+
}, null);
|
|
135
|
+
store.current = callback;
|
|
136
|
+
return store.stable;
|
|
137
|
+
};
|
|
138
|
+
|
|
83
139
|
//
|
|
84
140
|
// effect.ts
|
|
85
141
|
//
|
|
@@ -113,7 +169,7 @@ const _useMemo = (hook, factory, deps) => {
|
|
|
113
169
|
* It can optionally return a cleanup function or a promise that resolves to a cleanup function.
|
|
114
170
|
*
|
|
115
171
|
* @param deps -
|
|
116
|
-
* An optional
|
|
172
|
+
* An optional dependencies that determines when the effect should be re-executed.
|
|
117
173
|
*
|
|
118
174
|
* @example
|
|
119
175
|
* useEffect((signal) => {
|
|
@@ -192,62 +248,6 @@ const useEffect = (effect, deps) => _useEffect('useEffect', () => {
|
|
|
192
248
|
*/
|
|
193
249
|
const useMemo = (factory, deps) => _useMemo('useMemo', factory, deps);
|
|
194
250
|
|
|
195
|
-
//
|
|
196
|
-
// memo.ts
|
|
197
|
-
//
|
|
198
|
-
// The MIT License
|
|
199
|
-
// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
|
|
200
|
-
//
|
|
201
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
202
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
203
|
-
// in the Software without restriction, including without limitation the rights
|
|
204
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
205
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
206
|
-
// furnished to do so, subject to the following conditions:
|
|
207
|
-
//
|
|
208
|
-
// The above copyright notice and this permission notice shall be included in
|
|
209
|
-
// all copies or substantial portions of the Software.
|
|
210
|
-
//
|
|
211
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
212
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
213
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
214
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
215
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
216
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
217
|
-
// THE SOFTWARE.
|
|
218
|
-
//
|
|
219
|
-
/**
|
|
220
|
-
* A hook that memoizes a callback function, ensuring that it only changes
|
|
221
|
-
* if its dependencies change. This is useful for optimizing performance by preventing
|
|
222
|
-
* unnecessary re-creations of functions.
|
|
223
|
-
*
|
|
224
|
-
* @template T - The type of the callback function.
|
|
225
|
-
* @param callback - The callback function to be memoized.
|
|
226
|
-
* @param deps - An optional array of dependencies. If provided, the callback
|
|
227
|
-
* will only be updated when one of these dependencies changes.
|
|
228
|
-
* If not provided, the callback will remain stable.
|
|
229
|
-
* @returns - A stable version of the callback function that will not change unless
|
|
230
|
-
* its dependencies change.
|
|
231
|
-
*
|
|
232
|
-
* @example
|
|
233
|
-
* const memoizedCallback = useCallback(() => {
|
|
234
|
-
* console.log('This function is memoized!');
|
|
235
|
-
* }, [dependency]);
|
|
236
|
-
*/
|
|
237
|
-
const useCallback = (callback, deps) => {
|
|
238
|
-
if (!_.isUndefined(deps))
|
|
239
|
-
return _useMemo('useCallback', callback, deps);
|
|
240
|
-
const store = _useMemo('useCallback', () => {
|
|
241
|
-
const store = {
|
|
242
|
-
current: callback,
|
|
243
|
-
stable: (...args) => store.current(...args),
|
|
244
|
-
};
|
|
245
|
-
return store;
|
|
246
|
-
}, null);
|
|
247
|
-
store.current = callback;
|
|
248
|
-
return store.stable;
|
|
249
|
-
};
|
|
250
|
-
|
|
251
251
|
//
|
|
252
252
|
// sync.ts
|
|
253
253
|
//
|
|
@@ -288,8 +288,8 @@ const useCallback = (callback, deps) => {
|
|
|
288
288
|
* @throws Will throw an error if used outside of a valid render context.
|
|
289
289
|
*/
|
|
290
290
|
const useSyncExternalStore = (subscribe, getSnapshot, getServerSnapshot) => {
|
|
291
|
-
const state
|
|
292
|
-
if (!state
|
|
291
|
+
const state = utils.reconciler.currentHookState;
|
|
292
|
+
if (!state)
|
|
293
293
|
throw Error('useSyncExternalStore must be used within a render function.');
|
|
294
294
|
_useEffect('useSyncExternalStore', ({ node }) => {
|
|
295
295
|
const abort = new AbortController();
|
|
@@ -314,7 +314,7 @@ const useSyncExternalStore = (subscribe, getSnapshot, getServerSnapshot) => {
|
|
|
314
314
|
return () => abort.abort();
|
|
315
315
|
}
|
|
316
316
|
}, null);
|
|
317
|
-
if (getServerSnapshot && state
|
|
317
|
+
if (getServerSnapshot && state.renderer._server) {
|
|
318
318
|
return getServerSnapshot();
|
|
319
319
|
}
|
|
320
320
|
return getSnapshot();
|
|
@@ -326,4 +326,4 @@ exports.useCallback = useCallback;
|
|
|
326
326
|
exports.useEffect = useEffect;
|
|
327
327
|
exports.useMemo = useMemo;
|
|
328
328
|
exports.useSyncExternalStore = useSyncExternalStore;
|
|
329
|
-
//# sourceMappingURL=sync-
|
|
329
|
+
//# sourceMappingURL=sync-BIbWmXEq.js.map
|