Viewing File: /home/ubuntu/route-and-root-frontend-base/node_modules/zustand/system/middleware.development.js

System.register([], (function (exports) {
  'use strict';
  return {
    execute: (function () {

      const reduxImpl = (reducer, initial) => (set, _get, api) => {
        api.dispatch = (action) => {
          set((state) => reducer(state, action), false, action);
          return action;
        };
        api.dispatchFromDevtools = true;
        return { dispatch: (...a) => api.dispatch(...a), ...initial };
      };
      const redux = exports('redux', reduxImpl);

      const devtoolsImpl = (fn, devtoolsOptions = {}) => (set, get, api) => {
        const { enabled, anonymousActionType, ...options } = devtoolsOptions;
        let extensionConnector;
        try {
          extensionConnector = (enabled != null ? enabled : true) && window.__REDUX_DEVTOOLS_EXTENSION__;
        } catch {
        }
        if (!extensionConnector) {
          if (enabled) {
            console.warn(
              "[zustand devtools middleware] Please install/enable Redux devtools extension"
            );
          }
          return fn(set, get, api);
        }
        const extension = extensionConnector.connect(options);
        let isRecording = true;
        api.setState = (state, replace, nameOrAction) => {
          const r = set(state, replace);
          if (!isRecording)
            return r;
          extension.send(
            nameOrAction === void 0 ? { type: anonymousActionType || "anonymous" } : typeof nameOrAction === "string" ? { type: nameOrAction } : nameOrAction,
            get()
          );
          return r;
        };
        const setStateFromDevtools = (...a) => {
          const originalIsRecording = isRecording;
          isRecording = false;
          set(...a);
          isRecording = originalIsRecording;
        };
        const initialState = fn(api.setState, get, api);
        extension.init(initialState);
        if (api.dispatchFromDevtools && typeof api.dispatch === "function") {
          let didWarnAboutReservedActionType = false;
          const originalDispatch = api.dispatch;
          api.dispatch = (...a) => {
            if (a[0].type === "__setState" && !didWarnAboutReservedActionType) {
              console.warn(
                '[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'
              );
              didWarnAboutReservedActionType = true;
            }
            originalDispatch(...a);
          };
        }
        extension.subscribe((message) => {
          var _a;
          switch (message.type) {
            case "ACTION":
              if (typeof message.payload !== "string") {
                console.error(
                  "[zustand devtools middleware] Unsupported action format"
                );
                return;
              }
              return parseJsonThen(
                message.payload,
                (action) => {
                  if (action.type === "__setState") {
                    setStateFromDevtools(action.state);
                    return;
                  }
                  if (!api.dispatchFromDevtools)
                    return;
                  if (typeof api.dispatch !== "function")
                    return;
                  api.dispatch(action);
                }
              );
            case "DISPATCH":
              switch (message.payload.type) {
                case "RESET":
                  setStateFromDevtools(initialState);
                  return extension.init(api.getState());
                case "COMMIT":
                  return extension.init(api.getState());
                case "ROLLBACK":
                  return parseJsonThen(message.state, (state) => {
                    setStateFromDevtools(state);
                    extension.init(api.getState());
                  });
                case "JUMP_TO_STATE":
                case "JUMP_TO_ACTION":
                  return parseJsonThen(message.state, (state) => {
                    setStateFromDevtools(state);
                  });
                case "IMPORT_STATE": {
                  const { nextLiftedState } = message.payload;
                  const lastComputedState = (_a = nextLiftedState.computedStates.slice(-1)[0]) == null ? void 0 : _a.state;
                  if (!lastComputedState)
                    return;
                  setStateFromDevtools(lastComputedState);
                  extension.send(
                    null,
                    nextLiftedState
                  );
                  return;
                }
                case "PAUSE_RECORDING":
                  return isRecording = !isRecording;
              }
              return;
          }
        });
        return initialState;
      };
      const devtools = exports('devtools', devtoolsImpl);
      const parseJsonThen = (stringified, f) => {
        let parsed;
        try {
          parsed = JSON.parse(stringified);
        } catch (e) {
          console.error(
            "[zustand devtools middleware] Could not parse the received json",
            e
          );
        }
        if (parsed !== void 0)
          f(parsed);
      };

      const subscribeWithSelectorImpl = (fn) => (set, get, api) => {
        const origSubscribe = api.subscribe;
        api.subscribe = (selector, optListener, options) => {
          let listener = selector;
          if (optListener) {
            const equalityFn = (options == null ? void 0 : options.equalityFn) || Object.is;
            let currentSlice = selector(api.getState());
            listener = (state) => {
              const nextSlice = selector(state);
              if (!equalityFn(currentSlice, nextSlice)) {
                const previousSlice = currentSlice;
                optListener(currentSlice = nextSlice, previousSlice);
              }
            };
            if (options == null ? void 0 : options.fireImmediately) {
              optListener(currentSlice, currentSlice);
            }
          }
          return origSubscribe(listener);
        };
        const initialState = fn(set, get, api);
        return initialState;
      };
      const subscribeWithSelector = exports('subscribeWithSelector', subscribeWithSelectorImpl);

      const combine = exports('combine', (initialState, create) => (...a) => Object.assign({}, initialState, create(...a)));

      const toThenable = (fn) => (input) => {
        try {
          const result = fn(input);
          if (result instanceof Promise) {
            return result;
          }
          return {
            then(onFulfilled) {
              return toThenable(onFulfilled)(result);
            },
            catch(_onRejected) {
              return this;
            }
          };
        } catch (e) {
          return {
            then(_onFulfilled) {
              return this;
            },
            catch(onRejected) {
              return toThenable(onRejected)(e);
            }
          };
        }
      };
      const persistImpl = (config, baseOptions) => (set, get, api) => {
        let options = {
          getStorage: () => localStorage,
          serialize: JSON.stringify,
          deserialize: JSON.parse,
          partialize: (state) => state,
          version: 0,
          merge: (persistedState, currentState) => ({
            ...currentState,
            ...persistedState
          }),
          ...baseOptions
        };
        let hasHydrated = false;
        const hydrationListeners = /* @__PURE__ */ new Set();
        const finishHydrationListeners = /* @__PURE__ */ new Set();
        let storage;
        try {
          storage = options.getStorage();
        } catch (e) {
        }
        if (!storage) {
          return config(
            (...args) => {
              console.warn(
                `[zustand persist middleware] Unable to update item '${options.name}', the given storage is currently unavailable.`
              );
              set(...args);
            },
            get,
            api
          );
        }
        const thenableSerialize = toThenable(options.serialize);
        const setItem = () => {
          const state = options.partialize({ ...get() });
          let errorInSync;
          const thenable = thenableSerialize({ state, version: options.version }).then(
            (serializedValue) => storage.setItem(options.name, serializedValue)
          ).catch((e) => {
            errorInSync = e;
          });
          if (errorInSync) {
            throw errorInSync;
          }
          return thenable;
        };
        const savedSetState = api.setState;
        api.setState = (state, replace) => {
          savedSetState(state, replace);
          void setItem();
        };
        const configResult = config(
          (...args) => {
            set(...args);
            void setItem();
          },
          get,
          api
        );
        let stateFromStorage;
        const hydrate = () => {
          var _a;
          if (!storage)
            return;
          hasHydrated = false;
          hydrationListeners.forEach((cb) => cb(get()));
          const postRehydrationCallback = ((_a = options.onRehydrateStorage) == null ? void 0 : _a.call(options, get())) || void 0;
          return toThenable(storage.getItem.bind(storage))(options.name).then((storageValue) => {
            if (storageValue) {
              return options.deserialize(storageValue);
            }
          }).then((deserializedStorageValue) => {
            if (deserializedStorageValue) {
              if (typeof deserializedStorageValue.version === "number" && deserializedStorageValue.version !== options.version) {
                if (options.migrate) {
                  return options.migrate(
                    deserializedStorageValue.state,
                    deserializedStorageValue.version
                  );
                }
                console.error(
                  `State loaded from storage couldn't be migrated since no migrate function was provided`
                );
              } else {
                return deserializedStorageValue.state;
              }
            }
          }).then((migratedState) => {
            var _a2;
            stateFromStorage = options.merge(
              migratedState,
              (_a2 = get()) != null ? _a2 : configResult
            );
            set(stateFromStorage, true);
            return setItem();
          }).then(() => {
            postRehydrationCallback == null ? void 0 : postRehydrationCallback(stateFromStorage, void 0);
            hasHydrated = true;
            finishHydrationListeners.forEach((cb) => cb(stateFromStorage));
          }).catch((e) => {
            postRehydrationCallback == null ? void 0 : postRehydrationCallback(void 0, e);
          });
        };
        api.persist = {
          setOptions: (newOptions) => {
            options = {
              ...options,
              ...newOptions
            };
            if (newOptions.getStorage) {
              storage = newOptions.getStorage();
            }
          },
          clearStorage: () => {
            storage == null ? void 0 : storage.removeItem(options.name);
          },
          getOptions: () => options,
          rehydrate: () => hydrate(),
          hasHydrated: () => hasHydrated,
          onHydrate: (cb) => {
            hydrationListeners.add(cb);
            return () => {
              hydrationListeners.delete(cb);
            };
          },
          onFinishHydration: (cb) => {
            finishHydrationListeners.add(cb);
            return () => {
              finishHydrationListeners.delete(cb);
            };
          }
        };
        hydrate();
        return stateFromStorage || configResult;
      };
      const persist = exports('persist', persistImpl);

    })
  };
}));
Back to Directory File Manager