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