react-saga-redux 1.0.1

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