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