@e1011/es-kit 1.1.48 → 1.1.50
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.
- package/dist/hooks/esm/index.css +159 -159
- package/dist/hooks/index.css +159 -159
- package/dist/lib/cjs/src/core/utils/appState/peregrineMQ/index.js.map +1 -1
- package/dist/lib/cjs/src/core/utils/appState/peregrineMQ/peregrineMQ.js +1 -1
- package/dist/lib/cjs/src/core/utils/appState/peregrineMQ/peregrineMQ.js.map +1 -1
- package/dist/lib/cjs/src/core/utils/appState/peregrineMQ/peregrineMQ.types.js +2 -0
- package/dist/lib/cjs/src/core/utils/appState/peregrineMQ/peregrineMQ.types.js.map +1 -0
- package/dist/lib/cjs/src/core/utils/appState/peregrineMQ/usePeregrineMQ.react.js.map +1 -1
- package/dist/lib/cjs/src/core/utils/appState/store/store.vanillajs.js.map +1 -1
- package/dist/lib/cjs/src/core/utils/appState/store/store.vanillajs.templates.js.map +1 -1
- package/dist/lib/cjs/src/index.js +1 -1
- package/dist/lib/esm/src/core/utils/appState/peregrineMQ/index.js.map +1 -1
- package/dist/lib/esm/src/core/utils/appState/peregrineMQ/peregrineMQ.js +1 -1
- package/dist/lib/esm/src/core/utils/appState/peregrineMQ/peregrineMQ.js.map +1 -1
- package/dist/lib/esm/src/core/utils/appState/peregrineMQ/peregrineMQ.types.js +2 -0
- package/dist/lib/esm/src/core/utils/appState/peregrineMQ/peregrineMQ.types.js.map +1 -0
- package/dist/lib/esm/src/core/utils/appState/peregrineMQ/usePeregrineMQ.react.js.map +1 -1
- package/dist/lib/esm/src/core/utils/appState/store/store.vanillajs.js.map +1 -1
- package/dist/lib/esm/src/core/utils/appState/store/store.vanillajs.templates.js.map +1 -1
- package/dist/lib/esm/src/index.js +1 -1
- package/dist/lib/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/core/utils/appState/peregrineMQ/index.d.ts +1 -1
- package/dist/types/src/core/utils/appState/peregrineMQ/index.d.ts.map +1 -1
- package/dist/types/src/core/utils/appState/peregrineMQ/peregrineMQ.d.ts +2 -2
- package/dist/types/src/core/utils/appState/peregrineMQ/peregrineMQ.d.ts.map +1 -1
- package/dist/types/src/core/utils/appState/peregrineMQ/peregrineMQ.types.d.ts +5 -1
- package/dist/types/src/core/utils/appState/peregrineMQ/peregrineMQ.types.d.ts.map +1 -1
- package/dist/types/src/core/utils/appState/peregrineMQ/usePeregrineMQ.react.d.ts +2 -2
- package/dist/types/src/core/utils/appState/peregrineMQ/usePeregrineMQ.react.d.ts.map +1 -1
- package/dist/types/src/core/utils/appState/store/store.vanillajs.d.ts.map +1 -1
- package/dist/types/src/ts-playground.d.ts +1 -0
- package/dist/types/src/ts-playground.d.ts.map +1 -0
- package/dist/utils/esm/index.css +159 -159
- package/dist/utils/esm/src/core/utils/appState/peregrineMQ/index.js.map +1 -1
- package/dist/utils/esm/src/core/utils/appState/peregrineMQ/peregrineMQ.js +1 -1
- package/dist/utils/esm/src/core/utils/appState/peregrineMQ/peregrineMQ.js.map +1 -1
- package/dist/utils/esm/src/core/utils/appState/peregrineMQ/peregrineMQ.types.js +2 -0
- package/dist/utils/esm/src/core/utils/appState/peregrineMQ/peregrineMQ.types.js.map +1 -0
- package/dist/utils/esm/src/core/utils/appState/peregrineMQ/usePeregrineMQ.react.js.map +1 -1
- package/dist/utils/esm/src/core/utils/appState/store/store.vanillajs.js.map +1 -1
- package/dist/utils/esm/src/core/utils/appState/store/store.vanillajs.templates.js.map +1 -1
- package/dist/utils/esm/src/core/utils/index.js +1 -1
- package/dist/utils/index.css +159 -159
- package/dist/utils/src/core/utils/appState/peregrineMQ/index.js.map +1 -1
- package/dist/utils/src/core/utils/appState/peregrineMQ/peregrineMQ.js +1 -1
- package/dist/utils/src/core/utils/appState/peregrineMQ/peregrineMQ.js.map +1 -1
- package/dist/utils/src/core/utils/appState/peregrineMQ/peregrineMQ.types.js +2 -0
- package/dist/utils/src/core/utils/appState/peregrineMQ/peregrineMQ.types.js.map +1 -0
- package/dist/utils/src/core/utils/appState/peregrineMQ/usePeregrineMQ.react.js.map +1 -1
- package/dist/utils/src/core/utils/appState/store/store.vanillajs.js.map +1 -1
- package/dist/utils/src/core/utils/appState/store/store.vanillajs.templates.js.map +1 -1
- package/dist/utils/src/core/utils/index.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.vanillajs.js","sources":["../../../../../../../src/core/utils/appState/store/store.vanillajs.ts"],"sourcesContent":["\n// TinyStore, inspired by https://github.com/jherr/syncexternalstore/blob/main/csr/src/store.js\n\nimport { isFunctionAsync } from '../../helpers'\n\n/**\n * Represents the callback function for a store listener.\n */\nexport type ListenerCallBack<T> = (state: Partial<T>) => void\n\n/**\n * Represents a selector function that transforms the store state.\n */\n// export type Selector<T> = (state: Partial<T>) => Partial<T>;\nexport type SelectedValueType<T> = Partial<T> | Partial<keyof T>\n| string | number | boolean | undefined | string[] | number[] | boolean[] | undefined[];\nexport type Selector<T> = (state: Partial<T>) => SelectedValueType<T>;\n\n\n/**\n * Represents a listener for the store.\n */\nexport type Listener<T> = {\n selector?: Selector<T>\n previousValue?: SelectedValueType<T>\n} & ListenerCallBack<T>\n\n/**\n * Represents a store.\n */\nexport type Store<T> = {\n /**\n * Get the current state of the store.\n * @returns The current state of the store.\n */\n getState: () => Partial<T>\n /**\n * Set the state of the store.\n * @param state - The new state to set.\n * @returns A promise that resolves to the new state.\n */\n setState: (state: Partial<T>) => Promise<Partial<T>>\n /**\n * Subscribe a listener to the store.\n * @param listener - The listener function to be subscribed.\n * @param selector - Optional selector function to transform the store state.\n * @returns A function to unsubscribe the listener.\n */\n subscribe: (listener: Listener<T>, selector?: Selector<T>) => () => void\n /**\n * Unubscribe a listener from the store.\n * @param listener - The listener function to be unsubscribed.\n */\n unsubscribe: (listener: Listener<T>) => void\n}\n// & { actions?: { [actionName: string]: ActionHandlerCaller } }\n\n// TODO infer actionNames from createStore arguments\n/**\n * Represents a store with additional actions.\n */\nexport type StoreWithActions<T> = Store<T> & { actions: { [actionName: string]: ActionHandlerCaller<T> } }\n\n// export type PendingAction<A> = `${A}Pending`\n// export type ErrorAction<A> = `${A}Error`\n// export type ActionName<A> = `${A}`\n\n// export type ActionsReturnType<A, TActionHandler> = Record<ActionName<A>, TActionHandler>\n\n// export type ActionsStateReturnType<A>\n// = Partial<Record<PendingAction<A>, boolean>> & Partial<Record<ErrorAction<A>, boolean>>\n\n\n// function invert<T, ActionName extends string>(\n// arr: ActionName[], state: Partial<T>, actionHandler: ActionHandlerCaller<T>,\n// ): Partial<T> & ActionsStateReturnType<ActionName> {\n// arr.forEach((x) => {\n// state[`${x}Error`] = true\n// state[`${x}Pending`] = true\n// })\n\n// return state as (Partial<T> & ActionsStateReturnType<ActionName>)\n// }\n\n// function invert2<T, A extends string>(\n// arr: A[], actions: ActionsReturnType<A>, actionHandler: ActionHandlerCaller<T>,\n// ): ActionsReturnType<A, ActionHandlerCaller<T>> {\n// arr.forEach((x) => {\n// actions[`${x}`] = actionHandler\n// })\n\n// return actions as ActionsReturnType<A>\n// }\n\n// function invert3<T, A extends string>(\n// arr: A[], actions: ActionsReturnType<A>, state: Partial<T>, actionHandler: ActionHandlerCaller<T>,\n// ): [Partial<T> & ActionsStateReturnType<A>, ActionsReturnType<A, ActionHandlerCaller<T>>] {\n// arr.forEach((x) => {\n// state[`${x}Error`] = actionHandler\n// state[`${x}Pending`] = actionHandler\n// actions[`${x}`] = actionHandler\n// })\n\n// return [state, actions] as [Partial<T> & ActionsStateReturnType<A>, ActionsReturnType<A, ActionHandlerCaller<T>>]\n// }\n\n// const example = invert(['foo', 'bar', 'baz'], {}, () => {})\n// const example2 = invert2(['foo', 'bar', 'baz'], {}, () => {})\n// const example3 = invert3(['foo', 'bar', 'baz'], {}, () => {})\n\n\n\n/**\n * Represents an action handler function.\n */\nexport type ActionHandler<T> = (\n getState: Store<T>['getState'], // Function to get the current state of the store\n setState: Store<T>['setState'], // Function to set the state of the store\n ...rest: unknown[]\n) => void | Partial<T> | Promise<void | Partial<T>>\n\n/**\n * Represents an reducer function.\n */\nexport type Reducer<T> = (\n state: Partial<T>,\n action: string,\n ...rest: unknown[]\n) => Partial<T>\n\n\n/**\n * Represents a function that calls an action handler.\n */\nexport type ActionHandlerCaller<T> = (...args: unknown[]) => void | Partial<T> | Promise<void | Partial<T>>\n\n\ntype Actions<T> = { [key: string]: ActionHandler<T>}\n/**\n * Creates a new store.\n * @param initialState - The initial state of the store.\n * @param actions - Optional actions for the store.\n * @returns The created store.\n */\nexport const createStore = <T>(\n initialState: Partial<T>,\n actions?: Actions<T>,\n reducer?: Reducer<T>,\n): Store<T> | StoreWithActions<T> => {\n let currentState: Partial<T> = initialState\n const listeners = new Set<Listener<T>>()\n\n /**\n * Gets the current state of the store.\n * @returns The current state of the store.\n */\n const getState = (): Partial<T> => currentState\n\n // TODO debounce, batch? what is the meaningful time between setState ofr UI to be rendered and registerd by User?\n /**\n * Sets the state of the store.\n * @param newState - The new state to set.\n * @returns A promise that resolves to the new state.\n */\n const setState = async (newState: Partial<T>): Promise<Partial<T>> => {\n currentState = newState\n\n // eslint-disable-next-line no-restricted-syntax\n for (const listener of listeners) {\n // has Listener selector?\n const selector: Selector<T> | undefined = listener?.selector\n\n // TODO compare selected value to the previous values of that listener/selector pair\n // if listener.previousValue === selector(currentState) no call\n // else listener.previousValue = selector(currentState) and call\n // l1 cache, weak references?\n const newValue: SelectedValueType<T> = selector ? selector(currentState) : currentState\n\n // TODO plugin equality\n if (listener.previousValue === undefined || listener.previousValue !== newValue) {\n listener.previousValue = newValue\n // eslint-disable-next-line no-await-in-loop\n await listener(newValue as Partial<T>)\n }\n }\n return currentState\n }\n\n /**\n * Represents the basic API of the store.\n */\n const storeBaseicApi: Store<T> = {\n /**\n * Get the current state of the store.\n * @returns The current state of the store.\n */\n getState,\n /**\n * Set the state of the store.\n * @param state - The new state to set.\n * @returns A promise that resolves to the new state.\n */\n setState,\n /**\n * Subscribe a listener to the store.\n * @param listener - The listener function to be subscribed.\n * @returns A function to unsubscribe the listener.\n */\n subscribe: (listener: Listener<T>, selector?: Selector<T>) => {\n if (selector && listener.selector && listener.selector !== selector) {\n throw new Error('Error, mismatch selector, listener.selector !== selector.')\n }\n if (selector && !listener.selector) {\n // eslint-disable-next-line no-param-reassign\n listener.selector = selector\n }\n\n if (listener.selector) {\n // setting the previousValue for the next cache/equality check\n // eslint-disable-next-line no-param-reassign\n listener.previousValue = listener.selector(getState())\n }\n\n listeners.add(listener)\n return () => listeners.delete(listener)\n },\n /**\n * Unsubscribe a listener from the store.\n * @param listener - The listener function to be unsubscribed.\n */\n unsubscribe: (listener: Listener<T>) => {\n listeners.delete(listener)\n },\n }\n\n /**\n * Resolves the actions and creates action handlers.\n */\n const resolvedActions: Actions<T> | null | undefined\n = actions ? Object.entries(actions)?.reduce(\n (\n aggregator: Record<string, ActionHandlerCaller<T>>,\n [actionName, actionHandler]: [string, ActionHandler<T>],\n ) => {\n // eslint-disable-next-line no-param-reassign\n aggregator[actionName] = async(...rest: unknown[]): Promise<void | Partial<T>> => {\n // TODO try to not call subscriber too many times becuase of Error and Pending values\n const isAsync = isFunctionAsync(actionHandler as () => unknown)\n\n if (isAsync) {\n setState({\n ...getState(),\n [`${actionName}Error`]: null,\n [`${actionName}Pending`]: true,\n })\n }\n\n try {\n const resultOfAction = await actionHandler(getState, setState, ...rest)\n\n // TODO try to mutate state only once with the results, that means pass custom setState to action,\n // so that it would matk pending and error already inside action\n if (reducer) {\n setState(reducer(getState(), actionName, ...rest))\n }\n\n if (isAsync) {\n setState({ ...getState(), [`${actionName}Pending`]: false })\n }\n\n return resultOfAction\n } catch (error) {\n if (isAsync) {\n setState({\n ...getState(),\n [`${actionName}Pending`]: false,\n [`${actionName}Error`]: error,\n })\n }\n throw error\n }\n }\n\n return aggregator\n },\n {},\n ) : null\n\n /**\n * Represents the store combined with actions.\n */\n const storeCombinedWithActions = {\n ...storeBaseicApi,\n ...(resolvedActions ? { actions: { ...resolvedActions } } : {}),\n }\n\n return resolvedActions\n ? storeCombinedWithActions as StoreWithActions<T>\n // ? storeCombinedWithActions as StoreWithActions<T> & ActionsStateReturnType<A>\n : storeCombinedWithActions as Store<T>\n}\n"],"names":["createStore","initialState","actions","reducer","currentState","listeners","Set","getState","setState","_ref","_asyncToGenerator","newState","listener","selector","newValue","undefined","previousValue","_x","apply","this","arguments","storeBaseicApi","subscribe","Error","add","delete","unsubscribe","resolvedActions","Object","entries","reduce","aggregator","_ref2","actionName","actionHandler","isAsync","isFunctionAsync","_len","length","rest","Array","_key","resultOfAction","error","storeCombinedWithActions"],"mappings":"2IAgJ2BA,CACzBC,EACAC,EACAC,KAEA,IAAIC,EAA2BH,EAC/B,MAAMI,EAAY,IAAIC,IAMhBC,EAAWA,IAAkBH,EAQ7BI,EAAQ,WAAA,IAAAC,EAAAC,oBAAG,UAAOC,GACtBP,EAAeO,EAGf,IAAK,MAAMC,KAAYP,EAAW,CAEhC,MAAMQ,EAAoCD,GAAUC,SAM9CC,EAAiCD,EAAWA,EAAST,GAAgBA,OAG5CW,IAA3BH,EAASI,eAA+BJ,EAASI,gBAAkBF,IACrEF,EAASI,cAAgBF,QAEnBF,EAASE,GAEnB,CACA,OAAOV,KACR,OAtBKI,SAAQS,GAAA,OAAAR,EAAAS,MAAAC,KAAAC,UAAA,EAAA,GA2BRC,EAA2B,CAK/Bd,WAMAC,WAMAc,UAAWA,CAACV,EAAuBC,KACjC,GAAIA,GAAYD,EAASC,UAAYD,EAASC,WAAaA,EACzD,MAAM,IAAIU,MAAM,6DAclB,OAZIV,IAAaD,EAASC,WAExBD,EAASC,SAAWA,GAGlBD,EAASC,WAGXD,EAASI,cAAgBJ,EAASC,SAASN,MAG7CF,EAAUmB,IAAIZ,GACP,IAAMP,EAAUoB,OAAOb,EAAS,EAMzCc,YAAcd,IACZP,EAAUoB,OAAOb,EAAS,GAOxBe,EACFzB,EAAU0B,OAAOC,QAAQ3B,IAAU4B,QACnC,CACEC,EAAkDC,KAE/C,IADFC,EAAYC,GAA0CF,EAyCvD,OAtCAD,EAAWE,GAAWvB,EAAAA,kBAAG,YAEvB,MAAMyB,EAAUC,kBAAgBF,GAE5BC,GACF3B,EAAS,IACJD,IACH,CAAC,GAAG0B,UAAoB,KACxB,CAAC,GAAGA,aAAsB,IAI9B,IAAI,IAAA,IAAAI,EAAAjB,UAAAkB,OAZ4BC,EAAIC,IAAAA,MAAAH,GAAAI,EAAA,EAAAA,EAAAJ,EAAAI,IAAJF,EAAIE,GAAArB,UAAAqB,GAalC,MAAMC,QAAuBR,EAAc3B,EAAUC,KAAa+B,GAYlE,OARIpC,GACFK,EAASL,EAAQI,IAAY0B,KAAeM,IAG1CJ,GACF3B,EAAS,IAAKD,IAAY,CAAC,GAAG0B,aAAsB,IAG/CS,CACR,CAAC,MAAOC,GAQP,MAPIR,GACF3B,EAAS,IACJD,IACH,CAAC,GAAG0B,aAAsB,EAC1B,CAAC,GAAGA,UAAoBU,IAGtBA,CACR,KAGKZ,CAAU,GAEnB,CAAA,GACE,KAKAa,EAA2B,IAC5BvB,KACCM,EAAkB,CAAEzB,QAAS,IAAKyB,IAAsB,IAG9D,OACIiB,CAEoC"}
|
|
1
|
+
{"version":3,"file":"store.vanillajs.js","sources":["../../../../../../../src/core/utils/appState/store/store.vanillajs.ts"],"sourcesContent":["\n// TinyStore, inspired by https://github.com/jherr/syncexternalstore/blob/main/csr/src/store.js\n\nimport { isFunctionAsync } from '../../helpers'\n\n/**\n * Represents the callback function for a store listener.\n */\nexport type ListenerCallBack<T> = (state: Partial<T>) => void\n\n/**\n * Represents a selector function that transforms the store state.\n */\n// export type Selector<T> = (state: Partial<T>) => Partial<T>;\nexport type SelectedValueType<T> = Partial<T> | Partial<keyof T>\n| string | number | boolean | undefined | string[] | number[] | boolean[] | undefined[];\nexport type Selector<T> = (state: Partial<T>) => SelectedValueType<T>;\n\n\n/**\n * Represents a listener for the store.\n */\nexport type Listener<T> = {\n selector?: Selector<T>\n previousValue?: SelectedValueType<T>\n} & ListenerCallBack<T>\n\n/**\n * Represents a store.\n */\nexport type Store<T> = {\n /**\n * Get the current state of the store.\n * @returns The current state of the store.\n */\n getState: () => Partial<T>\n /**\n * Set the state of the store.\n * @param state - The new state to set.\n * @returns A promise that resolves to the new state.\n */\n setState: (state: Partial<T>) => Promise<Partial<T>>\n /**\n * Subscribe a listener to the store.\n * @param listener - The listener function to be subscribed.\n * @param selector - Optional selector function to transform the store state.\n * @returns A function to unsubscribe the listener.\n */\n subscribe: (listener: Listener<T>, selector?: Selector<T>) => () => void\n /**\n * Unubscribe a listener from the store.\n * @param listener - The listener function to be unsubscribed.\n */\n unsubscribe: (listener: Listener<T>) => void\n}\n// & { actions?: { [actionName: string]: ActionHandlerCaller } }\n\n// TODO infer actionNames from createStore arguments\n/**\n * Represents a store with additional actions.\n */\nexport type StoreWithActions<T> = Store<T> & { actions: { [actionName: string]: ActionHandlerCaller<T> } }\n\n\n\n\n/**\n * Represents an action handler function.\n */\nexport type ActionHandler<T> = (\n getState: Store<T>['getState'], // Function to get the current state of the store\n setState: Store<T>['setState'], // Function to set the state of the store\n ...rest: unknown[]\n) => void | Partial<T> | Promise<void | Partial<T>>\n\n/**\n * Represents an reducer function.\n */\nexport type Reducer<T> = (\n state: Partial<T>,\n action: string,\n ...rest: unknown[]\n) => Partial<T>\n\n\n/**\n * Represents a function that calls an action handler.\n */\nexport type ActionHandlerCaller<T> = (...args: unknown[]) => void | Partial<T> | Promise<void | Partial<T>>\n\n\ntype Actions<T> = { [key: string]: ActionHandler<T>}\n/**\n * Creates a new store.\n * @param initialState - The initial state of the store.\n * @param actions - Optional actions for the store.\n * @returns The created store.\n */\nexport const createStore = <T>(\n initialState: Partial<T>,\n actions?: Actions<T>,\n reducer?: Reducer<T>,\n): Store<T> | StoreWithActions<T> => {\n let currentState: Partial<T> = initialState\n const listeners = new Set<Listener<T>>()\n\n /**\n * Gets the current state of the store.\n * @returns The current state of the store.\n */\n const getState = (): Partial<T> => currentState\n\n // TODO debounce, batch? what is the meaningful time between setState ofr UI to be rendered and registerd by User?\n /**\n * Sets the state of the store.\n * @param newState - The new state to set.\n * @returns A promise that resolves to the new state.\n */\n const setState = async (newState: Partial<T>): Promise<Partial<T>> => {\n currentState = newState\n\n // eslint-disable-next-line no-restricted-syntax\n for (const listener of listeners) {\n // has Listener selector?\n const selector: Selector<T> | undefined = listener?.selector\n\n // TODO compare selected value to the previous values of that listener/selector pair\n // if listener.previousValue === selector(currentState) no call\n // else listener.previousValue = selector(currentState) and call\n // l1 cache, weak references?\n const newValue: SelectedValueType<T> = selector ? selector(currentState) : currentState\n\n // TODO plugin equality\n if (listener.previousValue === undefined || listener.previousValue !== newValue) {\n listener.previousValue = newValue\n // eslint-disable-next-line no-await-in-loop\n await listener(newValue as Partial<T>)\n }\n }\n return currentState\n }\n\n /**\n * Represents the basic API of the store.\n */\n const storeBaseicApi: Store<T> = {\n /**\n * Get the current state of the store.\n * @returns The current state of the store.\n */\n getState,\n /**\n * Set the state of the store.\n * @param state - The new state to set.\n * @returns A promise that resolves to the new state.\n */\n setState,\n /**\n * Subscribe a listener to the store.\n * @param listener - The listener function to be subscribed.\n * @returns A function to unsubscribe the listener.\n */\n subscribe: (listener: Listener<T>, selector?: Selector<T>) => {\n if (selector && listener.selector && listener.selector !== selector) {\n throw new Error('Error, mismatch selector, listener.selector !== selector.')\n }\n if (selector && !listener.selector) {\n // eslint-disable-next-line no-param-reassign\n listener.selector = selector\n }\n\n if (listener.selector) {\n // setting the previousValue for the next cache/equality check\n // eslint-disable-next-line no-param-reassign\n listener.previousValue = listener.selector(getState())\n }\n\n listeners.add(listener)\n return () => listeners.delete(listener)\n },\n /**\n * Unsubscribe a listener from the store.\n * @param listener - The listener function to be unsubscribed.\n */\n unsubscribe: (listener: Listener<T>) => {\n listeners.delete(listener)\n },\n }\n\n /**\n * Resolves the actions and creates action handlers.\n */\n const resolvedActions: Actions<T> | null | undefined\n = actions ? Object.entries(actions)?.reduce(\n (\n aggregator: Record<string, ActionHandlerCaller<T>>,\n [actionName, actionHandler]: [string, ActionHandler<T>],\n ) => {\n // eslint-disable-next-line no-param-reassign\n aggregator[actionName] = async(...rest: unknown[]): Promise<void | Partial<T>> => {\n // TODO try to not call subscriber too many times becuase of Error and Pending values\n const isAsync = isFunctionAsync(actionHandler as () => unknown)\n\n if (isAsync) {\n setState({\n ...getState(),\n [`${actionName}Error`]: null,\n [`${actionName}Pending`]: true,\n })\n }\n\n try {\n const resultOfAction = await actionHandler(getState, setState, ...rest)\n\n // TODO try to mutate state only once with the results, that means pass custom setState to action,\n // so that it would matk pending and error already inside action\n if (reducer) {\n setState(reducer(getState(), actionName, ...rest))\n }\n\n if (isAsync) {\n setState({ ...getState(), [`${actionName}Pending`]: false })\n }\n\n return resultOfAction\n } catch (error) {\n if (isAsync) {\n setState({\n ...getState(),\n [`${actionName}Pending`]: false,\n [`${actionName}Error`]: error,\n })\n }\n throw error\n }\n }\n\n return aggregator\n },\n {},\n ) : null\n\n /**\n * Represents the store combined with actions.\n */\n const storeCombinedWithActions = {\n ...storeBaseicApi,\n ...(resolvedActions ? { actions: { ...resolvedActions } } : {}),\n }\n\n return resolvedActions\n ? storeCombinedWithActions as StoreWithActions<T>\n // ? storeCombinedWithActions as StoreWithActions<T> & ActionsStateReturnType<A>\n : storeCombinedWithActions as Store<T>\n}\n"],"names":["createStore","initialState","actions","reducer","currentState","listeners","Set","getState","setState","_ref","_asyncToGenerator","newState","listener","selector","newValue","undefined","previousValue","_x","apply","this","arguments","storeBaseicApi","subscribe","Error","add","delete","unsubscribe","resolvedActions","Object","entries","reduce","aggregator","_ref2","actionName","actionHandler","isAsync","isFunctionAsync","_len","length","rest","Array","_key","resultOfAction","error","storeCombinedWithActions"],"mappings":"2IAkG2BA,CACzBC,EACAC,EACAC,KAEA,IAAIC,EAA2BH,EAC/B,MAAMI,EAAY,IAAIC,IAMhBC,EAAWA,IAAkBH,EAQ7BI,EAAQ,WAAA,IAAAC,EAAAC,oBAAG,UAAOC,GACtBP,EAAeO,EAGf,IAAK,MAAMC,KAAYP,EAAW,CAEhC,MAAMQ,EAAoCD,GAAUC,SAM9CC,EAAiCD,EAAWA,EAAST,GAAgBA,OAG5CW,IAA3BH,EAASI,eAA+BJ,EAASI,gBAAkBF,IACrEF,EAASI,cAAgBF,QAEnBF,EAASE,GAEnB,CACA,OAAOV,KACR,OAtBKI,SAAQS,GAAA,OAAAR,EAAAS,MAAAC,KAAAC,UAAA,EAAA,GA2BRC,EAA2B,CAK/Bd,WAMAC,WAMAc,UAAWA,CAACV,EAAuBC,KACjC,GAAIA,GAAYD,EAASC,UAAYD,EAASC,WAAaA,EACzD,MAAM,IAAIU,MAAM,6DAclB,OAZIV,IAAaD,EAASC,WAExBD,EAASC,SAAWA,GAGlBD,EAASC,WAGXD,EAASI,cAAgBJ,EAASC,SAASN,MAG7CF,EAAUmB,IAAIZ,GACP,IAAMP,EAAUoB,OAAOb,EAAS,EAMzCc,YAAcd,IACZP,EAAUoB,OAAOb,EAAS,GAOxBe,EACFzB,EAAU0B,OAAOC,QAAQ3B,IAAU4B,QACnC,CACEC,EAAkDC,KAE/C,IADFC,EAAYC,GAA0CF,EAyCvD,OAtCAD,EAAWE,GAAWvB,EAAAA,kBAAG,YAEvB,MAAMyB,EAAUC,kBAAgBF,GAE5BC,GACF3B,EAAS,IACJD,IACH,CAAC,GAAG0B,UAAoB,KACxB,CAAC,GAAGA,aAAsB,IAI9B,IAAI,IAAA,IAAAI,EAAAjB,UAAAkB,OAZ4BC,EAAIC,IAAAA,MAAAH,GAAAI,EAAA,EAAAA,EAAAJ,EAAAI,IAAJF,EAAIE,GAAArB,UAAAqB,GAalC,MAAMC,QAAuBR,EAAc3B,EAAUC,KAAa+B,GAYlE,OARIpC,GACFK,EAASL,EAAQI,IAAY0B,KAAeM,IAG1CJ,GACF3B,EAAS,IAAKD,IAAY,CAAC,GAAG0B,aAAsB,IAG/CS,CACR,CAAC,MAAOC,GAQP,MAPIR,GACF3B,EAAS,IACJD,IACH,CAAC,GAAG0B,aAAsB,EAC1B,CAAC,GAAGA,UAAoBU,IAGtBA,CACR,KAGKZ,CAAU,GAEnB,CAAA,GACE,KAKAa,EAA2B,IAC5BvB,KACCM,EAAkB,CAAEzB,QAAS,IAAKyB,IAAsB,IAG9D,OACIiB,CAEoC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.vanillajs.templates.js","sources":["../../../../../../../src/core/utils/appState/store/store.vanillajs.templates.ts"],"sourcesContent":["import { ActionHandler, Reducer, Store, StoreWithActions, createStore } from './store.vanillajs'\n\n\ntype DefaultES = { [key: string]: any }\n\n\nexport type DataState<T, ES = DefaultES> = {\n dataId: string\n isLoading: boolean\n error?: unknown\n data?: T\n} & ES\n\n\ntype Load<T, ES = DefaultES> = (\n getState: Store<DataState<T, ES>>['getState'],\n setState: Store<DataState<T, ES>>['setState'],\n dataPromise: unknown | Promise<unknown>,\n) => Promise<Partial<DataState<T, ES>>>\n\n\ntype LoadHandler<T, ES = DefaultES> = (\n dataPromise: unknown | Promise<unknown>,\n) => Promise<Partial<DataState<T, ES>>>\n\n/**\n * Creates a data store with actions.\n * @param dataId - The ID of the data.\n * @param actions - Optional actions for the data store.\n * @returns The created data store with actions.\n */\nexport const createDataStore\n= <T, ES = DefaultES>(\n dataId: string,\n initialState?: Partial<ES>,\n actions?: Record<string, ActionHandler<DataState<T, ES>>>,\n reducer?: Reducer<DataState<T, ES>>,\n): StoreWithActions<DataState<T, ES>>\n& { actions: { load: LoadHandler<T, ES> } } => {\n const loadActions: { load: Load<T, ES> } = {\n ...actions,\n /**\n * Loads data into the data store.\n * @param getState - Function to get the current state of the data store.\n * @param setState - Function to set the state of the data store.\n * @param dataPromise - The data promise to be loaded.\n * @returns A promise that resolves to the updated state of the data store.\n */\n load: async (\n getState: Store<DataState<T, ES>>['getState'],\n setState: Store<DataState<T, ES>>['setState'],\n dataPromise: unknown | Promise<unknown>,\n ) => {\n const dataState: Partial<DataState<T, ES>> = getState()\n\n setState({ ...dataState, isLoading: true })\n\n try {\n const response: unknown = await dataPromise\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n dataState.data = response?.data || response\n } catch (error: unknown) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n dataState.error = error\n }\n return setState({ ...dataState, isLoading: false })\n },\n }\n\n return (createStore<DataState<T, ES>>({\n ...initialState,\n dataId,\n isLoading: false,\n } as Partial<DataState<T, ES>>, loadActions, reducer)) as StoreWithActions<DataState<T, ES>>\n & { actions: { load: LoadHandler<T, ES> } }\n}\n"],"names":["createDataStore","dataId","initialState","actions","reducer","loadActions","load","_ref","_asyncToGenerator","asyncToGenerator","getState","setState","dataPromise","dataState","isLoading","response","data","error","_x","_x2","_x3","apply","this","arguments","createStore"],"mappings":"6IAgCEA,CACAC,EACAC,EACAC,EACAC,KAGA,MAAMC,EAAqC,IACtCF,EAQHG,MAAIC,EAAAC,EAAAC,kBAAE,UACJC,EACAC,EACAC,GAEA,MAAMC,EAAuCH,IAE7CC,EAAS,IAAKE,EAAWC,WAAW,IAEpC,IACE,MAAMC,QAA0BH,EAIhCC,EAAUG,KAAOD,GAAUC,MAAQD,CACpC,CAAC,MAAOE,GAGPJ,EAAUI,MAAQA,CACpB,CACA,OAAON,EAAS,IAAKE,EAAWC,WAAW,OAC5C,
|
|
1
|
+
{"version":3,"file":"store.vanillajs.templates.js","sources":["../../../../../../../src/core/utils/appState/store/store.vanillajs.templates.ts"],"sourcesContent":["import { ActionHandler, Reducer, Store, StoreWithActions, createStore } from './store.vanillajs'\n\n\ntype DefaultES = { [key: string]: any }\n\n\nexport type DataState<T, ES = DefaultES> = {\n dataId: string\n isLoading: boolean\n error?: unknown\n data?: T\n} & ES\n\n\ntype Load<T, ES = DefaultES> = (\n getState: Store<DataState<T, ES>>['getState'],\n setState: Store<DataState<T, ES>>['setState'],\n dataPromise: unknown | Promise<unknown>,\n) => Promise<Partial<DataState<T, ES>>>\n\n\ntype LoadHandler<T, ES = DefaultES> = (\n dataPromise: unknown | Promise<unknown>,\n) => Promise<Partial<DataState<T, ES>>>\n\n/**\n * Creates a data store with actions.\n * @param dataId - The ID of the data.\n * @param actions - Optional actions for the data store.\n * @returns The created data store with actions.\n */\nexport const createDataStore\n= <T, ES = DefaultES>(\n dataId: string,\n initialState?: Partial<ES>,\n actions?: Record<string, ActionHandler<DataState<T, ES>>>,\n reducer?: Reducer<DataState<T, ES>>,\n): StoreWithActions<DataState<T, ES>>\n& { actions: { load: LoadHandler<T, ES> } } => {\n const loadActions: { load: Load<T, ES> } = {\n ...actions,\n /**\n * Loads data into the data store.\n * @param getState - Function to get the current state of the data store.\n * @param setState - Function to set the state of the data store.\n * @param dataPromise - The data promise to be loaded.\n * @returns A promise that resolves to the updated state of the data store.\n */\n load: async (\n getState: Store<DataState<T, ES>>['getState'],\n setState: Store<DataState<T, ES>>['setState'],\n dataPromise: unknown | Promise<unknown>,\n ) => {\n const dataState: Partial<DataState<T, ES>> = getState()\n\n setState({ ...dataState, isLoading: true })\n\n try {\n const response: unknown = await dataPromise\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n dataState.data = response?.data || response\n } catch (error: unknown) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n dataState.error = error\n }\n return setState({ ...dataState, isLoading: false })\n },\n }\n\n return (createStore<DataState<T, ES>>({\n ...initialState,\n dataId,\n isLoading: false,\n } as Partial<DataState<T, ES>>, loadActions, reducer)) as StoreWithActions<DataState<T, ES>>\n & { actions: { load: LoadHandler<T, ES> } }\n}\n"],"names":["createDataStore","dataId","initialState","actions","reducer","loadActions","load","_ref","_asyncToGenerator","asyncToGenerator","getState","setState","dataPromise","dataState","isLoading","response","data","error","_x","_x2","_x3","apply","this","arguments","createStore"],"mappings":"6IAgCEA,CACAC,EACAC,EACAC,EACAC,KAGA,MAAMC,EAAqC,IACtCF,EAQHG,MAAIC,EAAAC,EAAAC,kBAAE,UACJC,EACAC,EACAC,GAEA,MAAMC,EAAuCH,IAE7CC,EAAS,IAAKE,EAAWC,WAAW,IAEpC,IACE,MAAMC,QAA0BH,EAIhCC,EAAUG,KAAOD,GAAUC,MAAQD,CACpC,CAAC,MAAOE,GAGPJ,EAAUI,MAAQA,CACpB,CACA,OAAON,EAAS,IAAKE,EAAWC,WAAW,OAC5C,SArBGI,EAAAC,EAAAC,GAAA,OAAAb,EAAAc,MAAAC,KAAAC,UAAA,IAAA,IAAAhB,EAwBN,OAAQiB,cAA8B,IACjCtB,EACHD,SACAa,WAAW,GACmBT,EAAaD,EAAQ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("./keyExtractor.js"),t=require("./date.js"),r=require("./appState/peregrineMQ/index.js"),a=require("./helpers/birthnumber.validator.js"),s=require("./helpers/birthnumberCZSKvalidator.js"),o=require("./helpers/fileValidator.js"),i=require("./helpers/date.js"),p=require("./helpers/deviceInfo.js"),n=require("./helpers/emailMatcher.js"),l=require("./helpers/file.js"),x=require("./helpers/objectOperations.js"),m=require("./helpers/other.js"),c=require("./helpers/textValueOperations.js"),u=require("./helpers/valueOperations.js"),d=require("./helpers/cancelableDelayedFunction.js"),S=require("./helpers/ui.js"),T=require("./helpers/text.js"),g=require("./webComponents/webComponent.utils.js"),h=require("./appState/store/store.vanillajs.js"),M=require("./appState/store/store.vanillajs.templates.js"),v=require("./appState/store/useStore.react.js"),b=require("./appState/peregrineMQ/peregrineMQ.js"),
|
|
1
|
+
"use strict";var e=require("./keyExtractor.js"),t=require("./date.js"),r=require("./appState/peregrineMQ/index.js"),a=require("./helpers/birthnumber.validator.js"),s=require("./helpers/birthnumberCZSKvalidator.js"),o=require("./helpers/fileValidator.js"),i=require("./helpers/date.js"),p=require("./helpers/deviceInfo.js"),n=require("./helpers/emailMatcher.js"),l=require("./helpers/file.js"),x=require("./helpers/objectOperations.js"),m=require("./helpers/other.js"),c=require("./helpers/textValueOperations.js"),u=require("./helpers/valueOperations.js"),d=require("./helpers/cancelableDelayedFunction.js"),S=require("./helpers/ui.js"),T=require("./helpers/text.js"),g=require("./webComponents/webComponent.utils.js"),h=require("./appState/store/store.vanillajs.js"),M=require("./appState/store/store.vanillajs.templates.js"),v=require("./appState/store/useStore.react.js"),j=require("./appState/peregrineMQ/peregrineMQ.js"),b=require("./appState/peregrineMQ/peregrineMQ.types.js"),y=require("./appState/peregrineMQ/usePeregrineMQ.react.js"),f=require("./appState/stateMachine/tiny-state-machine.base.js");exports.keyExtractor=e.keyExtractor,exports.keyExtractorFunction=e.keyExtractorFunction,exports.dateRangeFormat=t.dateRangeFormat,exports.getDateTime=t.getDateTime,exports.getTimeFromNow=t.getTimeFromNow,exports.getTimeFromNowOriginal=t.getTimeFromNowOriginal,exports.getTimeTo=t.getTimeTo,exports.peregrineMQInstance=r.peregrineMQInstance,exports.isBirthNumberValid=a.isBirthNumberValid,exports.getMatch=s.getMatch,exports.isValidFormat=s.isValidFormat,exports.isValidModulo11=s.isValidModulo11,exports.parse=s.parse,exports.regex=s.regex,exports.parseCSVdata=o.parseCSVdata,exports.validateCSVFile=o.validateCSVFile,exports.validateCSVlines=o.validateCSVlines,exports.validateJSONFile=o.validateJSONFile,exports.validateLineCellTrimmed=o.validateLineCellTrimmed,exports.validateLineNumColumns=o.validateLineNumColumns,exports.validateSDFFile=o.validateSDFFile,exports.DATE_FORMAT=i.DATE_FORMAT,exports.DATE_TIME_FORMAT=i.DATE_TIME_FORMAT,exports.formatDate=i.formatDate,exports.formatDateTime=i.formatDateTime,exports.formatDateToTimestamp=i.formatDateToTimestamp,exports.getDate=i.getDate,exports.getDeviceId=p.getDeviceId,exports.emailMatch=n.emailMatch,exports.emailMatcher=n.emailMatcher,exports.regexBuilder=n.regexBuilder,exports.cleanCsvLines=l.cleanCsvLines,exports.formatFilePath=l.formatFilePath,exports.arrayToObjectTree=x.arrayToObjectTree,exports.chunkArray=x.chunkArray,exports.duplicatesInArray=x.duplicatesInArray,exports.formatJsonString=x.formatJsonString,exports.formatObj=x.formatObj,exports.formatObj2=x.formatObj2,exports.AsyncFunctionTemplate=m.AsyncFunctionTemplate,exports.debounce=m.debounce,exports.delay=m.delay,exports.isFunctionAsync=m.isFunctionAsync,exports.memoize=m.memoize,exports.memoizeComplex=m.memoizeComplex,exports.memoizer=m.memoizer,exports.nestedTernary=m.nestedTernary,exports.escapeRegExp=c.escapeRegExp,exports.fileNameExt=c.fileNameExt,exports.findStringInText=c.findStringInText,exports.normalizeString=c.normalizeString,exports.removeWhitespaces=c.removeWhitespaces,exports.sanitizeId=c.sanitizeId,exports.sanitizePathId=c.sanitizePathId,exports.toLowerCase=c.toLowerCase,exports.toUpperCase=c.toUpperCase,exports.truncateText=c.truncateText,exports.Operation=u.Operation,exports.decrementValue=u.decrementValue,exports.incerementValue=u.incerementValue,exports.numberDefined=u.numberDefined,exports.numberOperation=u.numberOperation,exports.restrictNumberInLimits=u.restrictNumberInLimits,exports.setValue=u.setValue,exports.cancelableSetInterval=d.cancelableSetInterval,exports.cancelableSetTimeout=d.cancelableSetTimeout,exports.anchorClick=S.anchorClick,exports.classNames=S.classNames,exports.generateId=S.generateId,exports.mapSerReplacer=S.mapSerReplacer,exports.noop=S.noop,exports.parseProps=S.parseProps,exports.composeId=T.composeId,exports.defaultSanitizeConfig=T.defaultSanitizeConfig,exports.sanitizeHtml=T.sanitizeHtml,exports.ced=g.ced,exports.createResolveAttribute=g.createResolveAttribute,exports.customElementDefine=g.customElementDefine,exports.resolveAttributes=g.resolveAttributes,exports.createStore=h.createStore,exports.createDataStore=M.createDataStore,exports.useStore=v.useStore,exports.useStoreApi=v.useStoreApi,exports.PeregrineMQ=j.PeregrineMQ,exports.PeregrineMQClearError=j.PeregrineMQClearError,exports.NON_EXISTENT_CHANNEL=b.NON_EXISTENT_CHANNEL,exports.usePeregrineMQ=y.usePeregrineMQ,exports.TinyStateMachine=f.TinyStateMachine,exports.TinyStateMachineEvent=f.TinyStateMachineEvent,exports.TinyStateMachineEventType=f.TinyStateMachineEventType,exports.TinyStateMachineState=f.TinyStateMachineState,exports.createStates=f.createStates,exports.stateIterator=f.stateIterator;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|