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
@@ -0,0 +1,105 @@
1
+ import type { Context, ReactNode } from 'react'
2
+ import { React } from '../utils/react'
3
+ import type { Action, Store, UnknownAction } from 'redux'
4
+ import type { DevModeCheckFrequency } from '../hooks/useSelector'
5
+ import { createSubscription } from '../utils/Subscription'
6
+ import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect'
7
+ import type { ReactReduxContextValue } from './Context'
8
+ import { ReactReduxContext } from './Context'
9
+
10
+ export interface ProviderProps<
11
+ A extends Action<string> = UnknownAction,
12
+ S = unknown,
13
+ > {
14
+ /**
15
+ * The single Redux store in your application.
16
+ */
17
+ store: Store<S, A>
18
+
19
+ /**
20
+ * An optional server state snapshot. Will be used during initial hydration render if available, to ensure that the UI output is consistent with the HTML generated on the server.
21
+ */
22
+ serverState?: S
23
+
24
+ /**
25
+ * Optional context to be used internally in react-redux. Use React.createContext() to create a context to be used.
26
+ * If this is used, you'll need to customize `connect` by supplying the same context provided to the Provider.
27
+ * Set the initial value to null, and the hooks will error
28
+ * if this is not overwritten by Provider.
29
+ */
30
+ context?: Context<ReactReduxContextValue<S, A> | null>
31
+
32
+ /**
33
+ * Determines the frequency of stability checks for all selectors.
34
+ * This setting overrides the global configuration for
35
+ * the `useSelector` stability check, allowing you to specify how often
36
+ * these checks should occur in development mode.
37
+ *
38
+ * @since 8.1.0
39
+ */
40
+ stabilityCheck?: DevModeCheckFrequency
41
+
42
+ /**
43
+ * Determines the frequency of identity function checks for all selectors.
44
+ * This setting overrides the global configuration for
45
+ * the `useSelector` identity function check, allowing you to specify how often
46
+ * these checks should occur in development mode.
47
+ *
48
+ * **Note**: Previously referred to as `noopCheck`.
49
+ *
50
+ * @since 9.0.0
51
+ */
52
+ identityFunctionCheck?: DevModeCheckFrequency
53
+
54
+ children: ReactNode
55
+ }
56
+
57
+ function Provider<A extends Action<string> = UnknownAction, S = unknown>(
58
+ providerProps: ProviderProps<A, S>,
59
+ ) {
60
+ const { children, context, serverState, store } = providerProps
61
+
62
+ const contextValue = React.useMemo(() => {
63
+ const subscription = createSubscription(store)
64
+
65
+ const baseContextValue = {
66
+ store,
67
+ subscription,
68
+ getServerState: serverState ? () => serverState : undefined,
69
+ }
70
+
71
+ if (process.env.NODE_ENV === 'production') {
72
+ return baseContextValue
73
+ } else {
74
+ const { identityFunctionCheck = 'once', stabilityCheck = 'once' } =
75
+ providerProps
76
+
77
+ return /* @__PURE__ */ Object.assign(baseContextValue, {
78
+ stabilityCheck,
79
+ identityFunctionCheck,
80
+ })
81
+ }
82
+ }, [store, serverState])
83
+
84
+ const previousState = React.useMemo(() => store.getState(), [store])
85
+
86
+ useIsomorphicLayoutEffect(() => {
87
+ const { subscription } = contextValue
88
+ subscription.onStateChange = subscription.notifyNestedSubs
89
+ subscription.trySubscribe()
90
+
91
+ if (previousState !== store.getState()) {
92
+ subscription.notifyNestedSubs()
93
+ }
94
+ return () => {
95
+ subscription.tryUnsubscribe()
96
+ subscription.onStateChange = undefined
97
+ }
98
+ }, [contextValue, previousState])
99
+
100
+ const Context = context || ReactReduxContext
101
+
102
+ return <Context.Provider value={contextValue}>{children}</Context.Provider>
103
+ }
104
+
105
+ export default Provider