@ngxs/store 19.0.0-dev.master-179a5bb → 19.0.0-dev.master-6b0346e
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.
|
@@ -4,7 +4,7 @@ import { ɵgetDOM as _getDOM, BrowserModule, ɵBrowserDomAdapter as _BrowserDomA
|
|
|
4
4
|
import * as i0 from '@angular/core';
|
|
5
5
|
import { destroyPlatform, VERSION, createPlatform, Component, NgModule, ApplicationRef, provideEnvironmentInitializer, inject, DestroyRef, Injectable } from '@angular/core';
|
|
6
6
|
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
|
|
7
|
-
import { NgxsModule, Store, Actions } from '@ngxs/store';
|
|
7
|
+
import { NgxsModule, Store, Actions, ActionStatus } from '@ngxs/store';
|
|
8
8
|
import { ReplaySubject, Subject, takeUntil } from 'rxjs';
|
|
9
9
|
|
|
10
10
|
function createRootElement() {
|
|
@@ -230,18 +230,18 @@ class NgxsActionCollector {
|
|
|
230
230
|
this._actions$.pipe(takeUntil(this._destroyed$), takeUntil(this._stopped$)).subscribe({
|
|
231
231
|
next: (ctx) => {
|
|
232
232
|
switch (ctx?.status) {
|
|
233
|
-
case
|
|
233
|
+
case ActionStatus.Dispatched:
|
|
234
234
|
this.dispatched.push(ctx.action);
|
|
235
235
|
break;
|
|
236
|
-
case
|
|
236
|
+
case ActionStatus.Successful:
|
|
237
237
|
this.successful.push(ctx.action);
|
|
238
238
|
this.completed.push(ctx.action);
|
|
239
239
|
break;
|
|
240
|
-
case
|
|
240
|
+
case ActionStatus.Errored:
|
|
241
241
|
this.errored.push(ctx.action);
|
|
242
242
|
this.completed.push(ctx.action);
|
|
243
243
|
break;
|
|
244
|
-
case
|
|
244
|
+
case ActionStatus.Canceled:
|
|
245
245
|
this.cancelled.push(ctx.action);
|
|
246
246
|
this.completed.push(ctx.action);
|
|
247
247
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngxs-store-internals-testing.mjs","sources":["../../../packages/store/internals/testing/src/fresh-platform.ts","../../../packages/store/internals/testing/src/helpers/ngxs-test.component.ts","../../../packages/store/internals/testing/src/helpers/ngxs-test.module.ts","../../../packages/store/internals/testing/src/skip-console-logging.ts","../../../packages/store/internals/testing/src/ngxs.setup.ts","../../../packages/store/internals/testing/src/action-collector.ts","../../../packages/store/internals/testing/src/ngxs-store-internals-testing.ts"],"sourcesContent":["import { TestBed } from '@angular/core/testing';\nimport { DOCUMENT } from '@angular/common';\nimport { ɵgetDOM as getDOM } from '@angular/platform-browser';\nimport { VERSION, destroyPlatform, createPlatform } from '@angular/core';\n\nfunction createRootElement() {\n const document = TestBed.inject(DOCUMENT);\n const root = getDOM().createElement('app-root', document);\n document.body.appendChild(root);\n}\n\nfunction removeRootElement() {\n const root: Element = document.getElementsByTagName('app-root').item(0)!;\n try {\n document.body.removeChild(root);\n } catch {}\n}\n\nfunction destroyPlatformBeforeBootstrappingTheNewOne(freshUrl: string) {\n destroyPlatform();\n resetLocationToUrl(freshUrl);\n createRootElement();\n}\n\n// As we create our custom platform via `bootstrapModule`\n// we have to destroy it after assetions and revert\n// the previous one\nfunction resetPlatformAfterBootstrapping() {\n removeRootElement();\n destroyPlatform();\n const version = +VERSION.major;\n // https://github.com/angular/angular/commit/e250db4f261741b04ee4cbad4dec41a8908a12aa\n if (version < 14) {\n createPlatform(TestBed);\n }\n}\n\nfunction resetLocationToUrl(freshUrl: string) {\n window.history.replaceState({}, 'Test', freshUrl);\n}\n\nexport function freshPlatform(fn: (done?: VoidFunction) => Promise<void>) {\n let resolve: VoidFunction | null = null;\n let reject: ((error: Error) => void) | null = null;\n let whenDoneIsCalledPromise: Promise<void> | null = null;\n\n const hasDoneArgument = fn.length === 1;\n\n if (hasDoneArgument) {\n whenDoneIsCalledPromise = new Promise<void>((_resolve, _reject) => {\n resolve = _resolve;\n reject = _reject;\n });\n }\n\n return async function testWithAFreshPlatform() {\n try {\n const freshUrl = '/';\n destroyPlatformBeforeBootstrappingTheNewOne(freshUrl);\n\n if (hasDoneArgument) {\n await fn((error?: Error) => {\n if (error) {\n reject!(error);\n } else {\n resolve!();\n }\n });\n await whenDoneIsCalledPromise!;\n } else {\n await fn();\n }\n } finally {\n resetPlatformAfterBootstrapping();\n }\n };\n}\n","import { AfterViewInit, Component, OnInit } from '@angular/core';\n\n@Component({\n selector: 'app-root',\n template: ''\n})\nexport class NgxsTestComponent implements OnInit, AfterViewInit {\n public ngOnInit(): void {}\n public ngAfterViewInit(): void {}\n}\n","import { ApplicationRef, NgModule } from '@angular/core';\nimport { BrowserModule } from '@angular/platform-browser';\n\nimport { NgxsTestComponent } from './ngxs-test.component';\n\n@NgModule({\n imports: [BrowserModule, NgxsTestComponent]\n})\nexport class NgxsTestModule {\n public static ngDoBootstrap(app: ApplicationRef): void {\n app.bootstrap(NgxsTestComponent);\n }\n}\n","export type ConsoleRecord = [string, any[]];\nexport type ConsoleRecorder = ConsoleRecord[];\n\nexport function loggedError(message: string): ConsoleRecord {\n return ['error', [expect.objectContaining({ message })]];\n}\n\nexport function skipConsoleLogging<T extends (...args: any[]) => any>(\n fn: T,\n consoleRecorder: ConsoleRecorder = []\n): ReturnType<T> {\n const consoleSpies = [\n jest.spyOn(console, 'log').mockImplementation((...args) => {\n consoleRecorder.push(['log', args]);\n }),\n jest.spyOn(console, 'warn').mockImplementation((...args) => {\n consoleRecorder.push(['warn', args]);\n }),\n jest.spyOn(console, 'error').mockImplementation((...args) => {\n consoleRecorder.push(['error', args]);\n }),\n jest.spyOn(console, 'info').mockImplementation((...args) => {\n consoleRecorder.push(['info', args]);\n })\n ];\n function restoreSpies() {\n consoleSpies.forEach(spy => spy.mockRestore());\n }\n let restoreSpyAsync = false;\n try {\n const returnValue = fn();\n if (returnValue instanceof Promise) {\n restoreSpyAsync = true;\n return returnValue.finally(() => restoreSpies()) as ReturnType<T>;\n }\n return returnValue;\n } finally {\n if (!restoreSpyAsync) {\n restoreSpies();\n }\n }\n}\n","import { ApplicationRef } from '@angular/core';\nimport { TestBed, TestBedStatic } from '@angular/core/testing';\nimport { DOCUMENT } from '@angular/common';\nimport { ɵBrowserDomAdapter as BrowserDomAdapter } from '@angular/platform-browser';\nimport {\n BrowserDynamicTestingModule,\n platformBrowserDynamicTesting\n} from '@angular/platform-browser-dynamic/testing';\nimport { NgxsModule, Store } from '@ngxs/store';\n\nimport { NgxsTestModule } from './helpers/ngxs-test.module';\nimport { NgxsOptionsTesting, NgxsTesting } from './symbol';\nimport { skipConsoleLogging } from './skip-console-logging';\n\nexport class NgxsTestBed {\n public static configureTestingStates(options: NgxsOptionsTesting): NgxsTesting {\n this.resetTestBed();\n\n if (options.before) {\n options.before();\n }\n\n skipConsoleLogging(() =>\n TestBed.configureTestingModule({\n imports: [\n NgxsTestModule,\n NgxsModule.forRoot(options.states || [], options.ngxsOptions || {}),\n ...(options.imports || [])\n ]\n }).compileComponents()\n );\n\n NgxsTestBed.ngxsBootstrap();\n\n return {\n get store(): Store {\n return TestBed.inject(Store);\n },\n get getTestBed(): TestBedStatic {\n return TestBed;\n }\n };\n }\n\n private static ngxsBootstrap(): void {\n NgxsTestBed.createRootNode();\n NgxsTestModule.ngDoBootstrap(TestBed.inject(ApplicationRef));\n }\n\n private static resetTestBed(): void {\n TestBed.resetTestEnvironment();\n TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), {\n teardown: { destroyAfterEach: true }\n });\n }\n\n private static createRootNode(selector = 'app-root'): void {\n const document = TestBed.inject(DOCUMENT);\n const adapter = new BrowserDomAdapter();\n const root = adapter.createElement(selector);\n document.body.appendChild(root);\n }\n}\n","import {\n DestroyRef,\n EnvironmentProviders,\n inject,\n Injectable,\n provideEnvironmentInitializer\n} from '@angular/core';\nimport { Actions, ActionStatus, type ActionContext } from '@ngxs/store';\nimport { ReplaySubject, Subject, takeUntil } from 'rxjs';\n\n@Injectable({ providedIn: 'root' })\nexport class NgxsActionCollector {\n /**\n * Including this in your providers will\n * set up the the action collector to start collecting actions\n * from before NGXS initializes\n * @example\n * // In your providers declaration for your tests:\n * {\n * providers: [\n * NgxsActionCollector.collectActions(),\n * provideStore([MyState]),\n * ],\n * // ...\n * }\n * // and then in your test:\n * const actionCollector = TestBed.inject(NgxsActionCollector);\n * const actionsDispatched = actionCollector.dispatched;\n * const action = actionsDispatched.find(\n * (item) => item instanceof MyAction\n * );\n * expect(action).toBeDefined();\n * @returns An environment initializer that starts the collector immediately\n */\n static collectActions(): EnvironmentProviders {\n return provideEnvironmentInitializer(() => {\n inject(NgxsActionCollector).start();\n });\n }\n\n private _destroyed$ = new ReplaySubject<void>(1);\n private _stopped$ = new Subject<void>();\n private _started = false;\n\n readonly dispatched: any[] = [];\n readonly completed: any[] = [];\n readonly successful: any[] = [];\n readonly errored: any[] = [];\n readonly cancelled: any[] = [];\n\n private _actions$ = inject(Actions);\n\n constructor() {\n inject(DestroyRef).onDestroy(() => this._destroyed$.next());\n }\n\n start() {\n if (this._started) {\n return;\n }\n this._started = true;\n this._actions$.pipe(takeUntil(this._destroyed$), takeUntil(this._stopped$)).subscribe({\n next: (ctx: ActionContext) => {\n switch (ctx?.status) {\n case ActionStatus.Dispatched:\n this.dispatched.push(ctx.action);\n break;\n case ActionStatus.Successful:\n this.successful.push(ctx.action);\n this.completed.push(ctx.action);\n break;\n case ActionStatus.Errored:\n this.errored.push(ctx.action);\n this.completed.push(ctx.action);\n break;\n case ActionStatus.Canceled:\n this.cancelled.push(ctx.action);\n this.completed.push(ctx.action);\n break;\n default:\n break;\n }\n },\n complete: () => {\n this._started = false;\n },\n error: () => {\n this._started = false;\n }\n });\n }\n\n reset() {\n function clearArray(array: any[]) {\n array.splice(0, array.length);\n }\n clearArray(this.dispatched);\n clearArray(this.completed);\n clearArray(this.successful);\n clearArray(this.errored);\n clearArray(this.cancelled);\n }\n\n stop() {\n this._stopped$.next();\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["getDO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GAAG,KAAK;aACtB;YACD,KAAK,EAAE,MAAK;AACV,gBAAA,IAAI,CAAC,QAAQ,GAAG,KAAK;;AAExB,SAAA,CAAC;;IAGJ,KAAK,GAAA;QACH,SAAS,UAAU,CAAC,KAAY,EAAA;YAC9B,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC;;AAE/B,QAAA,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC;AAC3B,QAAA,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;AAC1B,QAAA,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC;AAC3B,QAAA,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC;AACxB,QAAA,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;;IAG5B,IAAI,GAAA;AACF,QAAA,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE;;iIA7FZ,mBAAmB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;AAAnB,uBAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,mBAAmB,cADN,MAAM,EAAA,CAAA,CAAA;;2FACnB,mBAAmB,EAAA,UAAA,EAAA,CAAA;kBAD/B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACVlC;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"ngxs-store-internals-testing.mjs","sources":["../../../packages/store/internals/testing/src/fresh-platform.ts","../../../packages/store/internals/testing/src/helpers/ngxs-test.component.ts","../../../packages/store/internals/testing/src/helpers/ngxs-test.module.ts","../../../packages/store/internals/testing/src/skip-console-logging.ts","../../../packages/store/internals/testing/src/ngxs.setup.ts","../../../packages/store/internals/testing/src/action-collector.ts","../../../packages/store/internals/testing/src/ngxs-store-internals-testing.ts"],"sourcesContent":["import { TestBed } from '@angular/core/testing';\nimport { DOCUMENT } from '@angular/common';\nimport { ɵgetDOM as getDOM } from '@angular/platform-browser';\nimport { VERSION, destroyPlatform, createPlatform } from '@angular/core';\n\nfunction createRootElement() {\n const document = TestBed.inject(DOCUMENT);\n const root = getDOM().createElement('app-root', document);\n document.body.appendChild(root);\n}\n\nfunction removeRootElement() {\n const root: Element = document.getElementsByTagName('app-root').item(0)!;\n try {\n document.body.removeChild(root);\n } catch {}\n}\n\nfunction destroyPlatformBeforeBootstrappingTheNewOne(freshUrl: string) {\n destroyPlatform();\n resetLocationToUrl(freshUrl);\n createRootElement();\n}\n\n// As we create our custom platform via `bootstrapModule`\n// we have to destroy it after assetions and revert\n// the previous one\nfunction resetPlatformAfterBootstrapping() {\n removeRootElement();\n destroyPlatform();\n const version = +VERSION.major;\n // https://github.com/angular/angular/commit/e250db4f261741b04ee4cbad4dec41a8908a12aa\n if (version < 14) {\n createPlatform(TestBed);\n }\n}\n\nfunction resetLocationToUrl(freshUrl: string) {\n window.history.replaceState({}, 'Test', freshUrl);\n}\n\nexport function freshPlatform(fn: (done?: VoidFunction) => Promise<void>) {\n let resolve: VoidFunction | null = null;\n let reject: ((error: Error) => void) | null = null;\n let whenDoneIsCalledPromise: Promise<void> | null = null;\n\n const hasDoneArgument = fn.length === 1;\n\n if (hasDoneArgument) {\n whenDoneIsCalledPromise = new Promise<void>((_resolve, _reject) => {\n resolve = _resolve;\n reject = _reject;\n });\n }\n\n return async function testWithAFreshPlatform() {\n try {\n const freshUrl = '/';\n destroyPlatformBeforeBootstrappingTheNewOne(freshUrl);\n\n if (hasDoneArgument) {\n await fn((error?: Error) => {\n if (error) {\n reject!(error);\n } else {\n resolve!();\n }\n });\n await whenDoneIsCalledPromise!;\n } else {\n await fn();\n }\n } finally {\n resetPlatformAfterBootstrapping();\n }\n };\n}\n","import { AfterViewInit, Component, OnInit } from '@angular/core';\n\n@Component({\n selector: 'app-root',\n template: ''\n})\nexport class NgxsTestComponent implements OnInit, AfterViewInit {\n public ngOnInit(): void {}\n public ngAfterViewInit(): void {}\n}\n","import { ApplicationRef, NgModule } from '@angular/core';\nimport { BrowserModule } from '@angular/platform-browser';\n\nimport { NgxsTestComponent } from './ngxs-test.component';\n\n@NgModule({\n imports: [BrowserModule, NgxsTestComponent]\n})\nexport class NgxsTestModule {\n public static ngDoBootstrap(app: ApplicationRef): void {\n app.bootstrap(NgxsTestComponent);\n }\n}\n","export type ConsoleRecord = [string, any[]];\nexport type ConsoleRecorder = ConsoleRecord[];\n\nexport function loggedError(message: string): ConsoleRecord {\n return ['error', [expect.objectContaining({ message })]];\n}\n\nexport function skipConsoleLogging<T extends (...args: any[]) => any>(\n fn: T,\n consoleRecorder: ConsoleRecorder = []\n): ReturnType<T> {\n const consoleSpies = [\n jest.spyOn(console, 'log').mockImplementation((...args) => {\n consoleRecorder.push(['log', args]);\n }),\n jest.spyOn(console, 'warn').mockImplementation((...args) => {\n consoleRecorder.push(['warn', args]);\n }),\n jest.spyOn(console, 'error').mockImplementation((...args) => {\n consoleRecorder.push(['error', args]);\n }),\n jest.spyOn(console, 'info').mockImplementation((...args) => {\n consoleRecorder.push(['info', args]);\n })\n ];\n function restoreSpies() {\n consoleSpies.forEach(spy => spy.mockRestore());\n }\n let restoreSpyAsync = false;\n try {\n const returnValue = fn();\n if (returnValue instanceof Promise) {\n restoreSpyAsync = true;\n return returnValue.finally(() => restoreSpies()) as ReturnType<T>;\n }\n return returnValue;\n } finally {\n if (!restoreSpyAsync) {\n restoreSpies();\n }\n }\n}\n","import { ApplicationRef } from '@angular/core';\nimport { TestBed, TestBedStatic } from '@angular/core/testing';\nimport { DOCUMENT } from '@angular/common';\nimport { ɵBrowserDomAdapter as BrowserDomAdapter } from '@angular/platform-browser';\nimport {\n BrowserDynamicTestingModule,\n platformBrowserDynamicTesting\n} from '@angular/platform-browser-dynamic/testing';\nimport { NgxsModule, Store } from '@ngxs/store';\n\nimport { NgxsTestModule } from './helpers/ngxs-test.module';\nimport { NgxsOptionsTesting, NgxsTesting } from './symbol';\nimport { skipConsoleLogging } from './skip-console-logging';\n\nexport class NgxsTestBed {\n public static configureTestingStates(options: NgxsOptionsTesting): NgxsTesting {\n this.resetTestBed();\n\n if (options.before) {\n options.before();\n }\n\n skipConsoleLogging(() =>\n TestBed.configureTestingModule({\n imports: [\n NgxsTestModule,\n NgxsModule.forRoot(options.states || [], options.ngxsOptions || {}),\n ...(options.imports || [])\n ]\n }).compileComponents()\n );\n\n NgxsTestBed.ngxsBootstrap();\n\n return {\n get store(): Store {\n return TestBed.inject(Store);\n },\n get getTestBed(): TestBedStatic {\n return TestBed;\n }\n };\n }\n\n private static ngxsBootstrap(): void {\n NgxsTestBed.createRootNode();\n NgxsTestModule.ngDoBootstrap(TestBed.inject(ApplicationRef));\n }\n\n private static resetTestBed(): void {\n TestBed.resetTestEnvironment();\n TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), {\n teardown: { destroyAfterEach: true }\n });\n }\n\n private static createRootNode(selector = 'app-root'): void {\n const document = TestBed.inject(DOCUMENT);\n const adapter = new BrowserDomAdapter();\n const root = adapter.createElement(selector);\n document.body.appendChild(root);\n }\n}\n","import {\n DestroyRef,\n EnvironmentProviders,\n inject,\n Injectable,\n provideEnvironmentInitializer\n} from '@angular/core';\nimport { Actions, ActionStatus, type ActionContext } from '@ngxs/store';\nimport { ReplaySubject, Subject, takeUntil } from 'rxjs';\n\n@Injectable({ providedIn: 'root' })\nexport class NgxsActionCollector {\n /**\n * Including this in your providers will\n * set up the the action collector to start collecting actions\n * from before NGXS initializes\n * @example\n * // In your providers declaration for your tests:\n * {\n * providers: [\n * NgxsActionCollector.collectActions(),\n * provideStore([MyState]),\n * ],\n * // ...\n * }\n * // and then in your test:\n * const actionCollector = TestBed.inject(NgxsActionCollector);\n * const actionsDispatched = actionCollector.dispatched;\n * const action = actionsDispatched.find(\n * (item) => item instanceof MyAction\n * );\n * expect(action).toBeDefined();\n * @returns An environment initializer that starts the collector immediately\n */\n static collectActions(): EnvironmentProviders {\n return provideEnvironmentInitializer(() => {\n inject(NgxsActionCollector).start();\n });\n }\n\n private _destroyed$ = new ReplaySubject<void>(1);\n private _stopped$ = new Subject<void>();\n private _started = false;\n\n readonly dispatched: any[] = [];\n readonly completed: any[] = [];\n readonly successful: any[] = [];\n readonly errored: any[] = [];\n readonly cancelled: any[] = [];\n\n private _actions$ = inject(Actions);\n\n constructor() {\n inject(DestroyRef).onDestroy(() => this._destroyed$.next());\n }\n\n start() {\n if (this._started) {\n return;\n }\n this._started = true;\n this._actions$.pipe(takeUntil(this._destroyed$), takeUntil(this._stopped$)).subscribe({\n next: (ctx: ActionContext) => {\n switch (ctx?.status) {\n case ActionStatus.Dispatched:\n this.dispatched.push(ctx.action);\n break;\n case ActionStatus.Successful:\n this.successful.push(ctx.action);\n this.completed.push(ctx.action);\n break;\n case ActionStatus.Errored:\n this.errored.push(ctx.action);\n this.completed.push(ctx.action);\n break;\n case ActionStatus.Canceled:\n this.cancelled.push(ctx.action);\n this.completed.push(ctx.action);\n break;\n default:\n break;\n }\n },\n complete: () => {\n this._started = false;\n },\n error: () => {\n this._started = false;\n }\n });\n }\n\n reset() {\n function clearArray(array: any[]) {\n array.splice(0, array.length);\n }\n clearArray(this.dispatched);\n clearArray(this.completed);\n clearArray(this.successful);\n clearArray(this.errored);\n clearArray(this.cancelled);\n }\n\n stop() {\n this._stopped$.next();\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["getDOM","BrowserDomAdapter"],"mappings":";;;;;;;;;AAKA,SAAS,iBAAiB,GAAA;IACxB,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC;IACzC,MAAM,IAAI,GAAGA,OAAM,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,QAAQ,CAAC;AACzD,IAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IA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AC;;AAE/B,QAAA,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC;AAC3B,QAAA,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;AAC1B,QAAA,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC;AAC3B,QAAA,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC;AACxB,QAAA,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;;IAG5B,IAAI,GAAA;AACF,QAAA,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE;;iIA7FZ,mBAAmB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;AAAnB,uBAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,mBAAmB,cADN,MAAM,EAAA,CAAA,CAAA;;2FACnB,mBAAmB,EAAA,UAAA,EAAA,CAAA;kBAD/B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACVlC;;AAEG;;;;"}
|
package/fesm2022/ngxs-store.mjs
CHANGED
|
@@ -173,6 +173,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImpor
|
|
|
173
173
|
args: [{ providedIn: 'root' }]
|
|
174
174
|
}] });
|
|
175
175
|
|
|
176
|
+
/**
|
|
177
|
+
* Status of a dispatched action
|
|
178
|
+
*/
|
|
179
|
+
const ActionStatus = {
|
|
180
|
+
Dispatched: 'DISPATCHED',
|
|
181
|
+
Successful: 'SUCCESSFUL',
|
|
182
|
+
Canceled: 'CANCELED',
|
|
183
|
+
Errored: 'ERRORED'
|
|
184
|
+
};
|
|
176
185
|
/**
|
|
177
186
|
* Internal Action stream that is emitted anytime an action is dispatched.
|
|
178
187
|
*/
|
|
@@ -183,7 +192,7 @@ class InternalActions extends _OrderedSubject {
|
|
|
183
192
|
// any logic that must be executed before action handlers are invoked (i.e., cancelation).
|
|
184
193
|
this.dispatched$ = new Subject();
|
|
185
194
|
this.subscribe(ctx => {
|
|
186
|
-
if (ctx.status ===
|
|
195
|
+
if (ctx.status === ActionStatus.Dispatched) {
|
|
187
196
|
this.dispatched$.next(ctx);
|
|
188
197
|
}
|
|
189
198
|
});
|
|
@@ -280,22 +289,22 @@ class InternalDispatcher {
|
|
|
280
289
|
}
|
|
281
290
|
const actionResult$ = this.getActionResultStream(nextAction);
|
|
282
291
|
actionResult$.subscribe(ctx => this._actions.next(ctx));
|
|
283
|
-
this._actions.next({ action: nextAction, status:
|
|
292
|
+
this._actions.next({ action: nextAction, status: ActionStatus.Dispatched });
|
|
284
293
|
return this.createDispatchObservable(actionResult$);
|
|
285
294
|
}
|
|
286
295
|
])(prevState, action).pipe(shareReplay());
|
|
287
296
|
}
|
|
288
297
|
getActionResultStream(action) {
|
|
289
|
-
return this._actionResults.pipe(filter((ctx) => ctx.action === action && ctx.status !==
|
|
298
|
+
return this._actionResults.pipe(filter((ctx) => ctx.action === action && ctx.status !== ActionStatus.Dispatched), take(1), shareReplay());
|
|
290
299
|
}
|
|
291
300
|
createDispatchObservable(actionResult$) {
|
|
292
301
|
return actionResult$.pipe(mergeMap((ctx) => {
|
|
293
302
|
switch (ctx.status) {
|
|
294
|
-
case
|
|
303
|
+
case ActionStatus.Successful:
|
|
295
304
|
// The `createDispatchObservable` function should return the
|
|
296
305
|
// state, as its result is used by plugins.
|
|
297
306
|
return of(this._stateStream.getValue());
|
|
298
|
-
case
|
|
307
|
+
case ActionStatus.Errored:
|
|
299
308
|
throw ctx.error;
|
|
300
309
|
default:
|
|
301
310
|
// Once dispatched or canceled, we complete it immediately because
|
|
@@ -1034,7 +1043,7 @@ function ofAction(...allowedTypes) {
|
|
|
1034
1043
|
* This will ONLY grab actions that have just been dispatched
|
|
1035
1044
|
*/
|
|
1036
1045
|
function ofActionDispatched(...allowedTypes) {
|
|
1037
|
-
return ofActionOperator(allowedTypes, [
|
|
1046
|
+
return ofActionOperator(allowedTypes, [ActionStatus.Dispatched]);
|
|
1038
1047
|
}
|
|
1039
1048
|
/**
|
|
1040
1049
|
* RxJS operator for selecting out specific actions.
|
|
@@ -1042,7 +1051,7 @@ function ofActionDispatched(...allowedTypes) {
|
|
|
1042
1051
|
* This will ONLY grab actions that have just been successfully completed
|
|
1043
1052
|
*/
|
|
1044
1053
|
function ofActionSuccessful(...allowedTypes) {
|
|
1045
|
-
return ofActionOperator(allowedTypes, [
|
|
1054
|
+
return ofActionOperator(allowedTypes, [ActionStatus.Successful]);
|
|
1046
1055
|
}
|
|
1047
1056
|
/**
|
|
1048
1057
|
* RxJS operator for selecting out specific actions.
|
|
@@ -1050,7 +1059,7 @@ function ofActionSuccessful(...allowedTypes) {
|
|
|
1050
1059
|
* This will ONLY grab actions that have just been canceled
|
|
1051
1060
|
*/
|
|
1052
1061
|
function ofActionCanceled(...allowedTypes) {
|
|
1053
|
-
return ofActionOperator(allowedTypes, [
|
|
1062
|
+
return ofActionOperator(allowedTypes, [ActionStatus.Canceled]);
|
|
1054
1063
|
}
|
|
1055
1064
|
/**
|
|
1056
1065
|
* RxJS operator for selecting out specific actions.
|
|
@@ -1059,9 +1068,9 @@ function ofActionCanceled(...allowedTypes) {
|
|
|
1059
1068
|
*/
|
|
1060
1069
|
function ofActionCompleted(...allowedTypes) {
|
|
1061
1070
|
const allowedStatuses = [
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1071
|
+
ActionStatus.Successful,
|
|
1072
|
+
ActionStatus.Canceled,
|
|
1073
|
+
ActionStatus.Errored
|
|
1065
1074
|
];
|
|
1066
1075
|
return ofActionOperator(allowedTypes, allowedStatuses, mapActionResult);
|
|
1067
1076
|
}
|
|
@@ -1071,7 +1080,7 @@ function ofActionCompleted(...allowedTypes) {
|
|
|
1071
1080
|
* This will ONLY grab actions that have just thrown an error
|
|
1072
1081
|
*/
|
|
1073
1082
|
function ofActionErrored(...allowedTypes) {
|
|
1074
|
-
return ofActionOperator(allowedTypes, [
|
|
1083
|
+
return ofActionOperator(allowedTypes, [ActionStatus.Errored], mapActionResult);
|
|
1075
1084
|
}
|
|
1076
1085
|
function ofActionOperator(allowedTypes, statuses,
|
|
1077
1086
|
// This could have been written as
|
|
@@ -1099,8 +1108,8 @@ function mapActionResult() {
|
|
|
1099
1108
|
return {
|
|
1100
1109
|
action,
|
|
1101
1110
|
result: {
|
|
1102
|
-
successful:
|
|
1103
|
-
canceled:
|
|
1111
|
+
successful: ActionStatus.Successful === status,
|
|
1112
|
+
canceled: ActionStatus.Canceled === status,
|
|
1104
1113
|
error
|
|
1105
1114
|
}
|
|
1106
1115
|
};
|
|
@@ -1249,15 +1258,15 @@ class StateFactory {
|
|
|
1249
1258
|
}
|
|
1250
1259
|
connectActionHandlers() {
|
|
1251
1260
|
this._actionsSubscription = this._actions
|
|
1252
|
-
.pipe(filter((ctx) => ctx.status ===
|
|
1261
|
+
.pipe(filter((ctx) => ctx.status === ActionStatus.Dispatched), mergeMap(ctx => {
|
|
1253
1262
|
const action = ctx.action;
|
|
1254
|
-
return this.invokeActions(action).pipe(map(() => ({ action, status:
|
|
1263
|
+
return this.invokeActions(action).pipe(map(() => ({ action, status: ActionStatus.Successful })), defaultIfEmpty({ action, status: ActionStatus.Canceled }), catchError(error => {
|
|
1255
1264
|
const ngxsUnhandledErrorHandler = (this._ngxsUnhandledErrorHandler ||=
|
|
1256
1265
|
this._injector.get(NgxsUnhandledErrorHandler));
|
|
1257
1266
|
const handleableError = assignUnhandledCallback(error, () => ngxsUnhandledErrorHandler.handleError(error, { action }));
|
|
1258
1267
|
return of({
|
|
1259
1268
|
action,
|
|
1260
|
-
status:
|
|
1269
|
+
status: ActionStatus.Errored,
|
|
1261
1270
|
error: handleableError
|
|
1262
1271
|
});
|
|
1263
1272
|
}));
|
|
@@ -2196,7 +2205,7 @@ function withNgxsPendingTasks() {
|
|
|
2196
2205
|
});
|
|
2197
2206
|
const subscription = actions$
|
|
2198
2207
|
.pipe(filter(context => {
|
|
2199
|
-
if (context.status ===
|
|
2208
|
+
if (context.status === ActionStatus.Dispatched) {
|
|
2200
2209
|
executedActions.add(context.action);
|
|
2201
2210
|
removeTask ||= pendingTasks.add();
|
|
2202
2211
|
return false;
|
|
@@ -2429,5 +2438,5 @@ function ɵprovideNgxsInternalStateTokens() {
|
|
|
2429
2438
|
* Generated bundle index. Do not edit.
|
|
2430
2439
|
*/
|
|
2431
2440
|
|
|
2432
|
-
export { Action, Actions, NgxsConfig, NgxsDevelopmentModule, NgxsModule, NgxsSimpleChange, NgxsUnhandledActionsLogger, NgxsUnhandledErrorHandler, Select, Selector, SelectorOptions, State, Store, createDispatchMap, createModelSelector, createPickSelector, createPropertySelectors, createSelectMap, createSelector, dispatch, lazyProvider, ofAction, ofActionCanceled, ofActionCompleted, ofActionDispatched, ofActionErrored, ofActionSuccessful, provideStates, provideStore, select, withNgxsDevelopmentOptions, withNgxsPendingTasks, withNgxsPlugin, withNgxsPreboot, NgxsFeatureModule as ɵNgxsFeatureModule, NgxsRootModule as ɵNgxsRootModule, ɵprovideNgxsInternalStateTokens };
|
|
2441
|
+
export { Action, ActionStatus, Actions, NgxsConfig, NgxsDevelopmentModule, NgxsModule, NgxsSimpleChange, NgxsUnhandledActionsLogger, NgxsUnhandledErrorHandler, Select, Selector, SelectorOptions, State, Store, createDispatchMap, createModelSelector, createPickSelector, createPropertySelectors, createSelectMap, createSelector, dispatch, lazyProvider, ofAction, ofActionCanceled, ofActionCompleted, ofActionDispatched, ofActionErrored, ofActionSuccessful, provideStates, provideStore, select, withNgxsDevelopmentOptions, withNgxsPendingTasks, withNgxsPlugin, withNgxsPreboot, NgxsFeatureModule as ɵNgxsFeatureModule, NgxsRootModule as ɵNgxsRootModule, ɵprovideNgxsInternalStateTokens };
|
|
2433
2442
|
//# sourceMappingURL=ngxs-store.mjs.map
|