@e1011/es-kit 1.0.171 → 1.0.172
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/_virtual/{shared.js → shared-store.js} +1 -1
- package/dist/hooks/_virtual/shared-store.js.map +1 -0
- package/dist/{lib/esm/_virtual/shared.js → hooks/esm/_virtual/shared-store.js} +1 -1
- package/dist/hooks/esm/_virtual/shared-store.js.map +1 -0
- package/dist/hooks/esm/index.css +41 -41
- package/dist/hooks/esm/node_modules/core-js/internals/array-includes.js +1 -1
- package/dist/hooks/esm/node_modules/core-js/internals/array-includes.js.map +1 -1
- package/dist/hooks/esm/node_modules/core-js/internals/shared-store.js +1 -1
- package/dist/hooks/esm/node_modules/core-js/internals/shared-store.js.map +1 -1
- package/dist/hooks/esm/node_modules/core-js/internals/shared.js +1 -1
- package/dist/hooks/esm/node_modules/core-js/internals/shared.js.map +1 -1
- package/dist/hooks/index.css +41 -41
- package/dist/hooks/node_modules/core-js/internals/array-includes.js +1 -1
- package/dist/hooks/node_modules/core-js/internals/array-includes.js.map +1 -1
- package/dist/hooks/node_modules/core-js/internals/inspect-source.js +1 -1
- package/dist/hooks/node_modules/core-js/internals/inspect-source.js.map +1 -1
- package/dist/hooks/node_modules/core-js/internals/internal-state.js +1 -1
- package/dist/hooks/node_modules/core-js/internals/internal-state.js.map +1 -1
- package/dist/hooks/node_modules/core-js/internals/shared-key.js +1 -1
- package/dist/hooks/node_modules/core-js/internals/shared-key.js.map +1 -1
- package/dist/hooks/node_modules/core-js/internals/shared-store.js +1 -1
- package/dist/hooks/node_modules/core-js/internals/shared-store.js.map +1 -1
- package/dist/hooks/node_modules/core-js/internals/shared.js +1 -1
- package/dist/hooks/node_modules/core-js/internals/shared.js.map +1 -1
- package/dist/hooks/node_modules/core-js/internals/well-known-symbol.js +1 -1
- package/dist/hooks/node_modules/core-js/internals/well-known-symbol.js.map +1 -1
- package/dist/lib/cjs/_virtual/{shared.js → shared-store.js} +1 -1
- package/dist/lib/cjs/_virtual/shared-store.js.map +1 -0
- package/dist/lib/cjs/node_modules/core-js/internals/array-includes.js +1 -1
- package/dist/lib/cjs/node_modules/core-js/internals/array-includes.js.map +1 -1
- package/dist/lib/cjs/node_modules/core-js/internals/inspect-source.js +1 -1
- package/dist/lib/cjs/node_modules/core-js/internals/inspect-source.js.map +1 -1
- package/dist/lib/cjs/node_modules/core-js/internals/internal-state.js +1 -1
- package/dist/lib/cjs/node_modules/core-js/internals/internal-state.js.map +1 -1
- package/dist/lib/cjs/node_modules/core-js/internals/regexp-exec.js +1 -1
- package/dist/lib/cjs/node_modules/core-js/internals/regexp-exec.js.map +1 -1
- package/dist/lib/cjs/node_modules/core-js/internals/shared-key.js +1 -1
- package/dist/lib/cjs/node_modules/core-js/internals/shared-key.js.map +1 -1
- package/dist/lib/cjs/node_modules/core-js/internals/shared-store.js +1 -1
- package/dist/lib/cjs/node_modules/core-js/internals/shared-store.js.map +1 -1
- package/dist/lib/cjs/node_modules/core-js/internals/shared.js +1 -1
- package/dist/lib/cjs/node_modules/core-js/internals/shared.js.map +1 -1
- package/dist/lib/cjs/node_modules/core-js/internals/well-known-symbol.js +1 -1
- package/dist/lib/cjs/node_modules/core-js/internals/well-known-symbol.js.map +1 -1
- package/dist/lib/cjs/src/core/utils/appState/store/store.vanillajs.js +1 -1
- package/dist/lib/cjs/src/core/utils/appState/store/store.vanillajs.js.map +1 -1
- package/dist/{ui/esm/_virtual/shared.js → lib/esm/_virtual/shared-store.js} +1 -1
- package/dist/lib/esm/_virtual/shared-store.js.map +1 -0
- package/dist/lib/esm/node_modules/core-js/internals/array-includes.js +1 -1
- package/dist/lib/esm/node_modules/core-js/internals/array-includes.js.map +1 -1
- package/dist/lib/esm/node_modules/core-js/internals/shared-store.js +1 -1
- package/dist/lib/esm/node_modules/core-js/internals/shared-store.js.map +1 -1
- package/dist/lib/esm/node_modules/core-js/internals/shared.js +1 -1
- package/dist/lib/esm/node_modules/core-js/internals/shared.js.map +1 -1
- package/dist/lib/esm/src/core/utils/appState/store/store.vanillajs.js +1 -1
- package/dist/lib/esm/src/core/utils/appState/store/store.vanillajs.js.map +1 -1
- package/dist/lib/src/core/utils/appState/store/store.vanillajs.js +8 -1
- package/dist/lib/src/core/utils/appState/store/store.vanillajs.js.map +1 -1
- package/dist/lib/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/core/utils/appState/store/store.vanillajs.d.ts +2 -1
- package/dist/types/src/core/utils/appState/store/store.vanillajs.d.ts.map +1 -1
- package/dist/ui/_virtual/{shared.js → shared-store.js} +1 -1
- package/dist/ui/_virtual/shared-store.js.map +1 -0
- package/dist/{hooks/esm/_virtual/shared.js → ui/esm/_virtual/shared-store.js} +1 -1
- package/dist/ui/esm/_virtual/shared-store.js.map +1 -0
- package/dist/ui/esm/node_modules/core-js/internals/array-includes.js +1 -1
- package/dist/ui/esm/node_modules/core-js/internals/array-includes.js.map +1 -1
- package/dist/ui/esm/node_modules/core-js/internals/shared-store.js +1 -1
- package/dist/ui/esm/node_modules/core-js/internals/shared-store.js.map +1 -1
- package/dist/ui/esm/node_modules/core-js/internals/shared.js +1 -1
- package/dist/ui/esm/node_modules/core-js/internals/shared.js.map +1 -1
- package/dist/ui/node_modules/core-js/internals/array-includes.js +1 -1
- package/dist/ui/node_modules/core-js/internals/array-includes.js.map +1 -1
- package/dist/ui/node_modules/core-js/internals/inspect-source.js +1 -1
- package/dist/ui/node_modules/core-js/internals/inspect-source.js.map +1 -1
- package/dist/ui/node_modules/core-js/internals/internal-state.js +1 -1
- package/dist/ui/node_modules/core-js/internals/internal-state.js.map +1 -1
- package/dist/ui/node_modules/core-js/internals/regexp-exec.js +1 -1
- package/dist/ui/node_modules/core-js/internals/regexp-exec.js.map +1 -1
- package/dist/ui/node_modules/core-js/internals/shared-key.js +1 -1
- package/dist/ui/node_modules/core-js/internals/shared-key.js.map +1 -1
- package/dist/ui/node_modules/core-js/internals/shared-store.js +1 -1
- package/dist/ui/node_modules/core-js/internals/shared-store.js.map +1 -1
- package/dist/ui/node_modules/core-js/internals/shared.js +1 -1
- package/dist/ui/node_modules/core-js/internals/shared.js.map +1 -1
- package/dist/ui/node_modules/core-js/internals/well-known-symbol.js +1 -1
- package/dist/ui/node_modules/core-js/internals/well-known-symbol.js.map +1 -1
- package/dist/utils/_virtual/{shared.js → shared-store.js} +1 -1
- package/dist/utils/_virtual/shared-store.js.map +1 -0
- package/dist/utils/esm/_virtual/{shared.js → shared-store.js} +1 -1
- package/dist/utils/esm/_virtual/shared-store.js.map +1 -0
- package/dist/utils/esm/index.css +41 -41
- package/dist/utils/esm/node_modules/core-js/internals/array-includes.js +1 -1
- package/dist/utils/esm/node_modules/core-js/internals/array-includes.js.map +1 -1
- package/dist/utils/esm/node_modules/core-js/internals/shared-store.js +1 -1
- package/dist/utils/esm/node_modules/core-js/internals/shared-store.js.map +1 -1
- package/dist/utils/esm/node_modules/core-js/internals/shared.js +1 -1
- package/dist/utils/esm/node_modules/core-js/internals/shared.js.map +1 -1
- package/dist/utils/esm/src/core/utils/appState/store/store.vanillajs.js +1 -1
- package/dist/utils/esm/src/core/utils/appState/store/store.vanillajs.js.map +1 -1
- package/dist/utils/index.css +41 -41
- package/dist/utils/node_modules/core-js/internals/array-includes.js +1 -1
- package/dist/utils/node_modules/core-js/internals/array-includes.js.map +1 -1
- package/dist/utils/node_modules/core-js/internals/inspect-source.js +1 -1
- package/dist/utils/node_modules/core-js/internals/inspect-source.js.map +1 -1
- package/dist/utils/node_modules/core-js/internals/internal-state.js +1 -1
- package/dist/utils/node_modules/core-js/internals/internal-state.js.map +1 -1
- package/dist/utils/node_modules/core-js/internals/regexp-exec.js +1 -1
- package/dist/utils/node_modules/core-js/internals/regexp-exec.js.map +1 -1
- package/dist/utils/node_modules/core-js/internals/shared-key.js +1 -1
- package/dist/utils/node_modules/core-js/internals/shared-key.js.map +1 -1
- package/dist/utils/node_modules/core-js/internals/shared-store.js +1 -1
- package/dist/utils/node_modules/core-js/internals/shared-store.js.map +1 -1
- package/dist/utils/node_modules/core-js/internals/shared.js +1 -1
- package/dist/utils/node_modules/core-js/internals/shared.js.map +1 -1
- package/dist/utils/node_modules/core-js/internals/well-known-symbol.js +1 -1
- package/dist/utils/node_modules/core-js/internals/well-known-symbol.js.map +1 -1
- package/dist/utils/src/core/utils/appState/store/store.vanillajs.js +1 -1
- package/dist/utils/src/core/utils/appState/store/store.vanillajs.js.map +1 -1
- package/package.json +1 -1
- package/dist/hooks/_virtual/shared.js.map +0 -1
- package/dist/hooks/esm/_virtual/shared.js.map +0 -1
- package/dist/lib/cjs/_virtual/shared.js.map +0 -1
- package/dist/lib/esm/_virtual/shared.js.map +0 -1
- package/dist/ui/_virtual/shared.js.map +0 -1
- package/dist/ui/esm/_virtual/shared.js.map +0 -1
- package/dist/utils/_virtual/shared.js.map +0 -1
- package/dist/utils/esm/_virtual/shared.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sources":["../../../../../../node_modules/core-js/internals/shared.js"],"sourcesContent":["'use strict';\nvar
|
|
1
|
+
{"version":3,"file":"shared.js","sources":["../../../../../../node_modules/core-js/internals/shared.js"],"sourcesContent":["'use strict';\nvar store = require('../internals/shared-store');\n\nmodule.exports = function (key, value) {\n return store[key] || (store[key] = value || {});\n};\n"],"names":["store","require$$0","key","value"],"mappings":"wEACIA,+BAAQC,kCAEK,SAAUC,EAAKC,GAC9B,OAAOH,EAAME,KAASF,EAAME,GAAOC,GAAS,CAAA,EAC9C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./global.js"),r=require("./shared.js"),o=require("./has-own-property.js"),s=require("./uid.js"),t=require("./symbol-constructor-detection.js"),u=require("./use-symbol-as-uid.js"),i=e.global,l=r.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./global.js"),r=require("./shared.js"),o=require("./has-own-property.js"),s=require("./uid.js"),t=require("./symbol-constructor-detection.js"),u=require("./use-symbol-as-uid.js"),i=e.global,l=r.shared,n=o.hasOwnProperty_1,b=s.uid,y=t.symbolConstructorDetection,a=u.useSymbolAsUid,d=i.Symbol,c=l("wks"),j=a?d.for||d:d&&d.withoutSetter||b;exports.wellKnownSymbol=function(e){return n(c,e)||(c[e]=y&&n(d,e)?d[e]:j("Symbol."+e)),c[e]};
|
|
2
2
|
//# sourceMappingURL=well-known-symbol.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"well-known-symbol.js","sources":["../../../../../../node_modules/core-js/internals/well-known-symbol.js"],"sourcesContent":["'use strict';\nvar global = require('../internals/global');\nvar shared = require('../internals/shared');\nvar hasOwn = require('../internals/has-own-property');\nvar uid = require('../internals/uid');\nvar NATIVE_SYMBOL = require('../internals/symbol-constructor-detection');\nvar USE_SYMBOL_AS_UID = require('../internals/use-symbol-as-uid');\n\nvar Symbol = global.Symbol;\nvar WellKnownSymbolsStore = shared('wks');\nvar createWellKnownSymbol = USE_SYMBOL_AS_UID ? Symbol['for'] || Symbol : Symbol && Symbol.withoutSetter || uid;\n\nmodule.exports = function (name) {\n if (!hasOwn(WellKnownSymbolsStore, name)) {\n WellKnownSymbolsStore[name] = NATIVE_SYMBOL && hasOwn(Symbol, name)\n ? Symbol[name]\n : createWellKnownSymbol('Symbol.' + name);\n } return WellKnownSymbolsStore[name];\n};\n"],"names":["global","require$$0","shared","require$$1","hasOwn","require$$2","uid","require$$3","NATIVE_SYMBOL","require$$4","USE_SYMBOL_AS_UID","require$$5","Symbol","WellKnownSymbolsStore","createWellKnownSymbol","withoutSetter","name"],"mappings":"sQACIA,EAASC,EAAAA,OACTC,EAASC,EAAAA,
|
|
1
|
+
{"version":3,"file":"well-known-symbol.js","sources":["../../../../../../node_modules/core-js/internals/well-known-symbol.js"],"sourcesContent":["'use strict';\nvar global = require('../internals/global');\nvar shared = require('../internals/shared');\nvar hasOwn = require('../internals/has-own-property');\nvar uid = require('../internals/uid');\nvar NATIVE_SYMBOL = require('../internals/symbol-constructor-detection');\nvar USE_SYMBOL_AS_UID = require('../internals/use-symbol-as-uid');\n\nvar Symbol = global.Symbol;\nvar WellKnownSymbolsStore = shared('wks');\nvar createWellKnownSymbol = USE_SYMBOL_AS_UID ? Symbol['for'] || Symbol : Symbol && Symbol.withoutSetter || uid;\n\nmodule.exports = function (name) {\n if (!hasOwn(WellKnownSymbolsStore, name)) {\n WellKnownSymbolsStore[name] = NATIVE_SYMBOL && hasOwn(Symbol, name)\n ? Symbol[name]\n : createWellKnownSymbol('Symbol.' + name);\n } return WellKnownSymbolsStore[name];\n};\n"],"names":["global","require$$0","shared","require$$1","hasOwn","require$$2","uid","require$$3","NATIVE_SYMBOL","require$$4","USE_SYMBOL_AS_UID","require$$5","Symbol","WellKnownSymbolsStore","createWellKnownSymbol","withoutSetter","name"],"mappings":"sQACIA,EAASC,EAAAA,OACTC,EAASC,EAAAA,OACTC,EAASC,EAAAA,iBACTC,EAAMC,EAAAA,IACNC,EAAgBC,EAAAA,2BAChBC,EAAoBC,EAAAA,eAEpBC,EAASZ,EAAOY,OAChBC,EAAwBX,EAAO,OAC/BY,EAAwBJ,EAAoBE,EAAY,KAAKA,EAASA,GAAUA,EAAOG,eAAiBT,0BAE3F,SAAUU,GAKvB,OAJGZ,EAAOS,EAAuBG,KACjCH,EAAsBG,GAAQR,GAAiBJ,EAAOQ,EAAQI,GAC1DJ,EAAOI,GACPF,EAAsB,UAAYE,IAC/BH,EAAsBG,EACjC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../../_virtual/_rollupPluginBabelHelpers.js");require("../../../../../node_modules/core-js/modules/web.dom-collections.iterator.js");exports.createStore=(r,t,o)=>{var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../../_virtual/_rollupPluginBabelHelpers.js");require("../../../../../node_modules/core-js/modules/web.dom-collections.iterator.js");exports.createStore=(r,t,o)=>{var s;let l=r;const n=new Set,u=()=>l,c=function(){var r=e.asyncToGenerator((function*(e){l=e;for(const e of n){const r=null==e?void 0:e.selector,t=r?r(l):l;void 0!==e.previousValue&&e.previousValue===t||(e.previousValue=t,yield e(t))}return l}));return function(e){return r.apply(this,arguments)}}(),i={getState:u,setState:c,subscribe:(e,r)=>{if(r&&e.selector&&e.selector!==r)throw new Error("Error, mismatchm selector, listener.selector !== selector.");return r&&!e.selector&&(e.selector=r),n.add(e),()=>n.delete(e)},unsubscribe:e=>{n.delete(e)}},a=t?null===(s=Object.entries(t))||void 0===s?void 0:s.reduce(((r,t)=>{let[s,l]=t;return{...r,[s]:e.asyncToGenerator((function*(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];const n=yield l(u,c,...r);return o&&c(o(u(),s,...r)),n}))}}),{}):null,d={...i,...a?{actions:{...a}}:{}};return d};
|
|
2
2
|
//# sourceMappingURL=store.vanillajs.js.map
|
|
@@ -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\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 * @returns A function to unsubscribe the listener.\n */\n subscribe: (listener: Listener<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/**\n * Represents a store with additional actions.\n */\nexport type StoreWithActions<T> = Store<T> & { actions: { [actionName: string]: ActionHandlerCaller<T> } }\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\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?: Record<string, ActionHandler<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 = () => 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>) => {\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>) => {\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: Record<string, ActionHandlerCaller<T>> | null | undefined\n = actions ? Object.entries(actions)?.reduce(\n (\n aggregator: Record<string, ActionHandlerCaller<T>>,\n [actionName, actionHandler]: [string, ActionHandler<T>],\n ) => ({\n ...aggregator,\n [actionName]: async(...rest: unknown[]) => {\n const resultOfAction = await actionHandler(getState, setState, ...rest)\n\n if (reducer) {\n setState(reducer(getState(), actionName, ...rest))\n }\n return resultOfAction\n },\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 Store<T>\n}\n"],"names":["createStore","initialState","actions","reducer","_Object$entries","currentState","listeners","Set","getState","setState","_ref","_asyncToGenerator","newState","listener","selector","newValue","undefined","previousValue","_x","apply","this","arguments","storeBaseicApi","subscribe","add","delete","unsubscribe","resolvedActions","Object","entries","reduce","aggregator","_ref2","actionName","actionHandler","_len","length","rest","Array","_key","resultOfAction","storeCombinedWithActions"],"mappings":"
|
|
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\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/**\n * Represents a store with additional actions.\n */\nexport type StoreWithActions<T> = Store<T> & { actions: { [actionName: string]: ActionHandlerCaller<T> } }\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\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?: Record<string, ActionHandler<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 = () => 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>) => {\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, mismatchm selector, listener.selector !== selector.')\n }\n if (selector && !listener.selector) {\n // eslint-disable-next-line no-param-reassign\n listener.selector = selector\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: Record<string, ActionHandlerCaller<T>> | null | undefined\n = actions ? Object.entries(actions)?.reduce(\n (\n aggregator: Record<string, ActionHandlerCaller<T>>,\n [actionName, actionHandler]: [string, ActionHandler<T>],\n ) => ({\n ...aggregator,\n [actionName]: async(...rest: unknown[]) => {\n const resultOfAction = await actionHandler(getState, setState, ...rest)\n\n if (reducer) {\n setState(reducer(getState(), actionName, ...rest))\n }\n return resultOfAction\n },\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 Store<T>\n}\n"],"names":["createStore","initialState","actions","reducer","_Object$entries","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","_len","length","rest","Array","_key","resultOfAction","storeCombinedWithActions"],"mappings":"qPA2F2BA,CACzBC,EACAC,EACAC,KACmC,IAAAC,EACnC,IAAIC,EAA2BJ,EAC/B,MAAMK,EAAY,IAAIC,IAMhBC,EAAWA,IAAMH,E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2
|
-
//# sourceMappingURL=shared.js.map
|
|
2
|
+
//# sourceMappingURL=shared-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-store.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as r}from"./to-indexed-object.js";import{t}from"./to-absolute-index.js";import{l as e}from"./length-of-array-like.js";var o=r,i=t,n=e,f=function(r){return function(t,e,f){var a
|
|
1
|
+
import{t as r}from"./to-indexed-object.js";import{t}from"./to-absolute-index.js";import{l as e}from"./length-of-array-like.js";var o=r,i=t,n=e,f=function(r){return function(t,e,f){var a=o(t),s=n(a);if(0===s)return!r&&-1;var u,l=i(f,s);if(r&&e!=e){for(;s>l;)if((u=a[l++])!=u)return!0}else for(;s>l;l++)if((r||l in a)&&a[l]===e)return r||l||0;return!r&&-1}},a={includes:f(!0),indexOf:f(!1)};export{a};
|
|
2
2
|
//# sourceMappingURL=array-includes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-includes.js","sources":["../../../../../../node_modules/core-js/internals/array-includes.js"],"sourcesContent":["'use strict';\nvar toIndexedObject = require('../internals/to-indexed-object');\nvar toAbsoluteIndex = require('../internals/to-absolute-index');\nvar lengthOfArrayLike = require('../internals/length-of-array-like');\n\n// `Array.prototype.{ indexOf, includes }` methods implementation\nvar createMethod = function (IS_INCLUDES) {\n return function ($this, el, fromIndex) {\n var O = toIndexedObject($this);\n var length = lengthOfArrayLike(O);\n var index = toAbsoluteIndex(fromIndex, length);\n var value;\n // Array#includes uses SameValueZero equality algorithm\n // eslint-disable-next-line no-self-compare -- NaN check\n if (IS_INCLUDES && el !== el) while (length > index) {\n value = O[index++];\n // eslint-disable-next-line no-self-compare -- NaN check\n if (value !== value) return true;\n // Array#indexOf ignores holes, Array#includes - not\n } else for (;length > index; index++) {\n if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;\n } return !IS_INCLUDES && -1;\n };\n};\n\nmodule.exports = {\n // `Array.prototype.includes` method\n // https://tc39.es/ecma262/#sec-array.prototype.includes\n includes: createMethod(true),\n // `Array.prototype.indexOf` method\n // https://tc39.es/ecma262/#sec-array.prototype.indexof\n indexOf: createMethod(false)\n};\n"],"names":["toIndexedObject","require$$0","toAbsoluteIndex","require$$1","lengthOfArrayLike","require$$2","createMethod","IS_INCLUDES","$this","el","fromIndex","
|
|
1
|
+
{"version":3,"file":"array-includes.js","sources":["../../../../../../node_modules/core-js/internals/array-includes.js"],"sourcesContent":["'use strict';\nvar toIndexedObject = require('../internals/to-indexed-object');\nvar toAbsoluteIndex = require('../internals/to-absolute-index');\nvar lengthOfArrayLike = require('../internals/length-of-array-like');\n\n// `Array.prototype.{ indexOf, includes }` methods implementation\nvar createMethod = function (IS_INCLUDES) {\n return function ($this, el, fromIndex) {\n var O = toIndexedObject($this);\n var length = lengthOfArrayLike(O);\n if (length === 0) return !IS_INCLUDES && -1;\n var index = toAbsoluteIndex(fromIndex, length);\n var value;\n // Array#includes uses SameValueZero equality algorithm\n // eslint-disable-next-line no-self-compare -- NaN check\n if (IS_INCLUDES && el !== el) while (length > index) {\n value = O[index++];\n // eslint-disable-next-line no-self-compare -- NaN check\n if (value !== value) return true;\n // Array#indexOf ignores holes, Array#includes - not\n } else for (;length > index; index++) {\n if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;\n } return !IS_INCLUDES && -1;\n };\n};\n\nmodule.exports = {\n // `Array.prototype.includes` method\n // https://tc39.es/ecma262/#sec-array.prototype.includes\n includes: createMethod(true),\n // `Array.prototype.indexOf` method\n // https://tc39.es/ecma262/#sec-array.prototype.indexof\n indexOf: createMethod(false)\n};\n"],"names":["toIndexedObject","require$$0","toAbsoluteIndex","require$$1","lengthOfArrayLike","require$$2","createMethod","IS_INCLUDES","$this","el","fromIndex","O","length","value","index","arrayIncludes","includes","indexOf"],"mappings":"+HACA,IAAIA,EAAkBC,EAClBC,EAAkBC,EAClBC,EAAoBC,EAGpBC,EAAe,SAAUC,GAC3B,OAAO,SAAUC,EAAOC,EAAIC,GAC1B,IAAIC,EAAIX,EAAgBQ,GACpBI,EAASR,EAAkBO,GAC/B,GAAe,IAAXC,EAAc,OAAQL,IAAgB,EAC1C,IACIM,EADAC,EAAQZ,EAAgBQ,EAAWE,GAIvC,GAAIL,GAAeE,GAAOA,GAAI,KAAOG,EAASE,GAG5C,IAFAD,EAAQF,EAAEG,OAEID,EAAO,OAAO,OAEvB,KAAMD,EAASE,EAAOA,IAC3B,IAAKP,GAAeO,KAASH,IAAMA,EAAEG,KAAWL,EAAI,OAAOF,GAAeO,GAAS,EACnF,OAAQP,IAAgB,CAC9B,CACA,EAEAQ,EAAiB,CAGfC,SAAUV,GAAa,GAGvBW,QAASX,GAAa"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{g as r}from"./global.js";import{d as
|
|
1
|
+
import{__module as o}from"../../../_virtual/shared-store.js";import{g as r}from"./global.js";import{d as s}from"./define-global-property.js";var e=r,i=s,t="__core-js_shared__",a=o.exports=e[t]||i(t,{});(a.versions||(a.versions=[])).push({version:"3.36.0",mode:"global",copyright:"© 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.36.0/LICENSE",source:"https://github.com/zloirock/core-js"});var l=o.exports;export{l as s};
|
|
2
2
|
//# sourceMappingURL=shared-store.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-store.js","sources":["../../../../../../node_modules/core-js/internals/shared-store.js"],"sourcesContent":["'use strict';\nvar
|
|
1
|
+
{"version":3,"file":"shared-store.js","sources":["../../../../../../node_modules/core-js/internals/shared-store.js"],"sourcesContent":["'use strict';\nvar IS_PURE = require('../internals/is-pure');\nvar globalThis = require('../internals/global');\nvar defineGlobalProperty = require('../internals/define-global-property');\n\nvar SHARED = '__core-js_shared__';\nvar store = module.exports = globalThis[SHARED] || defineGlobalProperty(SHARED, {});\n\n(store.versions || (store.versions = [])).push({\n version: '3.36.0',\n mode: IS_PURE ? 'pure' : 'global',\n copyright: '© 2014-2024 Denis Pushkarev (zloirock.ru)',\n license: 'https://github.com/zloirock/core-js/blob/v3.36.0/LICENSE',\n source: 'https://github.com/zloirock/core-js'\n});\n"],"names":["globalThis","require$$1","defineGlobalProperty","require$$2","SHARED","store","sharedStoreModule","exports","versions","push","version","mode","copyright","license","source"],"mappings":"6IAEA,IAAIA,EAAaC,EACbC,EAAuBC,EAEvBC,EAAS,qBACTC,EAAQC,EAAcC,QAAGP,EAAWI,IAAWF,EAAqBE,EAAQ,CAAA,IAE/EC,EAAMG,WAAaH,EAAMG,SAAW,KAAKC,KAAK,CAC7CC,QAAS,SACTC,KAAyB,SACzBC,UAAW,4CACXC,QAAS,2DACTC,OAAQ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{s as r}from"./shared-store.js";var s=r,o=function(r,o){return s[r]||(s[r]=o||{})};export{o as s};
|
|
2
2
|
//# sourceMappingURL=shared.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sources":["../../../../../../node_modules/core-js/internals/shared.js"],"sourcesContent":["'use strict';\nvar
|
|
1
|
+
{"version":3,"file":"shared.js","sources":["../../../../../../node_modules/core-js/internals/shared.js"],"sourcesContent":["'use strict';\nvar store = require('../internals/shared-store');\n\nmodule.exports = function (key, value) {\n return store[key] || (store[key] = value || {});\n};\n"],"names":["store","require$$0","shared","key","value"],"mappings":"sCACA,IAAIA,EAAQC,EAEZC,EAAiB,SAAUC,EAAKC,GAC9B,OAAOJ,EAAMG,KAASH,EAAMG,GAAOC,GAAS,CAAA,EAC9C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{asyncToGenerator as e}from"../../../../../_virtual/_rollupPluginBabelHelpers.js";import"../../../../../node_modules/core-js/modules/web.dom-collections.iterator.js";const
|
|
1
|
+
import{asyncToGenerator as e}from"../../../../../_virtual/_rollupPluginBabelHelpers.js";import"../../../../../node_modules/core-js/modules/web.dom-collections.iterator.js";const r=(r,t,o)=>{var l;let n=r;const s=new Set,u=()=>n,c=function(){var r=e((function*(e){n=e;for(const e of s){const r=null==e?void 0:e.selector,t=r?r(n):n;void 0!==e.previousValue&&e.previousValue===t||(e.previousValue=t,yield e(t))}return n}));return function(e){return r.apply(this,arguments)}}(),i={getState:u,setState:c,subscribe:(e,r)=>{if(r&&e.selector&&e.selector!==r)throw new Error("Error, mismatchm selector, listener.selector !== selector.");return r&&!e.selector&&(e.selector=r),s.add(e),()=>s.delete(e)},unsubscribe:e=>{s.delete(e)}},a=t?null===(l=Object.entries(t))||void 0===l?void 0:l.reduce(((r,t)=>{let[l,n]=t;return{...r,[l]:e((function*(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];const s=yield n(u,c,...r);return o&&c(o(u(),l,...r)),s}))}}),{}):null,d={...i,...a?{actions:{...a}}:{}};return d};export{r as createStore};
|
|
2
2
|
//# sourceMappingURL=store.vanillajs.js.map
|
|
@@ -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\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 * @returns A function to unsubscribe the listener.\n */\n subscribe: (listener: Listener<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/**\n * Represents a store with additional actions.\n */\nexport type StoreWithActions<T> = Store<T> & { actions: { [actionName: string]: ActionHandlerCaller<T> } }\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\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?: Record<string, ActionHandler<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 = () => 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>) => {\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>) => {\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: Record<string, ActionHandlerCaller<T>> | null | undefined\n = actions ? Object.entries(actions)?.reduce(\n (\n aggregator: Record<string, ActionHandlerCaller<T>>,\n [actionName, actionHandler]: [string, ActionHandler<T>],\n ) => ({\n ...aggregator,\n [actionName]: async(...rest: unknown[]) => {\n const resultOfAction = await actionHandler(getState, setState, ...rest)\n\n if (reducer) {\n setState(reducer(getState(), actionName, ...rest))\n }\n return resultOfAction\n },\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 Store<T>\n}\n"],"names":["createStore","initialState","actions","reducer","_Object$entries","currentState","listeners","Set","getState","setState","_ref","_asyncToGenerator","newState","listener","selector","newValue","undefined","previousValue","_x","apply","this","arguments","storeBaseicApi","subscribe","add","delete","unsubscribe","resolvedActions","Object","entries","reduce","aggregator","_ref2","actionName","actionHandler","_len","length","rest","Array","_key","resultOfAction","storeCombinedWithActions"],"mappings":"
|
|
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\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/**\n * Represents a store with additional actions.\n */\nexport type StoreWithActions<T> = Store<T> & { actions: { [actionName: string]: ActionHandlerCaller<T> } }\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\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?: Record<string, ActionHandler<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 = () => 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>) => {\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, mismatchm selector, listener.selector !== selector.')\n }\n if (selector && !listener.selector) {\n // eslint-disable-next-line no-param-reassign\n listener.selector = selector\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: Record<string, ActionHandlerCaller<T>> | null | undefined\n = actions ? Object.entries(actions)?.reduce(\n (\n aggregator: Record<string, ActionHandlerCaller<T>>,\n [actionName, actionHandler]: [string, ActionHandler<T>],\n ) => ({\n ...aggregator,\n [actionName]: async(...rest: unknown[]) => {\n const resultOfAction = await actionHandler(getState, setState, ...rest)\n\n if (reducer) {\n setState(reducer(getState(), actionName, ...rest))\n }\n return resultOfAction\n },\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 Store<T>\n}\n"],"names":["createStore","initialState","actions","reducer","_Object$entries","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","_len","length","rest","Array","_key","resultOfAction","storeCombinedWithActions"],"mappings":"4KA2FO,MAAMA,EAAcA,CACzBC,EACAC,EACAC,KACmC,IAAAC,EACnC,IAAIC,EAA2B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14 @@ export const createStore = (initialState, actions, reducer) => {
|
|
|
59
59
|
* @param listener - The listener function to be subscribed.
|
|
60
60
|
* @returns A function to unsubscribe the listener.
|
|
61
61
|
*/
|
|
62
|
-
subscribe: (listener) => {
|
|
62
|
+
subscribe: (listener, selector) => {
|
|
63
|
+
if (selector && listener.selector && listener.selector !== selector) {
|
|
64
|
+
throw new Error('Error, mismatchm selector, listener.selector !== selector.');
|
|
65
|
+
}
|
|
66
|
+
if (selector && !listener.selector) {
|
|
67
|
+
// eslint-disable-next-line no-param-reassign
|
|
68
|
+
listener.selector = selector;
|
|
69
|
+
}
|
|
63
70
|
listeners.add(listener);
|
|
64
71
|
return () => listeners.delete(listener);
|
|
65
72
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.vanillajs.js","sourceRoot":"","sources":["../../../../../../../src/core/utils/appState/store/store.vanillajs.ts"],"names":[],"mappings":"AACA,+FAA+F;
|
|
1
|
+
{"version":3,"file":"store.vanillajs.js","sourceRoot":"","sources":["../../../../../../../src/core/utils/appState/store/store.vanillajs.ts"],"names":[],"mappings":"AACA,+FAA+F;AAoF/F;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,YAAwB,EACxB,OAA0C,EAC1C,OAAoB,EACY,EAAE;IAClC,IAAI,YAAY,GAAe,YAAY,CAAA;IAC3C,MAAM,SAAS,GAAG,IAAI,GAAG,EAAe,CAAA;IAExC;;;OAGG;IACH,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,YAAY,CAAA;IAEnC,kHAAkH;IAClH;;;;OAIG;IACH,MAAM,QAAQ,GAAG,KAAK,EAAE,QAAoB,EAAE,EAAE;QAC9C,YAAY,GAAG,QAAQ,CAAA;QAEvB,gDAAgD;QAChD,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;YAChC,yBAAyB;YACzB,MAAM,QAAQ,GAA4B,QAAQ,EAAE,QAAQ,CAAA;YAE5D,oFAAoF;YACpF,+DAA+D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