@foxford/den-preact 0.3.1 → 0.4.0
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/chunk-3F3F3ALW.js +32 -0
- package/chunk-3LGXNDYH.cjs +32 -0
- package/{chunk-SAZL2GWD.js → chunk-5BDZSAOP.js} +39 -9
- package/{chunk-XKEFCZET.cjs → chunk-ZVARQ3IY.cjs} +37 -7
- package/client.cjs +4 -3
- package/client.js +2 -1
- package/index.cjs +6 -5
- package/index.js +2 -1
- package/package.json +7 -5
- package/use-sync-external-store.cjs +6 -28
- package/use-sync-external-store.js +5 -27
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/use-sync-external-store.ts
|
|
2
|
+
import { useDebugValue, useEffect, useMemo, useRef, useSyncExternalStore } from "preact/compat";
|
|
3
|
+
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, _getServerSnapshot, selector, isEqual) {
|
|
4
|
+
const cache = useRef({ hasValue: false });
|
|
5
|
+
const getSelection = useMemo(() => {
|
|
6
|
+
let memo = null;
|
|
7
|
+
function select(snapshot) {
|
|
8
|
+
if (memo !== null && Object.is(memo.snapshot, snapshot)) {
|
|
9
|
+
return memo.selection;
|
|
10
|
+
}
|
|
11
|
+
const next = selector(snapshot);
|
|
12
|
+
const previous = memo === null ? cache.current : { hasValue: true, value: memo.selection };
|
|
13
|
+
const selection2 = isEqual !== void 0 && previous.hasValue && isEqual(previous.value, next) ? previous.value : next;
|
|
14
|
+
memo = { selection: selection2, snapshot };
|
|
15
|
+
return selection2;
|
|
16
|
+
}
|
|
17
|
+
return () => select(getSnapshot());
|
|
18
|
+
}, [getSnapshot, isEqual, selector]);
|
|
19
|
+
const selection = useSyncExternalStore(subscribe, getSelection);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
cache.current = { hasValue: true, value: selection };
|
|
22
|
+
}, [selection]);
|
|
23
|
+
useDebugValue(selection);
|
|
24
|
+
return selection;
|
|
25
|
+
}
|
|
26
|
+
var use_sync_external_store_default = { useSyncExternalStore, useSyncExternalStoreWithSelector };
|
|
27
|
+
|
|
28
|
+
export {
|
|
29
|
+
useSyncExternalStore,
|
|
30
|
+
useSyncExternalStoreWithSelector,
|
|
31
|
+
use_sync_external_store_default
|
|
32
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/use-sync-external-store.ts
|
|
2
|
+
var _compat = require('preact/compat');
|
|
3
|
+
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, _getServerSnapshot, selector, isEqual) {
|
|
4
|
+
const cache = _compat.useRef.call(void 0, { hasValue: false });
|
|
5
|
+
const getSelection = _compat.useMemo.call(void 0, () => {
|
|
6
|
+
let memo = null;
|
|
7
|
+
function select(snapshot) {
|
|
8
|
+
if (memo !== null && Object.is(memo.snapshot, snapshot)) {
|
|
9
|
+
return memo.selection;
|
|
10
|
+
}
|
|
11
|
+
const next = selector(snapshot);
|
|
12
|
+
const previous = memo === null ? cache.current : { hasValue: true, value: memo.selection };
|
|
13
|
+
const selection2 = isEqual !== void 0 && previous.hasValue && isEqual(previous.value, next) ? previous.value : next;
|
|
14
|
+
memo = { selection: selection2, snapshot };
|
|
15
|
+
return selection2;
|
|
16
|
+
}
|
|
17
|
+
return () => select(getSnapshot());
|
|
18
|
+
}, [getSnapshot, isEqual, selector]);
|
|
19
|
+
const selection = _compat.useSyncExternalStore.call(void 0, subscribe, getSelection);
|
|
20
|
+
_compat.useEffect.call(void 0, () => {
|
|
21
|
+
cache.current = { hasValue: true, value: selection };
|
|
22
|
+
}, [selection]);
|
|
23
|
+
_compat.useDebugValue.call(void 0, selection);
|
|
24
|
+
return selection;
|
|
25
|
+
}
|
|
26
|
+
var use_sync_external_store_default = { useSyncExternalStore: _compat.useSyncExternalStore, useSyncExternalStoreWithSelector };
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
exports.useSyncExternalStore = _compat.useSyncExternalStore; exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector; exports.use_sync_external_store_default = use_sync_external_store_default;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useSyncExternalStore
|
|
3
|
+
} from "./chunk-3F3F3ALW.js";
|
|
1
4
|
import {
|
|
2
5
|
__spreadValues
|
|
3
6
|
} from "./chunk-5JBD5THX.js";
|
|
@@ -77,18 +80,21 @@ function Slot({ name }) {
|
|
|
77
80
|
|
|
78
81
|
// src/island.tsx
|
|
79
82
|
import { Component } from "preact";
|
|
80
|
-
import { useEffect, useMemo, useState } from "preact/hooks";
|
|
83
|
+
import { useEffect, useMemo, useRef, useState } from "preact/hooks";
|
|
81
84
|
import {
|
|
82
85
|
activateIslandViewModels,
|
|
83
86
|
browserRequestContext,
|
|
84
87
|
collectDocumentContribution,
|
|
88
|
+
collectIslandState,
|
|
85
89
|
createIslandContainer,
|
|
86
90
|
describeIsland,
|
|
91
|
+
getIslandsGeneration,
|
|
87
92
|
hydrateIslandState,
|
|
88
93
|
islandInputsOf,
|
|
89
94
|
registerIsland,
|
|
90
95
|
reportIslandError,
|
|
91
|
-
resolveEagerUnits
|
|
96
|
+
resolveEagerUnits,
|
|
97
|
+
subscribeIslandsGeneration
|
|
92
98
|
} from "@foxford/den/island";
|
|
93
99
|
import { jsx as jsx3 } from "preact/jsx-runtime";
|
|
94
100
|
var failureStyle = {
|
|
@@ -131,12 +137,14 @@ function IslandRuntime({
|
|
|
131
137
|
route,
|
|
132
138
|
slots
|
|
133
139
|
}) {
|
|
134
|
-
var _a;
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
+
var _a, _b;
|
|
141
|
+
const inputs = useRef(null);
|
|
142
|
+
(_a = inputs.current) != null ? _a : inputs.current = islandInputsOf(descriptor, denState);
|
|
143
|
+
const [container, setContainer] = useState(
|
|
144
|
+
() => {
|
|
145
|
+
var _a2;
|
|
146
|
+
return createIslandContainer(descriptor, { context: browserRequestContext(), inputs: (_a2 = inputs.current) != null ? _a2 : {} });
|
|
147
|
+
}
|
|
140
148
|
);
|
|
141
149
|
const [seeded, setSeeded] = useState(void 0);
|
|
142
150
|
if (container !== null && denState !== void 0 && denState !== seeded) {
|
|
@@ -162,13 +170,35 @@ function IslandRuntime({
|
|
|
162
170
|
onDocument?.(collectDocumentContribution(container, descriptor));
|
|
163
171
|
});
|
|
164
172
|
}, [activeRoute, container, denState, descriptor, onDocument]);
|
|
173
|
+
const generation = useSyncExternalStore(subscribeIslandsGeneration, getIslandsGeneration);
|
|
174
|
+
const builtFor = useRef(generation);
|
|
175
|
+
useEffect(() => {
|
|
176
|
+
var _a2;
|
|
177
|
+
if (generation === builtFor.current || container === null) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
builtFor.current = generation;
|
|
181
|
+
const next = createIslandContainer(descriptor, { context: browserRequestContext(), inputs: (_a2 = inputs.current) != null ? _a2 : {} });
|
|
182
|
+
if (next === null) {
|
|
183
|
+
setContainer(null);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
hydrateIslandState(next, descriptor, collectIslandState(container, descriptor));
|
|
187
|
+
void container.dispose();
|
|
188
|
+
setContainer(next);
|
|
189
|
+
if (denState) {
|
|
190
|
+
void activateIslandViewModels(next, descriptor, activeRoute).then(() => {
|
|
191
|
+
onDocument?.(collectDocumentContribution(next, descriptor));
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}, [activeRoute, container, denState, descriptor, generation, onDocument]);
|
|
165
195
|
useEffect(() => {
|
|
166
196
|
if (container === null) {
|
|
167
197
|
return;
|
|
168
198
|
}
|
|
169
199
|
return registerIsland(describeIsland(descriptor, denState));
|
|
170
200
|
}, [container, descriptor, denState]);
|
|
171
|
-
const appName = (
|
|
201
|
+
const appName = (_b = descriptor.name) != null ? _b : "app";
|
|
172
202
|
if (container === null) {
|
|
173
203
|
return /* @__PURE__ */ jsx3(FailurePlaque, { name: appName, reason: "build" });
|
|
174
204
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
+
var _chunk3LGXNDYHcjs = require('./chunk-3LGXNDYH.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
3
6
|
var _chunkP4DSWCF6cjs = require('./chunk-P4DSWCF6.cjs');
|
|
4
7
|
|
|
5
8
|
// src/container-context.tsx
|
|
@@ -91,6 +94,9 @@ function Slot({ name }) {
|
|
|
91
94
|
|
|
92
95
|
|
|
93
96
|
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
94
100
|
var failureStyle = {
|
|
95
101
|
background: "#fef2f2",
|
|
96
102
|
border: "1px solid #fca5a5",
|
|
@@ -131,12 +137,14 @@ function IslandRuntime({
|
|
|
131
137
|
route,
|
|
132
138
|
slots
|
|
133
139
|
}) {
|
|
134
|
-
var _a;
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
+
var _a, _b;
|
|
141
|
+
const inputs = _hooks.useRef.call(void 0, null);
|
|
142
|
+
(_a = inputs.current) != null ? _a : inputs.current = _island.islandInputsOf.call(void 0, descriptor, denState);
|
|
143
|
+
const [container, setContainer] = _hooks.useState.call(void 0,
|
|
144
|
+
() => {
|
|
145
|
+
var _a2;
|
|
146
|
+
return _island.createIslandContainer.call(void 0, descriptor, { context: _island.browserRequestContext.call(void 0, ), inputs: (_a2 = inputs.current) != null ? _a2 : {} });
|
|
147
|
+
}
|
|
140
148
|
);
|
|
141
149
|
const [seeded, setSeeded] = _hooks.useState.call(void 0, void 0);
|
|
142
150
|
if (container !== null && denState !== void 0 && denState !== seeded) {
|
|
@@ -162,13 +170,35 @@ function IslandRuntime({
|
|
|
162
170
|
onDocument == null ? void 0 : onDocument(_island.collectDocumentContribution.call(void 0, container, descriptor));
|
|
163
171
|
});
|
|
164
172
|
}, [activeRoute, container, denState, descriptor, onDocument]);
|
|
173
|
+
const generation = _chunk3LGXNDYHcjs.useSyncExternalStore.call(void 0, _island.subscribeIslandsGeneration, _island.getIslandsGeneration);
|
|
174
|
+
const builtFor = _hooks.useRef.call(void 0, generation);
|
|
175
|
+
_hooks.useEffect.call(void 0, () => {
|
|
176
|
+
var _a2;
|
|
177
|
+
if (generation === builtFor.current || container === null) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
builtFor.current = generation;
|
|
181
|
+
const next = _island.createIslandContainer.call(void 0, descriptor, { context: _island.browserRequestContext.call(void 0, ), inputs: (_a2 = inputs.current) != null ? _a2 : {} });
|
|
182
|
+
if (next === null) {
|
|
183
|
+
setContainer(null);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
_island.hydrateIslandState.call(void 0, next, descriptor, _island.collectIslandState.call(void 0, container, descriptor));
|
|
187
|
+
void container.dispose();
|
|
188
|
+
setContainer(next);
|
|
189
|
+
if (denState) {
|
|
190
|
+
void _island.activateIslandViewModels.call(void 0, next, descriptor, activeRoute).then(() => {
|
|
191
|
+
onDocument == null ? void 0 : onDocument(_island.collectDocumentContribution.call(void 0, next, descriptor));
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}, [activeRoute, container, denState, descriptor, generation, onDocument]);
|
|
165
195
|
_hooks.useEffect.call(void 0, () => {
|
|
166
196
|
if (container === null) {
|
|
167
197
|
return;
|
|
168
198
|
}
|
|
169
199
|
return _island.registerIsland.call(void 0, _island.describeIsland.call(void 0, descriptor, denState));
|
|
170
200
|
}, [container, descriptor, denState]);
|
|
171
|
-
const appName = (
|
|
201
|
+
const appName = (_b = descriptor.name) != null ? _b : "app";
|
|
172
202
|
if (container === null) {
|
|
173
203
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, FailurePlaque, { name: appName, reason: "build" });
|
|
174
204
|
}
|
package/client.cjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkZVARQ3IYcjs = require('./chunk-ZVARQ3IY.cjs');
|
|
5
|
+
require('./chunk-3LGXNDYH.cjs');
|
|
5
6
|
require('./chunk-P4DSWCF6.cjs');
|
|
6
7
|
|
|
7
8
|
// src/client.ts
|
|
@@ -56,8 +57,8 @@ function mountApp(descriptor) {
|
|
|
56
57
|
return;
|
|
57
58
|
}
|
|
58
59
|
hydrated.add(node);
|
|
59
|
-
|
|
60
|
-
const Island =
|
|
60
|
+
_chunkZVARQ3IYcjs.installIslandResolver.call(void 0, );
|
|
61
|
+
const Island = _chunkZVARQ3IYcjs.createPreactIsland.call(void 0, descriptor);
|
|
61
62
|
const onDocument = (contribution) => {
|
|
62
63
|
_island.publishIslandDocument.call(void 0, node, contribution);
|
|
63
64
|
};
|
package/client.js
CHANGED
package/index.cjs
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkZVARQ3IYcjs = require('./chunk-ZVARQ3IY.cjs');
|
|
9
|
+
require('./chunk-3LGXNDYH.cjs');
|
|
9
10
|
require('./chunk-P4DSWCF6.cjs');
|
|
10
11
|
|
|
11
12
|
// src/render-island.tsx
|
|
@@ -13,7 +14,7 @@ var _preactrendertostring = require('preact-render-to-string');
|
|
|
13
14
|
var _jsxruntime = require('preact/jsx-runtime');
|
|
14
15
|
function renderPreactIsland(descriptor, { container, slots }) {
|
|
15
16
|
const View = descriptor.view;
|
|
16
|
-
const tree = /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
17
|
+
const tree = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkZVARQ3IYcjs.ContainerProvider, { value: container, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkZVARQ3IYcjs.SlotHost, { fills: slots, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, View, {}) }) });
|
|
17
18
|
const serverRender = descriptor.serverRender;
|
|
18
19
|
if (serverRender) {
|
|
19
20
|
return serverRender(tree, (node) => _preactrendertostring.renderToString.call(void 0, node));
|
|
@@ -30,8 +31,8 @@ function renderIslandOnClient() {
|
|
|
30
31
|
}
|
|
31
32
|
function preactAdapter() {
|
|
32
33
|
return {
|
|
33
|
-
createIsland:
|
|
34
|
-
installResolver:
|
|
34
|
+
createIsland: _chunkZVARQ3IYcjs.createPreactIsland,
|
|
35
|
+
installResolver: _chunkZVARQ3IYcjs.installIslandResolver,
|
|
35
36
|
renderIsland: CLIENT_BUNDLE ? renderIslandOnClient : renderPreactIsland,
|
|
36
37
|
type: "preact"
|
|
37
38
|
};
|
|
@@ -44,4 +45,4 @@ function preactAdapter() {
|
|
|
44
45
|
|
|
45
46
|
|
|
46
47
|
|
|
47
|
-
exports.ContainerProvider =
|
|
48
|
+
exports.ContainerProvider = _chunkZVARQ3IYcjs.ContainerProvider; exports.Slot = _chunkZVARQ3IYcjs.Slot; exports.SlotHost = _chunkZVARQ3IYcjs.SlotHost; exports.createPreactIsland = _chunkZVARQ3IYcjs.createPreactIsland; exports.installIslandResolver = _chunkZVARQ3IYcjs.installIslandResolver; exports.preactAdapter = preactAdapter; exports.useContainer = _chunkZVARQ3IYcjs.useContainer;
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foxford/den-preact",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Den Preact view adapter — остров, серверная отрисовка, слоты, пресет сборки",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"foxford",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"type": "module",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@foxford/den": "^3.
|
|
29
|
+
"@foxford/den": "^3.7.0",
|
|
30
30
|
"@foxford/logger": "^1.2.2"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
@@ -65,10 +65,12 @@
|
|
|
65
65
|
},
|
|
66
66
|
"files": [
|
|
67
67
|
"README.mdx",
|
|
68
|
+
"chunk-3F3F3ALW.js",
|
|
69
|
+
"chunk-3LGXNDYH.cjs",
|
|
70
|
+
"chunk-5BDZSAOP.js",
|
|
68
71
|
"chunk-5JBD5THX.js",
|
|
69
72
|
"chunk-P4DSWCF6.cjs",
|
|
70
|
-
"chunk-
|
|
71
|
-
"chunk-XKEFCZET.cjs",
|
|
73
|
+
"chunk-ZVARQ3IY.cjs",
|
|
72
74
|
"client.cjs",
|
|
73
75
|
"client.d.cts",
|
|
74
76
|
"client.d.ts",
|
|
@@ -87,6 +89,6 @@
|
|
|
87
89
|
"use-sync-external-store.d.ts",
|
|
88
90
|
"use-sync-external-store.js"
|
|
89
91
|
],
|
|
90
|
-
"sha": "
|
|
92
|
+
"sha": "c642307",
|
|
91
93
|
"scripts": {}
|
|
92
94
|
}
|
|
@@ -1,33 +1,11 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
// src/use-sync-external-store.ts
|
|
4
|
-
var _compat = require('preact/compat');
|
|
5
|
-
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, _getServerSnapshot, selector, isEqual) {
|
|
6
|
-
const cache = _compat.useRef.call(void 0, { hasValue: false });
|
|
7
|
-
const getSelection = _compat.useMemo.call(void 0, () => {
|
|
8
|
-
let memo = null;
|
|
9
|
-
function select(snapshot) {
|
|
10
|
-
if (memo !== null && Object.is(memo.snapshot, snapshot)) {
|
|
11
|
-
return memo.selection;
|
|
12
|
-
}
|
|
13
|
-
const next = selector(snapshot);
|
|
14
|
-
const previous = memo === null ? cache.current : { hasValue: true, value: memo.selection };
|
|
15
|
-
const selection2 = isEqual !== void 0 && previous.hasValue && isEqual(previous.value, next) ? previous.value : next;
|
|
16
|
-
memo = { selection: selection2, snapshot };
|
|
17
|
-
return selection2;
|
|
18
|
-
}
|
|
19
|
-
return () => select(getSnapshot());
|
|
20
|
-
}, [getSnapshot, isEqual, selector]);
|
|
21
|
-
const selection = _compat.useSyncExternalStore.call(void 0, subscribe, getSelection);
|
|
22
|
-
_compat.useEffect.call(void 0, () => {
|
|
23
|
-
cache.current = { hasValue: true, value: selection };
|
|
24
|
-
}, [selection]);
|
|
25
|
-
_compat.useDebugValue.call(void 0, selection);
|
|
26
|
-
return selection;
|
|
27
|
-
}
|
|
28
|
-
var use_sync_external_store_default = { useSyncExternalStore: _compat.useSyncExternalStore, useSyncExternalStoreWithSelector };
|
|
29
3
|
|
|
30
4
|
|
|
5
|
+
var _chunk3LGXNDYHcjs = require('./chunk-3LGXNDYH.cjs');
|
|
6
|
+
require('./chunk-P4DSWCF6.cjs');
|
|
31
7
|
|
|
32
8
|
|
|
33
|
-
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
exports.default = _chunk3LGXNDYHcjs.use_sync_external_store_default; exports.useSyncExternalStore = _chunk3LGXNDYHcjs.useSyncExternalStore; exports.useSyncExternalStoreWithSelector = _chunk3LGXNDYHcjs.useSyncExternalStoreWithSelector;
|
|
@@ -1,31 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useSyncExternalStore,
|
|
3
|
+
useSyncExternalStoreWithSelector,
|
|
4
|
+
use_sync_external_store_default
|
|
5
|
+
} from "./chunk-3F3F3ALW.js";
|
|
1
6
|
import "./chunk-5JBD5THX.js";
|
|
2
|
-
|
|
3
|
-
// src/use-sync-external-store.ts
|
|
4
|
-
import { useDebugValue, useEffect, useMemo, useRef, useSyncExternalStore } from "preact/compat";
|
|
5
|
-
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, _getServerSnapshot, selector, isEqual) {
|
|
6
|
-
const cache = useRef({ hasValue: false });
|
|
7
|
-
const getSelection = useMemo(() => {
|
|
8
|
-
let memo = null;
|
|
9
|
-
function select(snapshot) {
|
|
10
|
-
if (memo !== null && Object.is(memo.snapshot, snapshot)) {
|
|
11
|
-
return memo.selection;
|
|
12
|
-
}
|
|
13
|
-
const next = selector(snapshot);
|
|
14
|
-
const previous = memo === null ? cache.current : { hasValue: true, value: memo.selection };
|
|
15
|
-
const selection2 = isEqual !== void 0 && previous.hasValue && isEqual(previous.value, next) ? previous.value : next;
|
|
16
|
-
memo = { selection: selection2, snapshot };
|
|
17
|
-
return selection2;
|
|
18
|
-
}
|
|
19
|
-
return () => select(getSnapshot());
|
|
20
|
-
}, [getSnapshot, isEqual, selector]);
|
|
21
|
-
const selection = useSyncExternalStore(subscribe, getSelection);
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
cache.current = { hasValue: true, value: selection };
|
|
24
|
-
}, [selection]);
|
|
25
|
-
useDebugValue(selection);
|
|
26
|
-
return selection;
|
|
27
|
-
}
|
|
28
|
-
var use_sync_external_store_default = { useSyncExternalStore, useSyncExternalStoreWithSelector };
|
|
29
7
|
export {
|
|
30
8
|
use_sync_external_store_default as default,
|
|
31
9
|
useSyncExternalStore,
|