1 | // src/index.ts
|
---|
2 | import * as React2 from "react";
|
---|
3 | import { useSyncExternalStoreWithSelector as useSyncExternalStoreWithSelector2 } from "use-sync-external-store/with-selector.js";
|
---|
4 |
|
---|
5 | // src/utils/react.ts
|
---|
6 | import * as ReactOriginal from "react";
|
---|
7 | var React = (
|
---|
8 | // prettier-ignore
|
---|
9 | // @ts-ignore
|
---|
10 | "default" in ReactOriginal ? ReactOriginal["default"] : ReactOriginal
|
---|
11 | );
|
---|
12 |
|
---|
13 | // src/components/Context.ts
|
---|
14 | var ContextKey = Symbol.for(`react-redux-context`);
|
---|
15 | var gT = typeof globalThis !== "undefined" ? globalThis : (
|
---|
16 | /* fall back to a per-module scope (pre-8.1 behaviour) if `globalThis` is not available */
|
---|
17 | {}
|
---|
18 | );
|
---|
19 | function getContext() {
|
---|
20 | if (!React.createContext)
|
---|
21 | return {};
|
---|
22 | const contextMap = gT[ContextKey] ?? (gT[ContextKey] = /* @__PURE__ */ new Map());
|
---|
23 | let realContext = contextMap.get(React.createContext);
|
---|
24 | if (!realContext) {
|
---|
25 | realContext = React.createContext(
|
---|
26 | null
|
---|
27 | );
|
---|
28 | if (process.env.NODE_ENV !== "production") {
|
---|
29 | realContext.displayName = "ReactRedux";
|
---|
30 | }
|
---|
31 | contextMap.set(React.createContext, realContext);
|
---|
32 | }
|
---|
33 | return realContext;
|
---|
34 | }
|
---|
35 | var ReactReduxContext = /* @__PURE__ */ getContext();
|
---|
36 |
|
---|
37 | // src/utils/useSyncExternalStore.ts
|
---|
38 | var notInitialized = () => {
|
---|
39 | throw new Error("uSES not initialized!");
|
---|
40 | };
|
---|
41 |
|
---|
42 | // src/hooks/useReduxContext.ts
|
---|
43 | function createReduxContextHook(context = ReactReduxContext) {
|
---|
44 | return function useReduxContext2() {
|
---|
45 | const contextValue = React.useContext(context);
|
---|
46 | if (process.env.NODE_ENV !== "production" && !contextValue) {
|
---|
47 | throw new Error(
|
---|
48 | "could not find react-redux context value; please ensure the component is wrapped in a <Provider>"
|
---|
49 | );
|
---|
50 | }
|
---|
51 | return contextValue;
|
---|
52 | };
|
---|
53 | }
|
---|
54 | var useReduxContext = /* @__PURE__ */ createReduxContextHook();
|
---|
55 |
|
---|
56 | // src/hooks/useSelector.ts
|
---|
57 | var useSyncExternalStoreWithSelector = notInitialized;
|
---|
58 | var initializeUseSelector = (fn) => {
|
---|
59 | useSyncExternalStoreWithSelector = fn;
|
---|
60 | };
|
---|
61 | var refEquality = (a, b) => a === b;
|
---|
62 | function createSelectorHook(context = ReactReduxContext) {
|
---|
63 | const useReduxContext2 = context === ReactReduxContext ? useReduxContext : createReduxContextHook(context);
|
---|
64 | const useSelector2 = (selector, equalityFnOrOptions = {}) => {
|
---|
65 | const { equalityFn = refEquality, devModeChecks = {} } = typeof equalityFnOrOptions === "function" ? { equalityFn: equalityFnOrOptions } : equalityFnOrOptions;
|
---|
66 | if (process.env.NODE_ENV !== "production") {
|
---|
67 | if (!selector) {
|
---|
68 | throw new Error(`You must pass a selector to useSelector`);
|
---|
69 | }
|
---|
70 | if (typeof selector !== "function") {
|
---|
71 | throw new Error(`You must pass a function as a selector to useSelector`);
|
---|
72 | }
|
---|
73 | if (typeof equalityFn !== "function") {
|
---|
74 | throw new Error(
|
---|
75 | `You must pass a function as an equality function to useSelector`
|
---|
76 | );
|
---|
77 | }
|
---|
78 | }
|
---|
79 | const {
|
---|
80 | store,
|
---|
81 | subscription,
|
---|
82 | getServerState,
|
---|
83 | stabilityCheck,
|
---|
84 | identityFunctionCheck
|
---|
85 | } = useReduxContext2();
|
---|
86 | const firstRun = React.useRef(true);
|
---|
87 | const wrappedSelector = React.useCallback(
|
---|
88 | {
|
---|
89 | [selector.name](state) {
|
---|
90 | const selected = selector(state);
|
---|
91 | if (process.env.NODE_ENV !== "production") {
|
---|
92 | const {
|
---|
93 | identityFunctionCheck: finalIdentityFunctionCheck,
|
---|
94 | stabilityCheck: finalStabilityCheck
|
---|
95 | } = {
|
---|
96 | stabilityCheck,
|
---|
97 | identityFunctionCheck,
|
---|
98 | ...devModeChecks
|
---|
99 | };
|
---|
100 | if (finalStabilityCheck === "always" || finalStabilityCheck === "once" && firstRun.current) {
|
---|
101 | const toCompare = selector(state);
|
---|
102 | if (!equalityFn(selected, toCompare)) {
|
---|
103 | let stack = void 0;
|
---|
104 | try {
|
---|
105 | throw new Error();
|
---|
106 | } catch (e) {
|
---|
107 | ;
|
---|
108 | ({ stack } = e);
|
---|
109 | }
|
---|
110 | console.warn(
|
---|
111 | "Selector " + (selector.name || "unknown") + " returned a different result when called with the same parameters. This can lead to unnecessary rerenders.\nSelectors that return a new reference (such as an object or an array) should be memoized: https://redux.js.org/usage/deriving-data-selectors#optimizing-selectors-with-memoization",
|
---|
112 | {
|
---|
113 | state,
|
---|
114 | selected,
|
---|
115 | selected2: toCompare,
|
---|
116 | stack
|
---|
117 | }
|
---|
118 | );
|
---|
119 | }
|
---|
120 | }
|
---|
121 | if (finalIdentityFunctionCheck === "always" || finalIdentityFunctionCheck === "once" && firstRun.current) {
|
---|
122 | if (selected === state) {
|
---|
123 | let stack = void 0;
|
---|
124 | try {
|
---|
125 | throw new Error();
|
---|
126 | } catch (e) {
|
---|
127 | ;
|
---|
128 | ({ stack } = e);
|
---|
129 | }
|
---|
130 | console.warn(
|
---|
131 | "Selector " + (selector.name || "unknown") + " returned the root state when called. This can lead to unnecessary rerenders.\nSelectors that return the entire state are almost certainly a mistake, as they will cause a rerender whenever *anything* in state changes.",
|
---|
132 | { stack }
|
---|
133 | );
|
---|
134 | }
|
---|
135 | }
|
---|
136 | if (firstRun.current)
|
---|
137 | firstRun.current = false;
|
---|
138 | }
|
---|
139 | return selected;
|
---|
140 | }
|
---|
141 | }[selector.name],
|
---|
142 | [selector, stabilityCheck, devModeChecks.stabilityCheck]
|
---|
143 | );
|
---|
144 | const selectedState = useSyncExternalStoreWithSelector(
|
---|
145 | subscription.addNestedSub,
|
---|
146 | store.getState,
|
---|
147 | getServerState || store.getState,
|
---|
148 | wrappedSelector,
|
---|
149 | equalityFn
|
---|
150 | );
|
---|
151 | React.useDebugValue(selectedState);
|
---|
152 | return selectedState;
|
---|
153 | };
|
---|
154 | Object.assign(useSelector2, {
|
---|
155 | withTypes: () => useSelector2
|
---|
156 | });
|
---|
157 | return useSelector2;
|
---|
158 | }
|
---|
159 | var useSelector = /* @__PURE__ */ createSelectorHook();
|
---|
160 |
|
---|
161 | // src/utils/react-is.ts
|
---|
162 | var REACT_ELEMENT_TYPE = Symbol.for("react.element");
|
---|
163 | var REACT_PORTAL_TYPE = Symbol.for("react.portal");
|
---|
164 | var REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
|
---|
165 | var REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode");
|
---|
166 | var REACT_PROFILER_TYPE = Symbol.for("react.profiler");
|
---|
167 | var REACT_PROVIDER_TYPE = Symbol.for("react.provider");
|
---|
168 | var REACT_CONTEXT_TYPE = Symbol.for("react.context");
|
---|
169 | var REACT_SERVER_CONTEXT_TYPE = Symbol.for("react.server_context");
|
---|
170 | var REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref");
|
---|
171 | var REACT_SUSPENSE_TYPE = Symbol.for("react.suspense");
|
---|
172 | var REACT_SUSPENSE_LIST_TYPE = Symbol.for("react.suspense_list");
|
---|
173 | var REACT_MEMO_TYPE = Symbol.for("react.memo");
|
---|
174 | var REACT_LAZY_TYPE = Symbol.for("react.lazy");
|
---|
175 | var REACT_OFFSCREEN_TYPE = Symbol.for("react.offscreen");
|
---|
176 | var REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference");
|
---|
177 | var ForwardRef = REACT_FORWARD_REF_TYPE;
|
---|
178 | var Memo = REACT_MEMO_TYPE;
|
---|
179 | function isValidElementType(type) {
|
---|
180 | if (typeof type === "string" || typeof type === "function") {
|
---|
181 | return true;
|
---|
182 | }
|
---|
183 | if (type === REACT_FRAGMENT_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || type === REACT_OFFSCREEN_TYPE) {
|
---|
184 | return true;
|
---|
185 | }
|
---|
186 | if (typeof type === "object" && type !== null) {
|
---|
187 | if (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || // This needs to include all possible module reference object
|
---|
188 | // types supported by any Flight configuration anywhere since
|
---|
189 | // we don't know which Flight build this will end up being used
|
---|
190 | // with.
|
---|
191 | type.$$typeof === REACT_CLIENT_REFERENCE || type.getModuleId !== void 0) {
|
---|
192 | return true;
|
---|
193 | }
|
---|
194 | }
|
---|
195 | return false;
|
---|
196 | }
|
---|
197 | function typeOf(object) {
|
---|
198 | if (typeof object === "object" && object !== null) {
|
---|
199 | const $$typeof = object.$$typeof;
|
---|
200 | switch ($$typeof) {
|
---|
201 | case REACT_ELEMENT_TYPE: {
|
---|
202 | const type = object.type;
|
---|
203 | switch (type) {
|
---|
204 | case REACT_FRAGMENT_TYPE:
|
---|
205 | case REACT_PROFILER_TYPE:
|
---|
206 | case REACT_STRICT_MODE_TYPE:
|
---|
207 | case REACT_SUSPENSE_TYPE:
|
---|
208 | case REACT_SUSPENSE_LIST_TYPE:
|
---|
209 | return type;
|
---|
210 | default: {
|
---|
211 | const $$typeofType = type && type.$$typeof;
|
---|
212 | switch ($$typeofType) {
|
---|
213 | case REACT_SERVER_CONTEXT_TYPE:
|
---|
214 | case REACT_CONTEXT_TYPE:
|
---|
215 | case REACT_FORWARD_REF_TYPE:
|
---|
216 | case REACT_LAZY_TYPE:
|
---|
217 | case REACT_MEMO_TYPE:
|
---|
218 | case REACT_PROVIDER_TYPE:
|
---|
219 | return $$typeofType;
|
---|
220 | default:
|
---|
221 | return $$typeof;
|
---|
222 | }
|
---|
223 | }
|
---|
224 | }
|
---|
225 | }
|
---|
226 | case REACT_PORTAL_TYPE: {
|
---|
227 | return $$typeof;
|
---|
228 | }
|
---|
229 | }
|
---|
230 | }
|
---|
231 | return void 0;
|
---|
232 | }
|
---|
233 | function isContextConsumer(object) {
|
---|
234 | return typeOf(object) === REACT_CONTEXT_TYPE;
|
---|
235 | }
|
---|
236 | function isMemo(object) {
|
---|
237 | return typeOf(object) === REACT_MEMO_TYPE;
|
---|
238 | }
|
---|
239 |
|
---|
240 | // src/utils/warning.ts
|
---|
241 | function warning(message) {
|
---|
242 | if (typeof console !== "undefined" && typeof console.error === "function") {
|
---|
243 | console.error(message);
|
---|
244 | }
|
---|
245 | try {
|
---|
246 | throw new Error(message);
|
---|
247 | } catch (e) {
|
---|
248 | }
|
---|
249 | }
|
---|
250 |
|
---|
251 | // src/connect/verifySubselectors.ts
|
---|
252 | function verify(selector, methodName) {
|
---|
253 | if (!selector) {
|
---|
254 | throw new Error(`Unexpected value for ${methodName} in connect.`);
|
---|
255 | } else if (methodName === "mapStateToProps" || methodName === "mapDispatchToProps") {
|
---|
256 | if (!Object.prototype.hasOwnProperty.call(selector, "dependsOnOwnProps")) {
|
---|
257 | warning(
|
---|
258 | `The selector for ${methodName} of connect did not specify a value for dependsOnOwnProps.`
|
---|
259 | );
|
---|
260 | }
|
---|
261 | }
|
---|
262 | }
|
---|
263 | function verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps) {
|
---|
264 | verify(mapStateToProps, "mapStateToProps");
|
---|
265 | verify(mapDispatchToProps, "mapDispatchToProps");
|
---|
266 | verify(mergeProps, "mergeProps");
|
---|
267 | }
|
---|
268 |
|
---|
269 | // src/connect/selectorFactory.ts
|
---|
270 | function pureFinalPropsSelectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, {
|
---|
271 | areStatesEqual,
|
---|
272 | areOwnPropsEqual,
|
---|
273 | areStatePropsEqual
|
---|
274 | }) {
|
---|
275 | let hasRunAtLeastOnce = false;
|
---|
276 | let state;
|
---|
277 | let ownProps;
|
---|
278 | let stateProps;
|
---|
279 | let dispatchProps;
|
---|
280 | let mergedProps;
|
---|
281 | function handleFirstCall(firstState, firstOwnProps) {
|
---|
282 | state = firstState;
|
---|
283 | ownProps = firstOwnProps;
|
---|
284 | stateProps = mapStateToProps(state, ownProps);
|
---|
285 | dispatchProps = mapDispatchToProps(dispatch, ownProps);
|
---|
286 | mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
|
---|
287 | hasRunAtLeastOnce = true;
|
---|
288 | return mergedProps;
|
---|
289 | }
|
---|
290 | function handleNewPropsAndNewState() {
|
---|
291 | stateProps = mapStateToProps(state, ownProps);
|
---|
292 | if (mapDispatchToProps.dependsOnOwnProps)
|
---|
293 | dispatchProps = mapDispatchToProps(dispatch, ownProps);
|
---|
294 | mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
|
---|
295 | return mergedProps;
|
---|
296 | }
|
---|
297 | function handleNewProps() {
|
---|
298 | if (mapStateToProps.dependsOnOwnProps)
|
---|
299 | stateProps = mapStateToProps(state, ownProps);
|
---|
300 | if (mapDispatchToProps.dependsOnOwnProps)
|
---|
301 | dispatchProps = mapDispatchToProps(dispatch, ownProps);
|
---|
302 | mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
|
---|
303 | return mergedProps;
|
---|
304 | }
|
---|
305 | function handleNewState() {
|
---|
306 | const nextStateProps = mapStateToProps(state, ownProps);
|
---|
307 | const statePropsChanged = !areStatePropsEqual(nextStateProps, stateProps);
|
---|
308 | stateProps = nextStateProps;
|
---|
309 | if (statePropsChanged)
|
---|
310 | mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
|
---|
311 | return mergedProps;
|
---|
312 | }
|
---|
313 | function handleSubsequentCalls(nextState, nextOwnProps) {
|
---|
314 | const propsChanged = !areOwnPropsEqual(nextOwnProps, ownProps);
|
---|
315 | const stateChanged = !areStatesEqual(
|
---|
316 | nextState,
|
---|
317 | state,
|
---|
318 | nextOwnProps,
|
---|
319 | ownProps
|
---|
320 | );
|
---|
321 | state = nextState;
|
---|
322 | ownProps = nextOwnProps;
|
---|
323 | if (propsChanged && stateChanged)
|
---|
324 | return handleNewPropsAndNewState();
|
---|
325 | if (propsChanged)
|
---|
326 | return handleNewProps();
|
---|
327 | if (stateChanged)
|
---|
328 | return handleNewState();
|
---|
329 | return mergedProps;
|
---|
330 | }
|
---|
331 | return function pureFinalPropsSelector(nextState, nextOwnProps) {
|
---|
332 | return hasRunAtLeastOnce ? handleSubsequentCalls(nextState, nextOwnProps) : handleFirstCall(nextState, nextOwnProps);
|
---|
333 | };
|
---|
334 | }
|
---|
335 | function finalPropsSelectorFactory(dispatch, {
|
---|
336 | initMapStateToProps,
|
---|
337 | initMapDispatchToProps,
|
---|
338 | initMergeProps,
|
---|
339 | ...options
|
---|
340 | }) {
|
---|
341 | const mapStateToProps = initMapStateToProps(dispatch, options);
|
---|
342 | const mapDispatchToProps = initMapDispatchToProps(dispatch, options);
|
---|
343 | const mergeProps = initMergeProps(dispatch, options);
|
---|
344 | if (process.env.NODE_ENV !== "production") {
|
---|
345 | verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps);
|
---|
346 | }
|
---|
347 | return pureFinalPropsSelectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, options);
|
---|
348 | }
|
---|
349 |
|
---|
350 | // src/utils/bindActionCreators.ts
|
---|
351 | function bindActionCreators(actionCreators, dispatch) {
|
---|
352 | const boundActionCreators = {};
|
---|
353 | for (const key in actionCreators) {
|
---|
354 | const actionCreator = actionCreators[key];
|
---|
355 | if (typeof actionCreator === "function") {
|
---|
356 | boundActionCreators[key] = (...args) => dispatch(actionCreator(...args));
|
---|
357 | }
|
---|
358 | }
|
---|
359 | return boundActionCreators;
|
---|
360 | }
|
---|
361 |
|
---|
362 | // src/utils/isPlainObject.ts
|
---|
363 | function isPlainObject(obj) {
|
---|
364 | if (typeof obj !== "object" || obj === null)
|
---|
365 | return false;
|
---|
366 | const proto = Object.getPrototypeOf(obj);
|
---|
367 | if (proto === null)
|
---|
368 | return true;
|
---|
369 | let baseProto = proto;
|
---|
370 | while (Object.getPrototypeOf(baseProto) !== null) {
|
---|
371 | baseProto = Object.getPrototypeOf(baseProto);
|
---|
372 | }
|
---|
373 | return proto === baseProto;
|
---|
374 | }
|
---|
375 |
|
---|
376 | // src/utils/verifyPlainObject.ts
|
---|
377 | function verifyPlainObject(value, displayName, methodName) {
|
---|
378 | if (!isPlainObject(value)) {
|
---|
379 | warning(
|
---|
380 | `${methodName}() in ${displayName} must return a plain object. Instead received ${value}.`
|
---|
381 | );
|
---|
382 | }
|
---|
383 | }
|
---|
384 |
|
---|
385 | // src/connect/wrapMapToProps.ts
|
---|
386 | function wrapMapToPropsConstant(getConstant) {
|
---|
387 | return function initConstantSelector(dispatch) {
|
---|
388 | const constant = getConstant(dispatch);
|
---|
389 | function constantSelector() {
|
---|
390 | return constant;
|
---|
391 | }
|
---|
392 | constantSelector.dependsOnOwnProps = false;
|
---|
393 | return constantSelector;
|
---|
394 | };
|
---|
395 | }
|
---|
396 | function getDependsOnOwnProps(mapToProps) {
|
---|
397 | return mapToProps.dependsOnOwnProps ? Boolean(mapToProps.dependsOnOwnProps) : mapToProps.length !== 1;
|
---|
398 | }
|
---|
399 | function wrapMapToPropsFunc(mapToProps, methodName) {
|
---|
400 | return function initProxySelector(dispatch, { displayName }) {
|
---|
401 | const proxy = function mapToPropsProxy(stateOrDispatch, ownProps) {
|
---|
402 | return proxy.dependsOnOwnProps ? proxy.mapToProps(stateOrDispatch, ownProps) : proxy.mapToProps(stateOrDispatch, void 0);
|
---|
403 | };
|
---|
404 | proxy.dependsOnOwnProps = true;
|
---|
405 | proxy.mapToProps = function detectFactoryAndVerify(stateOrDispatch, ownProps) {
|
---|
406 | proxy.mapToProps = mapToProps;
|
---|
407 | proxy.dependsOnOwnProps = getDependsOnOwnProps(mapToProps);
|
---|
408 | let props = proxy(stateOrDispatch, ownProps);
|
---|
409 | if (typeof props === "function") {
|
---|
410 | proxy.mapToProps = props;
|
---|
411 | proxy.dependsOnOwnProps = getDependsOnOwnProps(props);
|
---|
412 | props = proxy(stateOrDispatch, ownProps);
|
---|
413 | }
|
---|
414 | if (process.env.NODE_ENV !== "production")
|
---|
415 | verifyPlainObject(props, displayName, methodName);
|
---|
416 | return props;
|
---|
417 | };
|
---|
418 | return proxy;
|
---|
419 | };
|
---|
420 | }
|
---|
421 |
|
---|
422 | // src/connect/invalidArgFactory.ts
|
---|
423 | function createInvalidArgFactory(arg, name) {
|
---|
424 | return (dispatch, options) => {
|
---|
425 | throw new Error(
|
---|
426 | `Invalid value of type ${typeof arg} for ${name} argument when connecting component ${options.wrappedComponentName}.`
|
---|
427 | );
|
---|
428 | };
|
---|
429 | }
|
---|
430 |
|
---|
431 | // src/connect/mapDispatchToProps.ts
|
---|
432 | function mapDispatchToPropsFactory(mapDispatchToProps) {
|
---|
433 | return mapDispatchToProps && typeof mapDispatchToProps === "object" ? wrapMapToPropsConstant(
|
---|
434 | (dispatch) => (
|
---|
435 | // @ts-ignore
|
---|
436 | bindActionCreators(mapDispatchToProps, dispatch)
|
---|
437 | )
|
---|
438 | ) : !mapDispatchToProps ? wrapMapToPropsConstant((dispatch) => ({
|
---|
439 | dispatch
|
---|
440 | })) : typeof mapDispatchToProps === "function" ? (
|
---|
441 | // @ts-ignore
|
---|
442 | wrapMapToPropsFunc(mapDispatchToProps, "mapDispatchToProps")
|
---|
443 | ) : createInvalidArgFactory(mapDispatchToProps, "mapDispatchToProps");
|
---|
444 | }
|
---|
445 |
|
---|
446 | // src/connect/mapStateToProps.ts
|
---|
447 | function mapStateToPropsFactory(mapStateToProps) {
|
---|
448 | return !mapStateToProps ? wrapMapToPropsConstant(() => ({})) : typeof mapStateToProps === "function" ? (
|
---|
449 | // @ts-ignore
|
---|
450 | wrapMapToPropsFunc(mapStateToProps, "mapStateToProps")
|
---|
451 | ) : createInvalidArgFactory(mapStateToProps, "mapStateToProps");
|
---|
452 | }
|
---|
453 |
|
---|
454 | // src/connect/mergeProps.ts
|
---|
455 | function defaultMergeProps(stateProps, dispatchProps, ownProps) {
|
---|
456 | return { ...ownProps, ...stateProps, ...dispatchProps };
|
---|
457 | }
|
---|
458 | function wrapMergePropsFunc(mergeProps) {
|
---|
459 | return function initMergePropsProxy(dispatch, { displayName, areMergedPropsEqual }) {
|
---|
460 | let hasRunOnce = false;
|
---|
461 | let mergedProps;
|
---|
462 | return function mergePropsProxy(stateProps, dispatchProps, ownProps) {
|
---|
463 | const nextMergedProps = mergeProps(stateProps, dispatchProps, ownProps);
|
---|
464 | if (hasRunOnce) {
|
---|
465 | if (!areMergedPropsEqual(nextMergedProps, mergedProps))
|
---|
466 | mergedProps = nextMergedProps;
|
---|
467 | } else {
|
---|
468 | hasRunOnce = true;
|
---|
469 | mergedProps = nextMergedProps;
|
---|
470 | if (process.env.NODE_ENV !== "production")
|
---|
471 | verifyPlainObject(mergedProps, displayName, "mergeProps");
|
---|
472 | }
|
---|
473 | return mergedProps;
|
---|
474 | };
|
---|
475 | };
|
---|
476 | }
|
---|
477 | function mergePropsFactory(mergeProps) {
|
---|
478 | return !mergeProps ? () => defaultMergeProps : typeof mergeProps === "function" ? wrapMergePropsFunc(mergeProps) : createInvalidArgFactory(mergeProps, "mergeProps");
|
---|
479 | }
|
---|
480 |
|
---|
481 | // src/utils/batch.ts
|
---|
482 | function defaultNoopBatch(callback) {
|
---|
483 | callback();
|
---|
484 | }
|
---|
485 |
|
---|
486 | // src/utils/Subscription.ts
|
---|
487 | function createListenerCollection() {
|
---|
488 | let first = null;
|
---|
489 | let last = null;
|
---|
490 | return {
|
---|
491 | clear() {
|
---|
492 | first = null;
|
---|
493 | last = null;
|
---|
494 | },
|
---|
495 | notify() {
|
---|
496 | defaultNoopBatch(() => {
|
---|
497 | let listener = first;
|
---|
498 | while (listener) {
|
---|
499 | listener.callback();
|
---|
500 | listener = listener.next;
|
---|
501 | }
|
---|
502 | });
|
---|
503 | },
|
---|
504 | get() {
|
---|
505 | const listeners = [];
|
---|
506 | let listener = first;
|
---|
507 | while (listener) {
|
---|
508 | listeners.push(listener);
|
---|
509 | listener = listener.next;
|
---|
510 | }
|
---|
511 | return listeners;
|
---|
512 | },
|
---|
513 | subscribe(callback) {
|
---|
514 | let isSubscribed = true;
|
---|
515 | const listener = last = {
|
---|
516 | callback,
|
---|
517 | next: null,
|
---|
518 | prev: last
|
---|
519 | };
|
---|
520 | if (listener.prev) {
|
---|
521 | listener.prev.next = listener;
|
---|
522 | } else {
|
---|
523 | first = listener;
|
---|
524 | }
|
---|
525 | return function unsubscribe() {
|
---|
526 | if (!isSubscribed || first === null)
|
---|
527 | return;
|
---|
528 | isSubscribed = false;
|
---|
529 | if (listener.next) {
|
---|
530 | listener.next.prev = listener.prev;
|
---|
531 | } else {
|
---|
532 | last = listener.prev;
|
---|
533 | }
|
---|
534 | if (listener.prev) {
|
---|
535 | listener.prev.next = listener.next;
|
---|
536 | } else {
|
---|
537 | first = listener.next;
|
---|
538 | }
|
---|
539 | };
|
---|
540 | }
|
---|
541 | };
|
---|
542 | }
|
---|
543 | var nullListeners = {
|
---|
544 | notify() {
|
---|
545 | },
|
---|
546 | get: () => []
|
---|
547 | };
|
---|
548 | function createSubscription(store, parentSub) {
|
---|
549 | let unsubscribe;
|
---|
550 | let listeners = nullListeners;
|
---|
551 | let subscriptionsAmount = 0;
|
---|
552 | let selfSubscribed = false;
|
---|
553 | function addNestedSub(listener) {
|
---|
554 | trySubscribe();
|
---|
555 | const cleanupListener = listeners.subscribe(listener);
|
---|
556 | let removed = false;
|
---|
557 | return () => {
|
---|
558 | if (!removed) {
|
---|
559 | removed = true;
|
---|
560 | cleanupListener();
|
---|
561 | tryUnsubscribe();
|
---|
562 | }
|
---|
563 | };
|
---|
564 | }
|
---|
565 | function notifyNestedSubs() {
|
---|
566 | listeners.notify();
|
---|
567 | }
|
---|
568 | function handleChangeWrapper() {
|
---|
569 | if (subscription.onStateChange) {
|
---|
570 | subscription.onStateChange();
|
---|
571 | }
|
---|
572 | }
|
---|
573 | function isSubscribed() {
|
---|
574 | return selfSubscribed;
|
---|
575 | }
|
---|
576 | function trySubscribe() {
|
---|
577 | subscriptionsAmount++;
|
---|
578 | if (!unsubscribe) {
|
---|
579 | unsubscribe = parentSub ? parentSub.addNestedSub(handleChangeWrapper) : store.subscribe(handleChangeWrapper);
|
---|
580 | listeners = createListenerCollection();
|
---|
581 | }
|
---|
582 | }
|
---|
583 | function tryUnsubscribe() {
|
---|
584 | subscriptionsAmount--;
|
---|
585 | if (unsubscribe && subscriptionsAmount === 0) {
|
---|
586 | unsubscribe();
|
---|
587 | unsubscribe = void 0;
|
---|
588 | listeners.clear();
|
---|
589 | listeners = nullListeners;
|
---|
590 | }
|
---|
591 | }
|
---|
592 | function trySubscribeSelf() {
|
---|
593 | if (!selfSubscribed) {
|
---|
594 | selfSubscribed = true;
|
---|
595 | trySubscribe();
|
---|
596 | }
|
---|
597 | }
|
---|
598 | function tryUnsubscribeSelf() {
|
---|
599 | if (selfSubscribed) {
|
---|
600 | selfSubscribed = false;
|
---|
601 | tryUnsubscribe();
|
---|
602 | }
|
---|
603 | }
|
---|
604 | const subscription = {
|
---|
605 | addNestedSub,
|
---|
606 | notifyNestedSubs,
|
---|
607 | handleChangeWrapper,
|
---|
608 | isSubscribed,
|
---|
609 | trySubscribe: trySubscribeSelf,
|
---|
610 | tryUnsubscribe: tryUnsubscribeSelf,
|
---|
611 | getListeners: () => listeners
|
---|
612 | };
|
---|
613 | return subscription;
|
---|
614 | }
|
---|
615 |
|
---|
616 | // src/utils/useIsomorphicLayoutEffect.ts
|
---|
617 | var canUseDOM = !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
|
---|
618 | var useIsomorphicLayoutEffect = canUseDOM ? React.useLayoutEffect : React.useEffect;
|
---|
619 |
|
---|
620 | // src/utils/shallowEqual.ts
|
---|
621 | function is(x, y) {
|
---|
622 | if (x === y) {
|
---|
623 | return x !== 0 || y !== 0 || 1 / x === 1 / y;
|
---|
624 | } else {
|
---|
625 | return x !== x && y !== y;
|
---|
626 | }
|
---|
627 | }
|
---|
628 | function shallowEqual(objA, objB) {
|
---|
629 | if (is(objA, objB))
|
---|
630 | return true;
|
---|
631 | if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) {
|
---|
632 | return false;
|
---|
633 | }
|
---|
634 | const keysA = Object.keys(objA);
|
---|
635 | const keysB = Object.keys(objB);
|
---|
636 | if (keysA.length !== keysB.length)
|
---|
637 | return false;
|
---|
638 | for (let i = 0; i < keysA.length; i++) {
|
---|
639 | if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
|
---|
640 | return false;
|
---|
641 | }
|
---|
642 | }
|
---|
643 | return true;
|
---|
644 | }
|
---|
645 |
|
---|
646 | // src/utils/hoistStatics.ts
|
---|
647 | var REACT_STATICS = {
|
---|
648 | childContextTypes: true,
|
---|
649 | contextType: true,
|
---|
650 | contextTypes: true,
|
---|
651 | defaultProps: true,
|
---|
652 | displayName: true,
|
---|
653 | getDefaultProps: true,
|
---|
654 | getDerivedStateFromError: true,
|
---|
655 | getDerivedStateFromProps: true,
|
---|
656 | mixins: true,
|
---|
657 | propTypes: true,
|
---|
658 | type: true
|
---|
659 | };
|
---|
660 | var KNOWN_STATICS = {
|
---|
661 | name: true,
|
---|
662 | length: true,
|
---|
663 | prototype: true,
|
---|
664 | caller: true,
|
---|
665 | callee: true,
|
---|
666 | arguments: true,
|
---|
667 | arity: true
|
---|
668 | };
|
---|
669 | var FORWARD_REF_STATICS = {
|
---|
670 | $$typeof: true,
|
---|
671 | render: true,
|
---|
672 | defaultProps: true,
|
---|
673 | displayName: true,
|
---|
674 | propTypes: true
|
---|
675 | };
|
---|
676 | var MEMO_STATICS = {
|
---|
677 | $$typeof: true,
|
---|
678 | compare: true,
|
---|
679 | defaultProps: true,
|
---|
680 | displayName: true,
|
---|
681 | propTypes: true,
|
---|
682 | type: true
|
---|
683 | };
|
---|
684 | var TYPE_STATICS = {
|
---|
685 | [ForwardRef]: FORWARD_REF_STATICS,
|
---|
686 | [Memo]: MEMO_STATICS
|
---|
687 | };
|
---|
688 | function getStatics(component) {
|
---|
689 | if (isMemo(component)) {
|
---|
690 | return MEMO_STATICS;
|
---|
691 | }
|
---|
692 | return TYPE_STATICS[component["$$typeof"]] || REACT_STATICS;
|
---|
693 | }
|
---|
694 | var defineProperty = Object.defineProperty;
|
---|
695 | var getOwnPropertyNames = Object.getOwnPropertyNames;
|
---|
696 | var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
---|
697 | var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
---|
698 | var getPrototypeOf = Object.getPrototypeOf;
|
---|
699 | var objectPrototype = Object.prototype;
|
---|
700 | function hoistNonReactStatics(targetComponent, sourceComponent) {
|
---|
701 | if (typeof sourceComponent !== "string") {
|
---|
702 | if (objectPrototype) {
|
---|
703 | const inheritedComponent = getPrototypeOf(sourceComponent);
|
---|
704 | if (inheritedComponent && inheritedComponent !== objectPrototype) {
|
---|
705 | hoistNonReactStatics(targetComponent, inheritedComponent);
|
---|
706 | }
|
---|
707 | }
|
---|
708 | let keys = getOwnPropertyNames(sourceComponent);
|
---|
709 | if (getOwnPropertySymbols) {
|
---|
710 | keys = keys.concat(getOwnPropertySymbols(sourceComponent));
|
---|
711 | }
|
---|
712 | const targetStatics = getStatics(targetComponent);
|
---|
713 | const sourceStatics = getStatics(sourceComponent);
|
---|
714 | for (let i = 0; i < keys.length; ++i) {
|
---|
715 | const key = keys[i];
|
---|
716 | if (!KNOWN_STATICS[key] && !(sourceStatics && sourceStatics[key]) && !(targetStatics && targetStatics[key])) {
|
---|
717 | const descriptor = getOwnPropertyDescriptor(sourceComponent, key);
|
---|
718 | try {
|
---|
719 | defineProperty(targetComponent, key, descriptor);
|
---|
720 | } catch (e) {
|
---|
721 | }
|
---|
722 | }
|
---|
723 | }
|
---|
724 | }
|
---|
725 | return targetComponent;
|
---|
726 | }
|
---|
727 |
|
---|
728 | // src/components/connect.tsx
|
---|
729 | var useSyncExternalStore = notInitialized;
|
---|
730 | var initializeConnect = (fn) => {
|
---|
731 | useSyncExternalStore = fn;
|
---|
732 | };
|
---|
733 | var NO_SUBSCRIPTION_ARRAY = [null, null];
|
---|
734 | var stringifyComponent = (Comp) => {
|
---|
735 | try {
|
---|
736 | return JSON.stringify(Comp);
|
---|
737 | } catch (err) {
|
---|
738 | return String(Comp);
|
---|
739 | }
|
---|
740 | };
|
---|
741 | function useIsomorphicLayoutEffectWithArgs(effectFunc, effectArgs, dependencies) {
|
---|
742 | useIsomorphicLayoutEffect(() => effectFunc(...effectArgs), dependencies);
|
---|
743 | }
|
---|
744 | function captureWrapperProps(lastWrapperProps, lastChildProps, renderIsScheduled, wrapperProps, childPropsFromStoreUpdate, notifyNestedSubs) {
|
---|
745 | lastWrapperProps.current = wrapperProps;
|
---|
746 | renderIsScheduled.current = false;
|
---|
747 | if (childPropsFromStoreUpdate.current) {
|
---|
748 | childPropsFromStoreUpdate.current = null;
|
---|
749 | notifyNestedSubs();
|
---|
750 | }
|
---|
751 | }
|
---|
752 | function subscribeUpdates(shouldHandleStateChanges, store, subscription, childPropsSelector, lastWrapperProps, lastChildProps, renderIsScheduled, isMounted, childPropsFromStoreUpdate, notifyNestedSubs, additionalSubscribeListener) {
|
---|
753 | if (!shouldHandleStateChanges)
|
---|
754 | return () => {
|
---|
755 | };
|
---|
756 | let didUnsubscribe = false;
|
---|
757 | let lastThrownError = null;
|
---|
758 | const checkForUpdates = () => {
|
---|
759 | if (didUnsubscribe || !isMounted.current) {
|
---|
760 | return;
|
---|
761 | }
|
---|
762 | const latestStoreState = store.getState();
|
---|
763 | let newChildProps, error;
|
---|
764 | try {
|
---|
765 | newChildProps = childPropsSelector(
|
---|
766 | latestStoreState,
|
---|
767 | lastWrapperProps.current
|
---|
768 | );
|
---|
769 | } catch (e) {
|
---|
770 | error = e;
|
---|
771 | lastThrownError = e;
|
---|
772 | }
|
---|
773 | if (!error) {
|
---|
774 | lastThrownError = null;
|
---|
775 | }
|
---|
776 | if (newChildProps === lastChildProps.current) {
|
---|
777 | if (!renderIsScheduled.current) {
|
---|
778 | notifyNestedSubs();
|
---|
779 | }
|
---|
780 | } else {
|
---|
781 | lastChildProps.current = newChildProps;
|
---|
782 | childPropsFromStoreUpdate.current = newChildProps;
|
---|
783 | renderIsScheduled.current = true;
|
---|
784 | additionalSubscribeListener();
|
---|
785 | }
|
---|
786 | };
|
---|
787 | subscription.onStateChange = checkForUpdates;
|
---|
788 | subscription.trySubscribe();
|
---|
789 | checkForUpdates();
|
---|
790 | const unsubscribeWrapper = () => {
|
---|
791 | didUnsubscribe = true;
|
---|
792 | subscription.tryUnsubscribe();
|
---|
793 | subscription.onStateChange = null;
|
---|
794 | if (lastThrownError) {
|
---|
795 | throw lastThrownError;
|
---|
796 | }
|
---|
797 | };
|
---|
798 | return unsubscribeWrapper;
|
---|
799 | }
|
---|
800 | function strictEqual(a, b) {
|
---|
801 | return a === b;
|
---|
802 | }
|
---|
803 | var hasWarnedAboutDeprecatedPureOption = false;
|
---|
804 | function connect(mapStateToProps, mapDispatchToProps, mergeProps, {
|
---|
805 | // The `pure` option has been removed, so TS doesn't like us destructuring this to check its existence.
|
---|
806 | // @ts-ignore
|
---|
807 | pure,
|
---|
808 | areStatesEqual = strictEqual,
|
---|
809 | areOwnPropsEqual = shallowEqual,
|
---|
810 | areStatePropsEqual = shallowEqual,
|
---|
811 | areMergedPropsEqual = shallowEqual,
|
---|
812 | // use React's forwardRef to expose a ref of the wrapped component
|
---|
813 | forwardRef = false,
|
---|
814 | // the context consumer to use
|
---|
815 | context = ReactReduxContext
|
---|
816 | } = {}) {
|
---|
817 | if (process.env.NODE_ENV !== "production") {
|
---|
818 | if (pure !== void 0 && !hasWarnedAboutDeprecatedPureOption) {
|
---|
819 | hasWarnedAboutDeprecatedPureOption = true;
|
---|
820 | warning(
|
---|
821 | 'The `pure` option has been removed. `connect` is now always a "pure/memoized" component'
|
---|
822 | );
|
---|
823 | }
|
---|
824 | }
|
---|
825 | const Context = context;
|
---|
826 | const initMapStateToProps = mapStateToPropsFactory(mapStateToProps);
|
---|
827 | const initMapDispatchToProps = mapDispatchToPropsFactory(mapDispatchToProps);
|
---|
828 | const initMergeProps = mergePropsFactory(mergeProps);
|
---|
829 | const shouldHandleStateChanges = Boolean(mapStateToProps);
|
---|
830 | const wrapWithConnect = (WrappedComponent) => {
|
---|
831 | if (process.env.NODE_ENV !== "production") {
|
---|
832 | const isValid = /* @__PURE__ */ isValidElementType(WrappedComponent);
|
---|
833 | if (!isValid)
|
---|
834 | throw new Error(
|
---|
835 | `You must pass a component to the function returned by connect. Instead received ${stringifyComponent(
|
---|
836 | WrappedComponent
|
---|
837 | )}`
|
---|
838 | );
|
---|
839 | }
|
---|
840 | const wrappedComponentName = WrappedComponent.displayName || WrappedComponent.name || "Component";
|
---|
841 | const displayName = `Connect(${wrappedComponentName})`;
|
---|
842 | const selectorFactoryOptions = {
|
---|
843 | shouldHandleStateChanges,
|
---|
844 | displayName,
|
---|
845 | wrappedComponentName,
|
---|
846 | WrappedComponent,
|
---|
847 | // @ts-ignore
|
---|
848 | initMapStateToProps,
|
---|
849 | // @ts-ignore
|
---|
850 | initMapDispatchToProps,
|
---|
851 | initMergeProps,
|
---|
852 | areStatesEqual,
|
---|
853 | areStatePropsEqual,
|
---|
854 | areOwnPropsEqual,
|
---|
855 | areMergedPropsEqual
|
---|
856 | };
|
---|
857 | function ConnectFunction(props) {
|
---|
858 | const [propsContext, reactReduxForwardedRef, wrapperProps] = React.useMemo(() => {
|
---|
859 | const { reactReduxForwardedRef: reactReduxForwardedRef2, ...wrapperProps2 } = props;
|
---|
860 | return [props.context, reactReduxForwardedRef2, wrapperProps2];
|
---|
861 | }, [props]);
|
---|
862 | const ContextToUse = React.useMemo(() => {
|
---|
863 | let ResultContext = Context;
|
---|
864 | if (propsContext?.Consumer) {
|
---|
865 | if (process.env.NODE_ENV !== "production") {
|
---|
866 | const isValid = /* @__PURE__ */ isContextConsumer(
|
---|
867 | // @ts-ignore
|
---|
868 | /* @__PURE__ */ React.createElement(propsContext.Consumer, null)
|
---|
869 | );
|
---|
870 | if (!isValid) {
|
---|
871 | throw new Error(
|
---|
872 | "You must pass a valid React context consumer as `props.context`"
|
---|
873 | );
|
---|
874 | }
|
---|
875 | ResultContext = propsContext;
|
---|
876 | }
|
---|
877 | }
|
---|
878 | return ResultContext;
|
---|
879 | }, [propsContext, Context]);
|
---|
880 | const contextValue = React.useContext(ContextToUse);
|
---|
881 | const didStoreComeFromProps = Boolean(props.store) && Boolean(props.store.getState) && Boolean(props.store.dispatch);
|
---|
882 | const didStoreComeFromContext = Boolean(contextValue) && Boolean(contextValue.store);
|
---|
883 | if (process.env.NODE_ENV !== "production" && !didStoreComeFromProps && !didStoreComeFromContext) {
|
---|
884 | throw new Error(
|
---|
885 | `Could not find "store" in the context of "${displayName}". Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to ${displayName} in connect options.`
|
---|
886 | );
|
---|
887 | }
|
---|
888 | const store = didStoreComeFromProps ? props.store : contextValue.store;
|
---|
889 | const getServerState = didStoreComeFromContext ? contextValue.getServerState : store.getState;
|
---|
890 | const childPropsSelector = React.useMemo(() => {
|
---|
891 | return finalPropsSelectorFactory(store.dispatch, selectorFactoryOptions);
|
---|
892 | }, [store]);
|
---|
893 | const [subscription, notifyNestedSubs] = React.useMemo(() => {
|
---|
894 | if (!shouldHandleStateChanges)
|
---|
895 | return NO_SUBSCRIPTION_ARRAY;
|
---|
896 | const subscription2 = createSubscription(
|
---|
897 | store,
|
---|
898 | didStoreComeFromProps ? void 0 : contextValue.subscription
|
---|
899 | );
|
---|
900 | const notifyNestedSubs2 = subscription2.notifyNestedSubs.bind(subscription2);
|
---|
901 | return [subscription2, notifyNestedSubs2];
|
---|
902 | }, [store, didStoreComeFromProps, contextValue]);
|
---|
903 | const overriddenContextValue = React.useMemo(() => {
|
---|
904 | if (didStoreComeFromProps) {
|
---|
905 | return contextValue;
|
---|
906 | }
|
---|
907 | return {
|
---|
908 | ...contextValue,
|
---|
909 | subscription
|
---|
910 | };
|
---|
911 | }, [didStoreComeFromProps, contextValue, subscription]);
|
---|
912 | const lastChildProps = React.useRef();
|
---|
913 | const lastWrapperProps = React.useRef(wrapperProps);
|
---|
914 | const childPropsFromStoreUpdate = React.useRef();
|
---|
915 | const renderIsScheduled = React.useRef(false);
|
---|
916 | const isProcessingDispatch = React.useRef(false);
|
---|
917 | const isMounted = React.useRef(false);
|
---|
918 | const latestSubscriptionCallbackError = React.useRef();
|
---|
919 | useIsomorphicLayoutEffect(() => {
|
---|
920 | isMounted.current = true;
|
---|
921 | return () => {
|
---|
922 | isMounted.current = false;
|
---|
923 | };
|
---|
924 | }, []);
|
---|
925 | const actualChildPropsSelector = React.useMemo(() => {
|
---|
926 | const selector = () => {
|
---|
927 | if (childPropsFromStoreUpdate.current && wrapperProps === lastWrapperProps.current) {
|
---|
928 | return childPropsFromStoreUpdate.current;
|
---|
929 | }
|
---|
930 | return childPropsSelector(store.getState(), wrapperProps);
|
---|
931 | };
|
---|
932 | return selector;
|
---|
933 | }, [store, wrapperProps]);
|
---|
934 | const subscribeForReact = React.useMemo(() => {
|
---|
935 | const subscribe = (reactListener) => {
|
---|
936 | if (!subscription) {
|
---|
937 | return () => {
|
---|
938 | };
|
---|
939 | }
|
---|
940 | return subscribeUpdates(
|
---|
941 | shouldHandleStateChanges,
|
---|
942 | store,
|
---|
943 | subscription,
|
---|
944 | // @ts-ignore
|
---|
945 | childPropsSelector,
|
---|
946 | lastWrapperProps,
|
---|
947 | lastChildProps,
|
---|
948 | renderIsScheduled,
|
---|
949 | isMounted,
|
---|
950 | childPropsFromStoreUpdate,
|
---|
951 | notifyNestedSubs,
|
---|
952 | reactListener
|
---|
953 | );
|
---|
954 | };
|
---|
955 | return subscribe;
|
---|
956 | }, [subscription]);
|
---|
957 | useIsomorphicLayoutEffectWithArgs(captureWrapperProps, [
|
---|
958 | lastWrapperProps,
|
---|
959 | lastChildProps,
|
---|
960 | renderIsScheduled,
|
---|
961 | wrapperProps,
|
---|
962 | childPropsFromStoreUpdate,
|
---|
963 | notifyNestedSubs
|
---|
964 | ]);
|
---|
965 | let actualChildProps;
|
---|
966 | try {
|
---|
967 | actualChildProps = useSyncExternalStore(
|
---|
968 | // TODO We're passing through a big wrapper that does a bunch of extra side effects besides subscribing
|
---|
969 | subscribeForReact,
|
---|
970 | // TODO This is incredibly hacky. We've already processed the store update and calculated new child props,
|
---|
971 | // TODO and we're just passing that through so it triggers a re-render for us rather than relying on `uSES`.
|
---|
972 | actualChildPropsSelector,
|
---|
973 | getServerState ? () => childPropsSelector(getServerState(), wrapperProps) : actualChildPropsSelector
|
---|
974 | );
|
---|
975 | } catch (err) {
|
---|
976 | if (latestSubscriptionCallbackError.current) {
|
---|
977 | ;
|
---|
978 | err.message += `
|
---|
979 | The error may be correlated with this previous error:
|
---|
980 | ${latestSubscriptionCallbackError.current.stack}
|
---|
981 |
|
---|
982 | `;
|
---|
983 | }
|
---|
984 | throw err;
|
---|
985 | }
|
---|
986 | useIsomorphicLayoutEffect(() => {
|
---|
987 | latestSubscriptionCallbackError.current = void 0;
|
---|
988 | childPropsFromStoreUpdate.current = void 0;
|
---|
989 | lastChildProps.current = actualChildProps;
|
---|
990 | });
|
---|
991 | const renderedWrappedComponent = React.useMemo(() => {
|
---|
992 | return (
|
---|
993 | // @ts-ignore
|
---|
994 | /* @__PURE__ */ React.createElement(
|
---|
995 | WrappedComponent,
|
---|
996 | {
|
---|
997 | ...actualChildProps,
|
---|
998 | ref: reactReduxForwardedRef
|
---|
999 | }
|
---|
1000 | )
|
---|
1001 | );
|
---|
1002 | }, [reactReduxForwardedRef, WrappedComponent, actualChildProps]);
|
---|
1003 | const renderedChild = React.useMemo(() => {
|
---|
1004 | if (shouldHandleStateChanges) {
|
---|
1005 | return /* @__PURE__ */ React.createElement(ContextToUse.Provider, { value: overriddenContextValue }, renderedWrappedComponent);
|
---|
1006 | }
|
---|
1007 | return renderedWrappedComponent;
|
---|
1008 | }, [ContextToUse, renderedWrappedComponent, overriddenContextValue]);
|
---|
1009 | return renderedChild;
|
---|
1010 | }
|
---|
1011 | const _Connect = React.memo(ConnectFunction);
|
---|
1012 | const Connect = _Connect;
|
---|
1013 | Connect.WrappedComponent = WrappedComponent;
|
---|
1014 | Connect.displayName = ConnectFunction.displayName = displayName;
|
---|
1015 | if (forwardRef) {
|
---|
1016 | const _forwarded = React.forwardRef(function forwardConnectRef(props, ref) {
|
---|
1017 | return /* @__PURE__ */ React.createElement(Connect, { ...props, reactReduxForwardedRef: ref });
|
---|
1018 | });
|
---|
1019 | const forwarded = _forwarded;
|
---|
1020 | forwarded.displayName = displayName;
|
---|
1021 | forwarded.WrappedComponent = WrappedComponent;
|
---|
1022 | return /* @__PURE__ */ hoistNonReactStatics(forwarded, WrappedComponent);
|
---|
1023 | }
|
---|
1024 | return /* @__PURE__ */ hoistNonReactStatics(Connect, WrappedComponent);
|
---|
1025 | };
|
---|
1026 | return wrapWithConnect;
|
---|
1027 | }
|
---|
1028 | var connect_default = connect;
|
---|
1029 |
|
---|
1030 | // src/components/Provider.tsx
|
---|
1031 | function Provider({
|
---|
1032 | store,
|
---|
1033 | context,
|
---|
1034 | children,
|
---|
1035 | serverState,
|
---|
1036 | stabilityCheck = "once",
|
---|
1037 | identityFunctionCheck = "once"
|
---|
1038 | }) {
|
---|
1039 | const contextValue = React.useMemo(() => {
|
---|
1040 | const subscription = createSubscription(store);
|
---|
1041 | return {
|
---|
1042 | store,
|
---|
1043 | subscription,
|
---|
1044 | getServerState: serverState ? () => serverState : void 0,
|
---|
1045 | stabilityCheck,
|
---|
1046 | identityFunctionCheck
|
---|
1047 | };
|
---|
1048 | }, [store, serverState, stabilityCheck, identityFunctionCheck]);
|
---|
1049 | const previousState = React.useMemo(() => store.getState(), [store]);
|
---|
1050 | useIsomorphicLayoutEffect(() => {
|
---|
1051 | const { subscription } = contextValue;
|
---|
1052 | subscription.onStateChange = subscription.notifyNestedSubs;
|
---|
1053 | subscription.trySubscribe();
|
---|
1054 | if (previousState !== store.getState()) {
|
---|
1055 | subscription.notifyNestedSubs();
|
---|
1056 | }
|
---|
1057 | return () => {
|
---|
1058 | subscription.tryUnsubscribe();
|
---|
1059 | subscription.onStateChange = void 0;
|
---|
1060 | };
|
---|
1061 | }, [contextValue, previousState]);
|
---|
1062 | const Context = context || ReactReduxContext;
|
---|
1063 | return /* @__PURE__ */ React.createElement(Context.Provider, { value: contextValue }, children);
|
---|
1064 | }
|
---|
1065 | var Provider_default = Provider;
|
---|
1066 |
|
---|
1067 | // src/hooks/useStore.ts
|
---|
1068 | function createStoreHook(context = ReactReduxContext) {
|
---|
1069 | const useReduxContext2 = context === ReactReduxContext ? useReduxContext : (
|
---|
1070 | // @ts-ignore
|
---|
1071 | createReduxContextHook(context)
|
---|
1072 | );
|
---|
1073 | const useStore2 = () => {
|
---|
1074 | const { store } = useReduxContext2();
|
---|
1075 | return store;
|
---|
1076 | };
|
---|
1077 | Object.assign(useStore2, {
|
---|
1078 | withTypes: () => useStore2
|
---|
1079 | });
|
---|
1080 | return useStore2;
|
---|
1081 | }
|
---|
1082 | var useStore = /* @__PURE__ */ createStoreHook();
|
---|
1083 |
|
---|
1084 | // src/hooks/useDispatch.ts
|
---|
1085 | function createDispatchHook(context = ReactReduxContext) {
|
---|
1086 | const useStore2 = context === ReactReduxContext ? useStore : createStoreHook(context);
|
---|
1087 | const useDispatch2 = () => {
|
---|
1088 | const store = useStore2();
|
---|
1089 | return store.dispatch;
|
---|
1090 | };
|
---|
1091 | Object.assign(useDispatch2, {
|
---|
1092 | withTypes: () => useDispatch2
|
---|
1093 | });
|
---|
1094 | return useDispatch2;
|
---|
1095 | }
|
---|
1096 | var useDispatch = /* @__PURE__ */ createDispatchHook();
|
---|
1097 |
|
---|
1098 | // src/exports.ts
|
---|
1099 | var batch = defaultNoopBatch;
|
---|
1100 |
|
---|
1101 | // src/index.ts
|
---|
1102 | initializeUseSelector(useSyncExternalStoreWithSelector2);
|
---|
1103 | initializeConnect(React2.useSyncExternalStore);
|
---|
1104 | export {
|
---|
1105 | Provider_default as Provider,
|
---|
1106 | ReactReduxContext,
|
---|
1107 | batch,
|
---|
1108 | connect_default as connect,
|
---|
1109 | createDispatchHook,
|
---|
1110 | createSelectorHook,
|
---|
1111 | createStoreHook,
|
---|
1112 | shallowEqual,
|
---|
1113 | useDispatch,
|
---|
1114 | useSelector,
|
---|
1115 | useStore
|
---|
1116 | };
|
---|
1117 | //# sourceMappingURL=react-redux.mjs.map |
---|