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