UNPKG

@ngxs/store

Version:
1 lines 4.78 kB
{"version":3,"file":"ngxs-store-plugins.mjs","sources":["../../../packages/store/plugins/src/actions.ts","../../../packages/store/plugins/src/symbols.ts","../../../packages/store/plugins/src/utils.ts","../../../packages/store/plugins/src/ngxs-store-plugins.ts"],"sourcesContent":["import { ɵPlainObject } from '@ngxs/store/internals';\n\n/**\n * Init action\n */\nexport class InitState {\n static readonly type = '@@INIT';\n}\n\n/**\n * Update action\n */\nexport class UpdateState {\n static readonly type = '@@UPDATE_STATE';\n\n constructor(readonly addedStates?: ɵPlainObject) {}\n}\n","import { InjectionToken, Type } from '@angular/core';\n\ndeclare const ngDevMode: boolean;\n\nexport type NgxsNextPluginFn = (state: any, action: any) => any;\n\nexport type NgxsPluginFn = (state: any, action: any, next: NgxsNextPluginFn) => any;\n\n/**\n * Plugin interface\n */\nexport interface NgxsPlugin {\n /**\n * Handle the state/action before its submitted to the state handlers.\n */\n handle(state: any, action: any, next: NgxsNextPluginFn): any;\n}\n\n/**\n * A multi-provider token used to resolve to custom NGXS plugins provided\n * at the root and feature levels through the `{provide}` scheme.\n *\n * @deprecated from v18.0.0, use `withNgxsPlugin` instead.\n */\nexport const NGXS_PLUGINS = /* @__PURE__ */ new InjectionToken<NgxsPlugin[]>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_PLUGINS' : ''\n);\n\nexport function ɵisPluginClass(\n plugin: Type<NgxsPlugin> | NgxsPluginFn\n): plugin is Type<NgxsPlugin> {\n // Determines whether the provided value is a class rather than a function.\n // If it’s a class, its handle method should be defined on its prototype,\n // as plugins can be either classes or functions.\n return !!plugin.prototype.handle;\n}\n","/**\n * Returns the type from an action instance/class.\n * @ignore\n */\nexport function getActionTypeFromInstance(action: any): string | undefined {\n return action.constructor?.type || action.type;\n}\n\n/**\n * Matches a action\n * @ignore\n */\nexport function actionMatcher(action1: any) {\n const type1 = getActionTypeFromInstance(action1);\n\n return function (action2: any) {\n return type1 === getActionTypeFromInstance(action2);\n };\n}\n\n/**\n * Set a deeply nested value. Example:\n *\n * setValue({ foo: { bar: { eat: false } } },\n * 'foo.bar.eat', true) //=> { foo: { bar: { eat: true } } }\n *\n * While it traverses it also creates new objects from top down.\n *\n * @ignore\n */\nexport const setValue = (obj: any, prop: string, val: any) => {\n obj = { ...obj };\n\n const split = prop.split('.');\n const lastIndex = split.length - 1;\n\n split.reduce((acc, part, index) => {\n if (index === lastIndex) {\n acc[part] = val;\n } else {\n acc[part] = Array.isArray(acc[part]) ? acc[part].slice() : { ...acc[part] };\n }\n\n return acc?.[part];\n }, obj);\n\n return obj;\n};\n\n/**\n * Get a deeply nested value. Example:\n *\n * getValue({ foo: bar: [] }, 'foo.bar') //=> []\n *\n * @ignore\n */\nexport const getValue = (obj: any, prop: string): any =>\n prop.split('.').reduce((acc: any, part: string) => acc?.[part], obj);\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;AAEA;;AAEG;MACU,SAAS,CAAA;AACpB,IAAA,OAAgB,IAAI,GAAG,QAAQ;;AAGjC;;AAEG;MACU,WAAW,CAAA;AAGD,IAAA,WAAA;AAFrB,IAAA,OAAgB,IAAI,GAAG,gBAAgB;AAEvC,IAAA,WAAA,CAAqB,WAA0B,EAAA;QAA1B,IAAW,CAAA,WAAA,GAAX,WAAW;;;;ACGlC;;;;;AAKG;AACU,MAAA,YAAY,mBAAmB,IAAI,cAAc,CAC5D,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,GAAG,cAAc,GAAG,EAAE;AAG/D,SAAU,cAAc,CAC5B,MAAuC,EAAA;;;;AAKvC,IAAA,OAAO,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM;AAClC;;ACnCA;;;AAGG;AACG,SAAU,yBAAyB,CAAC,MAAW,EAAA;IACnD,OAAO,MAAM,CAAC,WAAW,EAAE,IAAI,IAAI,MAAM,CAAC,IAAI;AAChD;AAEA;;;AAGG;AACG,SAAU,aAAa,CAAC,OAAY,EA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