@ngxs/store 3.8.2-dev.master-0fd1fe5 → 3.8.2-dev.master-ce98589

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.
Files changed (26) hide show
  1. package/esm2020/internals/testing/index.mjs +2 -2
  2. package/fesm2015/ngxs-store-internals-testing.mjs +74 -74
  3. package/fesm2015/ngxs-store-internals-testing.mjs.map +1 -1
  4. package/fesm2020/ngxs-store-internals-testing.mjs +71 -71
  5. package/fesm2020/ngxs-store-internals-testing.mjs.map +1 -1
  6. package/internals/testing/index.d.ts +2 -2
  7. package/package.json +1 -1
  8. package/schematics/src/starter-kit/files/store/auth/auth.state.spec.ts__template__ +18 -9
  9. package/schematics/src/starter-kit/files/store/auth/auth.state.ts__template__ +2 -0
  10. package/schematics/src/starter-kit/files/store/dashboard/states/dictionary/dictionary.state.spec.ts__template__ +24 -9
  11. package/schematics/src/starter-kit/files/store/dashboard/states/dictionary/dictionary.state.ts__template__ +2 -0
  12. package/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.spec.ts__template__ +16 -9
  13. package/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.ts__template__ +2 -0
  14. package/schematics/src/starter-kit/starter-kit.factory.js +9 -3
  15. package/schematics/src/starter-kit/starter-kit.factory.js.map +1 -1
  16. package/schematics/src/state/files/__name__.state.spec.ts__template__ +11 -8
  17. package/schematics/src/state/files/__name__.state.ts__template__ +2 -0
  18. package/schematics/src/state/schema.json +4 -0
  19. package/schematics/src/state/state.factory.js +16 -10
  20. package/schematics/src/state/state.factory.js.map +1 -1
  21. package/schematics/src/store/files/__name__.state.spec.ts__template__ +9 -7
  22. package/schematics/src/store/files/__name__.state.ts__template__ +2 -0
  23. package/schematics/src/store/schema.json +4 -0
  24. package/schematics/src/store/store.factory.js +16 -10
  25. package/schematics/src/store/store.factory.js.map +1 -1
  26. package/schematics/src/utils/versions.json +1 -1
@@ -1,4 +1,4 @@
1
- export { NgxsTestBed } from './ngxs.setup';
2
1
  export { freshPlatform } from './fresh-platform';
2
+ export { NgxsTestBed } from './ngxs.setup';
3
3
  export { skipConsoleLogging } from './skip-console-logging';
4
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9zdG9yZS9pbnRlcm5hbHMvdGVzdGluZy9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLGNBQWMsQ0FBQztBQUUzQyxPQUFPLEVBQUUsYUFBYSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFDakQsT0FBTyxFQUFFLGtCQUFrQixFQUFFLE1BQU0sd0JBQXdCLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgeyBOZ3hzVGVzdEJlZCB9IGZyb20gJy4vbmd4cy5zZXR1cCc7XG5leHBvcnQgeyBOZ3hzVGVzdGluZyB9IGZyb20gJy4vc3ltYm9sJztcbmV4cG9ydCB7IGZyZXNoUGxhdGZvcm0gfSBmcm9tICcuL2ZyZXNoLXBsYXRmb3JtJztcbmV4cG9ydCB7IHNraXBDb25zb2xlTG9nZ2luZyB9IGZyb20gJy4vc2tpcC1jb25zb2xlLWxvZ2dpbmcnO1xuIl19
4
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9zdG9yZS9pbnRlcm5hbHMvdGVzdGluZy9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLGtCQUFrQixDQUFDO0FBQ2pELE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSxjQUFjLENBQUM7QUFDM0MsT0FBTyxFQUFFLGtCQUFrQixFQUFFLE1BQU0sd0JBQXdCLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgeyBmcmVzaFBsYXRmb3JtIH0gZnJvbSAnLi9mcmVzaC1wbGF0Zm9ybSc7XG5leHBvcnQgeyBOZ3hzVGVzdEJlZCB9IGZyb20gJy4vbmd4cy5zZXR1cCc7XG5leHBvcnQgeyBza2lwQ29uc29sZUxvZ2dpbmcgfSBmcm9tICcuL3NraXAtY29uc29sZS1sb2dnaW5nJztcbmV4cG9ydCB7IE5neHNUZXN0aW5nIH0gZnJvbSAnLi9zeW1ib2wnO1xuIl19
@@ -1,11 +1,81 @@
1
- import * as i0 from '@angular/core';
2
- import { Component, NgModule, ApplicationRef, destroyPlatform, VERSION, createPlatform } from '@angular/core';
1
+ import { __awaiter } from 'tslib';
3
2
  import { TestBed } from '@angular/core/testing';
4
3
  import { DOCUMENT } from '@angular/common';
5
- import { BrowserModule, ɵBrowserDomAdapter, ɵgetDOM } from '@angular/platform-browser';
4
+ import { ɵgetDOM, BrowserModule, ɵBrowserDomAdapter } from '@angular/platform-browser';
5
+ import * as i0 from '@angular/core';
6
+ import { destroyPlatform, VERSION, createPlatform, Component, NgModule, ApplicationRef } from '@angular/core';
6
7
  import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
7
8
  import { NgxsModule, Store } from '@ngxs/store';
8
- import { __awaiter } from 'tslib';
9
+
10
+ function createRootElement() {
11
+ const document = TestBed.inject(DOCUMENT);
12
+ const root = ɵgetDOM().createElement('app-root', document);
13
+ document.body.appendChild(root);
14
+ }
15
+ function removeRootElement() {
16
+ const root = document.getElementsByTagName('app-root').item(0);
17
+ try {
18
+ document.body.removeChild(root);
19
+ }
20
+ catch (_a) { }
21
+ }
22
+ function destroyPlatformBeforeBootstrappingTheNewOne(freshUrl) {
23
+ destroyPlatform();
24
+ resetLocationToUrl(freshUrl);
25
+ createRootElement();
26
+ }
27
+ // As we create our custom platform via `bootstrapModule`
28
+ // we have to destroy it after assetions and revert
29
+ // the previous one
30
+ function resetPlatformAfterBootstrapping() {
31
+ removeRootElement();
32
+ destroyPlatform();
33
+ const version = +VERSION.major;
34
+ // https://github.com/angular/angular/commit/e250db4f261741b04ee4cbad4dec41a8908a12aa
35
+ if (version < 14) {
36
+ createPlatform(TestBed);
37
+ }
38
+ }
39
+ function resetLocationToUrl(freshUrl) {
40
+ window.history.replaceState({}, 'Test', freshUrl);
41
+ }
42
+ function freshPlatform(fn) {
43
+ let resolve = null;
44
+ let reject = null;
45
+ let whenDoneIsCalledPromise = null;
46
+ const hasDoneArgument = fn.length === 1;
47
+ if (hasDoneArgument) {
48
+ whenDoneIsCalledPromise = new Promise((_resolve, _reject) => {
49
+ resolve = _resolve;
50
+ reject = _reject;
51
+ });
52
+ }
53
+ return function testWithAFreshPlatform() {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ try {
56
+ const freshUrl = '/';
57
+ destroyPlatformBeforeBootstrappingTheNewOne(freshUrl);
58
+ if (hasDoneArgument) {
59
+ yield fn((error) => {
60
+ if (error) {
61
+ reject(error);
62
+ }
63
+ else {
64
+ resolve();
65
+ }
66
+ });
67
+ yield whenDoneIsCalledPromise;
68
+ }
69
+ else {
70
+ yield fn();
71
+ }
72
+ }
73
+ finally {
74
+ resetPlatformAfterBootstrapping();
75
+ }
76
+ });
77
+ };
78
+ }
9
79
 
10
80
  class NgxsTestComponent {
11
81
  ngOnInit() { }
@@ -78,76 +148,6 @@ class NgxsTestBed {
78
148
  }
79
149
  }
80
150
 
81
- function createRootElement() {
82
- const document = TestBed.inject(DOCUMENT);
83
- const root = ɵgetDOM().createElement('app-root', document);
84
- document.body.appendChild(root);
85
- }
86
- function removeRootElement() {
87
- const root = document.getElementsByTagName('app-root').item(0);
88
- try {
89
- document.body.removeChild(root);
90
- }
91
- catch (_a) { }
92
- }
93
- function destroyPlatformBeforeBootstrappingTheNewOne(freshUrl) {
94
- destroyPlatform();
95
- resetLocationToUrl(freshUrl);
96
- createRootElement();
97
- }
98
- // As we create our custom platform via `bootstrapModule`
99
- // we have to destroy it after assetions and revert
100
- // the previous one
101
- function resetPlatformAfterBootstrapping() {
102
- removeRootElement();
103
- destroyPlatform();
104
- const version = +VERSION.major;
105
- // https://github.com/angular/angular/commit/e250db4f261741b04ee4cbad4dec41a8908a12aa
106
- if (version < 14) {
107
- createPlatform(TestBed);
108
- }
109
- }
110
- function resetLocationToUrl(freshUrl) {
111
- window.history.replaceState({}, 'Test', freshUrl);
112
- }
113
- function freshPlatform(fn) {
114
- let resolve = null;
115
- let reject = null;
116
- let whenDoneIsCalledPromise = null;
117
- const hasDoneArgument = fn.length === 1;
118
- if (hasDoneArgument) {
119
- whenDoneIsCalledPromise = new Promise((_resolve, _reject) => {
120
- resolve = _resolve;
121
- reject = _reject;
122
- });
123
- }
124
- return function testWithAFreshPlatform() {
125
- return __awaiter(this, void 0, void 0, function* () {
126
- try {
127
- const freshUrl = '/';
128
- destroyPlatformBeforeBootstrappingTheNewOne(freshUrl);
129
- if (hasDoneArgument) {
130
- yield fn((error) => {
131
- if (error) {
132
- reject(error);
133
- }
134
- else {
135
- resolve();
136
- }
137
- });
138
- yield whenDoneIsCalledPromise;
139
- }
140
- else {
141
- yield fn();
142
- }
143
- }
144
- finally {
145
- resetPlatformAfterBootstrapping();
146
- }
147
- });
148
- };
149
- }
150
-
151
151
  /// <reference types="jest" />
152
152
  function skipConsoleLogging(fn) {
153
153
  const consoleSpies = [
@@ -1 +1 @@
1
- {"version":3,"file":"ngxs-store-internals-testing.mjs","sources":["../../../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/ngxs.setup.ts","../../../packages/store/internals/testing/src/fresh-platform.ts","../../../packages/store/internals/testing/src/skip-console-logging.ts","../../../packages/store/internals/testing/src/ngxs-store-internals-testing.ts"],"sourcesContent":["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],\n declarations: [NgxsTestComponent]\n})\nexport class NgxsTestModule {\n public static ngDoBootstrap(app: ApplicationRef): void {\n app.bootstrap(NgxsTestComponent);\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';\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 TestBed.configureTestingModule({\n imports: [\n NgxsTestModule,\n NgxsModule.forRoot(options.states || [], options.ngxsOptions || {}),\n ...(options.imports || [])\n ]\n }).compileComponents();\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 { 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","/// <reference types=\"jest\" />\n\nexport function skipConsoleLogging<T extends (...args: any[]) => any>(fn: T): ReturnType<T> {\n const consoleSpies = [\n jest.spyOn(console, 'log').mockImplementation(() => {}),\n jest.spyOn(console, 'warn').mockImplementation(() => {}),\n jest.spyOn(console, 'error').mockImplementation(() => {}),\n jest.spyOn(console, 'info').mockImplementation(() => {})\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","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["BrowserDomAdapter","getDOM"],"mappings":";;;;;;;;;MAMa,iBAAiB,CAAA;AACrB,IAAA,QAAQ,MAAW;AACnB,IAAA,eAAe,MAAW;;iIAFtB,iBAAiB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA,CAAA;AAAjB,mBAAA,iBAAA,CAAA,IAAA,GAAA,EAAA,CAAA,oBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,IAAA,EAAA,iBAAiB,gDAFlB,EAAE,EAAA,QAAA,EAAA,IAAA,EAAA,CAAA,CAAA;2FAED,iBAAiB,EAAA,UAAA,EAAA,CAAA;kBAJ7B,SAAS;AAAC,YAAA,IAAA,EAAA,CAAA;AACT,oBAAA,QAAQ,EAAE,UAAU;AACpB,oBAAA,QAAQ,EAAE,EAAE;iBACb,CAAA;;;MCIY,cAAc,CAAA;IAClB,OAAO,aAAa,CAAC,GAAmB,EAAA;AAC7C,QAAA,GAAG,CAAC,SAAS,CAAC,iBAAiB,CAAC,C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ACD,QAAA,OAAO,WAAW,CAAC;AACpB,KAAA;AAAS,YAAA;QACR,IAAI,CAAC,eAAe,EAAE;AACpB,YAAA,YAAY,EAAE,CAAC;AAChB,SAAA;AACF,KAAA;AACH;;ACzBA;;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/ngxs.setup.ts","../../../packages/store/internals/testing/src/skip-console-logging.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],\n declarations: [NgxsTestComponent]\n})\nexport class NgxsTestModule {\n public static ngDoBootstrap(app: ApplicationRef): void {\n app.bootstrap(NgxsTestComponent);\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';\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 TestBed.configureTestingModule({\n imports: [\n NgxsTestModule,\n NgxsModule.forRoot(options.states || [], options.ngxsOptions || {}),\n ...(options.imports || [])\n ]\n }).compileComponents();\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","/// <reference types=\"jest\" />\n\nexport function skipConsoleLogging<T extends (...args: any[]) => any>(fn: T): ReturnType<T> {\n const consoleSpies = [\n jest.spyOn(console, 'log').mockImplementation(() => {}),\n jest.spyOn(console, 'warn').mockImplementation(() => {}),\n jest.spyOn(console, 'error').mockImplementation(() => {}),\n jest.spyOn(console, 'info').mockImplementation(() => {})\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","/**\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,CAAC;IAC1C,MAAM,IAAI,GAAGA,OAAM,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC1D,IAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;AAClC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AK,GAAG,CAAC;KACzD,CAAC;AACF,IAAA,SAAS,YAAY,GAAA;AACnB,QAAA,YAAY,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;KAChD;IACD,IAAI,eAAe,GAAG,KAAK,CAAC;IAC5B,IAAI;AACF,QAAA,MAAM,WAAW,GAAG,EAAE,EAAE,CAAC;QACzB,IAAI,WAAW,YAAY,OAAO,EAAE;YAClC,eAAe,GAAG,IAAI,CAAC;YACvB,OAAO,WAAW,CAAC,OAAO,CAAC,MAAM,YAAY,EAAE,CAAkB,CAAC;AACnE,SAAA;AACD,QAAA,OAAO,WAAW,CAAC;AACpB,KAAA;AAAS,YAAA;QACR,IAAI,CAAC,eAAe,EAAE;AACpB,YAAA,YAAY,EAAE,CAAC;AAChB,SAAA;AACF,KAAA;AACH;;ACzBA;;AAEG;;;;"}
@@ -1,11 +1,79 @@
1
- import * as i0 from '@angular/core';
2
- import { Component, NgModule, ApplicationRef, destroyPlatform, VERSION, createPlatform } from '@angular/core';
3
1
  import { TestBed } from '@angular/core/testing';
4
2
  import { DOCUMENT } from '@angular/common';
5
- import { BrowserModule, ɵBrowserDomAdapter, ɵgetDOM } from '@angular/platform-browser';
3
+ import { ɵgetDOM, BrowserModule, ɵBrowserDomAdapter } from '@angular/platform-browser';
4
+ import * as i0 from '@angular/core';
5
+ import { destroyPlatform, VERSION, createPlatform, Component, NgModule, ApplicationRef } from '@angular/core';
6
6
  import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
7
7
  import { NgxsModule, Store } from '@ngxs/store';
8
8
 
9
+ function createRootElement() {
10
+ const document = TestBed.inject(DOCUMENT);
11
+ const root = ɵgetDOM().createElement('app-root', document);
12
+ document.body.appendChild(root);
13
+ }
14
+ function removeRootElement() {
15
+ const root = document.getElementsByTagName('app-root').item(0);
16
+ try {
17
+ document.body.removeChild(root);
18
+ }
19
+ catch { }
20
+ }
21
+ function destroyPlatformBeforeBootstrappingTheNewOne(freshUrl) {
22
+ destroyPlatform();
23
+ resetLocationToUrl(freshUrl);
24
+ createRootElement();
25
+ }
26
+ // As we create our custom platform via `bootstrapModule`
27
+ // we have to destroy it after assetions and revert
28
+ // the previous one
29
+ function resetPlatformAfterBootstrapping() {
30
+ removeRootElement();
31
+ destroyPlatform();
32
+ const version = +VERSION.major;
33
+ // https://github.com/angular/angular/commit/e250db4f261741b04ee4cbad4dec41a8908a12aa
34
+ if (version < 14) {
35
+ createPlatform(TestBed);
36
+ }
37
+ }
38
+ function resetLocationToUrl(freshUrl) {
39
+ window.history.replaceState({}, 'Test', freshUrl);
40
+ }
41
+ function freshPlatform(fn) {
42
+ let resolve = null;
43
+ let reject = null;
44
+ let whenDoneIsCalledPromise = null;
45
+ const hasDoneArgument = fn.length === 1;
46
+ if (hasDoneArgument) {
47
+ whenDoneIsCalledPromise = new Promise((_resolve, _reject) => {
48
+ resolve = _resolve;
49
+ reject = _reject;
50
+ });
51
+ }
52
+ return async function testWithAFreshPlatform() {
53
+ try {
54
+ const freshUrl = '/';
55
+ destroyPlatformBeforeBootstrappingTheNewOne(freshUrl);
56
+ if (hasDoneArgument) {
57
+ await fn((error) => {
58
+ if (error) {
59
+ reject(error);
60
+ }
61
+ else {
62
+ resolve();
63
+ }
64
+ });
65
+ await whenDoneIsCalledPromise;
66
+ }
67
+ else {
68
+ await fn();
69
+ }
70
+ }
71
+ finally {
72
+ resetPlatformAfterBootstrapping();
73
+ }
74
+ };
75
+ }
76
+
9
77
  class NgxsTestComponent {
10
78
  ngOnInit() { }
11
79
  ngAfterViewInit() { }
@@ -77,74 +145,6 @@ class NgxsTestBed {
77
145
  }
78
146
  }
79
147
 
80
- function createRootElement() {
81
- const document = TestBed.inject(DOCUMENT);
82
- const root = ɵgetDOM().createElement('app-root', document);
83
- document.body.appendChild(root);
84
- }
85
- function removeRootElement() {
86
- const root = document.getElementsByTagName('app-root').item(0);
87
- try {
88
- document.body.removeChild(root);
89
- }
90
- catch { }
91
- }
92
- function destroyPlatformBeforeBootstrappingTheNewOne(freshUrl) {
93
- destroyPlatform();
94
- resetLocationToUrl(freshUrl);
95
- createRootElement();
96
- }
97
- // As we create our custom platform via `bootstrapModule`
98
- // we have to destroy it after assetions and revert
99
- // the previous one
100
- function resetPlatformAfterBootstrapping() {
101
- removeRootElement();
102
- destroyPlatform();
103
- const version = +VERSION.major;
104
- // https://github.com/angular/angular/commit/e250db4f261741b04ee4cbad4dec41a8908a12aa
105
- if (version < 14) {
106
- createPlatform(TestBed);
107
- }
108
- }
109
- function resetLocationToUrl(freshUrl) {
110
- window.history.replaceState({}, 'Test', freshUrl);
111
- }
112
- function freshPlatform(fn) {
113
- let resolve = null;
114
- let reject = null;
115
- let whenDoneIsCalledPromise = null;
116
- const hasDoneArgument = fn.length === 1;
117
- if (hasDoneArgument) {
118
- whenDoneIsCalledPromise = new Promise((_resolve, _reject) => {
119
- resolve = _resolve;
120
- reject = _reject;
121
- });
122
- }
123
- return async function testWithAFreshPlatform() {
124
- try {
125
- const freshUrl = '/';
126
- destroyPlatformBeforeBootstrappingTheNewOne(freshUrl);
127
- if (hasDoneArgument) {
128
- await fn((error) => {
129
- if (error) {
130
- reject(error);
131
- }
132
- else {
133
- resolve();
134
- }
135
- });
136
- await whenDoneIsCalledPromise;
137
- }
138
- else {
139
- await fn();
140
- }
141
- }
142
- finally {
143
- resetPlatformAfterBootstrapping();
144
- }
145
- };
146
- }
147
-
148
148
  /// <reference types="jest" />
149
149
  function skipConsoleLogging(fn) {
150
150
  const consoleSpies = [
@@ -1 +1 @@
1
- {"version":3,"file":"ngxs-store-internals-testing.mjs","sources":["../../../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/ngxs.setup.ts","../../../packages/store/internals/testing/src/fresh-platform.ts","../../../packages/store/internals/testing/src/skip-console-logging.ts","../../../packages/store/internals/testing/src/ngxs-store-internals-testing.ts"],"sourcesContent":["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],\n declarations: [NgxsTestComponent]\n})\nexport class NgxsTestModule {\n public static ngDoBootstrap(app: ApplicationRef): void {\n app.bootstrap(NgxsTestComponent);\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';\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 TestBed.configureTestingModule({\n imports: [\n NgxsTestModule,\n NgxsModule.forRoot(options.states || [], options.ngxsOptions || {}),\n ...(options.imports || [])\n ]\n }).compileComponents();\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 { 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","/// <reference types=\"jest\" />\n\nexport function skipConsoleLogging<T extends (...args: any[]) => any>(fn: T): ReturnType<T> {\n const consoleSpies = [\n jest.spyOn(console, 'log').mockImplementation(() => {}),\n jest.spyOn(console, 'warn').mockImplementation(() => {}),\n jest.spyOn(console, 'error').mockImplementation(() => {}),\n jest.spyOn(console, 'info').mockImplementation(() => {})\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","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["BrowserDomAdapter","getDOM"],"mappings":";;;;;;;;MAMa,iBAAiB,CAAA;AACrB,IAAA,QAAQ,MAAW;AACnB,IAAA,eAAe,MAAW;;iIAFtB,iBAAiB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA,CAAA;AAAjB,mBAAA,iBAAA,CAAA,IAAA,GAAA,EAAA,CAAA,oBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,IAAA,EAAA,iBAAiB,gDAFlB,EAAE,EAAA,QAAA,EAAA,IAAA,EAAA,CAAA,CAAA;2FAED,iBAAiB,EAAA,UAAA,EAAA,CAAA;kBAJ7B,SAAS;AAAC,YAAA,IAAA,EAAA,CAAA;AACT,oBAAA,QAAQ,EAAE,UAAU;AACpB,oBAAA,QAAQ,EAAE,EAAE;AACb,iBAAA,CAAA;;;MCIY,cAAc,CAAA;IAClB,OAAO,aAAa,CAAC,GAAmB,EAAA;AAC7C,QAAA,GAAG,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC;KAClC;;8HAHU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;QACR,IAAI,CAAC,eAAe,EAAE;AACpB,YAAA,YAAY,EAAE,CAAC;AAChB,SAAA;AACF,KAAA;AACH;;ACzBA;;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/ngxs.setup.ts","../../../packages/store/internals/testing/src/skip-console-logging.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],\n declarations: [NgxsTestComponent]\n})\nexport class NgxsTestModule {\n public static ngDoBootstrap(app: ApplicationRef): void {\n app.bootstrap(NgxsTestComponent);\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';\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 TestBed.configureTestingModule({\n imports: [\n NgxsTestModule,\n NgxsModule.forRoot(options.states || [], options.ngxsOptions || {}),\n ...(options.imports || [])\n ]\n }).compileComponents();\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","/// <reference types=\"jest\" />\n\nexport function skipConsoleLogging<T extends (...args: any[]) => any>(fn: T): ReturnType<T> {\n const consoleSpies = [\n jest.spyOn(console, 'log').mockImplementation(() => {}),\n jest.spyOn(console, 'warn').mockImplementation(() => {}),\n jest.spyOn(console, 'error').mockImplementation(() => {}),\n jest.spyOn(console, 'info').mockImplementation(() => {})\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","/**\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,CAAC;IAC1C,MAAM,IAAI,GAAGA,OAAM,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC1D,IAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,iBAAiB,GAAA;AACxB,IAAA,MAAM,I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C,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;KAChD;IACD,IAAI,eAAe,GAAG,KAAK,CAAC;IAC5B,IAAI;AACF,QAAA,MAAM,WAAW,GAAG,EAAE,EAAE,CAAC;QACzB,IAAI,WAAW,YAAY,OAAO,EAAE;YAClC,eAAe,GAAG,IAAI,CAAC;YACvB,OAAO,WAAW,CAAC,OAAO,CAAC,MAAM,YAAY,EAAE,CAAkB,CAAC;AACnE,SAAA;AACD,QAAA,OAAO,WAAW,CAAC;AACpB,KAAA;AAAS,YAAA;QACR,IAAI,CAAC,eAAe,EAAE;AACpB,YAAA,YAAY,EAAE,CAAC;AAChB,SAAA;AACF,KAAA;AACH;;ACzBA;;AAEG;;;;"}
@@ -1,4 +1,4 @@
1
- export { NgxsTestBed } from './ngxs.setup';
2
- export { NgxsTesting } from './symbol';
3
1
  export { freshPlatform } from './fresh-platform';
2
+ export { NgxsTestBed } from './ngxs.setup';
4
3
  export { skipConsoleLogging } from './skip-console-logging';
4
+ export { NgxsTesting } from './symbol';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngxs/store",
3
- "version": "3.8.2-dev.master-0fd1fe5",
3
+ "version": "3.8.2-dev.master-ce98589",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -1,21 +1,22 @@
1
- import { NgxsModule, Store } from '@ngxs/store';
2
- import { async, TestBed } from '@angular/core/testing';
1
+ import { <% if (isStandalone) { %> provideStore, <% } else { %> NgxsModule, <% } %> Store } from '@ngxs/store';
2
+ import { TestBed } from '@angular/core/testing';
3
3
  import { AuthenticationStateModel, AuthState } from './auth.state';
4
4
  import { SetAuthData } from './auth.actions';
5
5
 
6
6
  describe('[TEST]: AuthStore', () => {
7
7
  let store: Store;
8
8
 
9
- beforeEach(async(() => {
9
+ beforeEach(() => {
10
10
  TestBed.configureTestingModule({
11
- imports: [NgxsModule.forRoot([AuthState])]
12
- })
13
- .compileComponents()
14
- .then();
15
- store = TestBed.get(Store);
16
- }));
11
+ <% if (isStandalone) { %> providers: [provideStore([AuthState])]
12
+ <% } else { %> imports: [NgxsModule.forRoot([AuthState])] <% } %>
13
+ });
14
+
15
+ store = TestBed.inject(Store);
16
+ });
17
17
 
18
18
  it('Should be correct dispatch and value is empty', () => {
19
+ // Arrange
19
20
  const Authentication: AuthenticationStateModel = {
20
21
  id: '',
21
22
  firstName: '',
@@ -24,12 +25,17 @@ describe('[TEST]: AuthStore', () => {
24
25
  email: '',
25
26
  roles: []
26
27
  };
28
+
29
+ // Act
27
30
  store.dispatch(new SetAuthData(Authentication));
28
31
  const actual = store.selectSnapshot<AuthenticationStateModel>(AuthState.getAuthData);
32
+
33
+ // Assert
29
34
  expect(actual).toEqual(Authentication);
30
35
  });
31
36
 
32
37
  it('Should be correct dispatch and next value is correct completed', () => {
38
+ // Arrange
33
39
  const authentication: AuthenticationStateModel = {
34
40
  id: '12',
35
41
  firstName: 'Adam',
@@ -39,8 +45,11 @@ describe('[TEST]: AuthStore', () => {
39
45
  roles: ['ADMIN']
40
46
  };
41
47
 
48
+ // Act
42
49
  store.dispatch(new SetAuthData(authentication));
43
50
  const actual = store.selectSnapshot<AuthenticationStateModel>(AuthState.getAuthData);
51
+
52
+ // Assert
44
53
  expect(actual).toEqual(authentication);
45
54
  });
46
55
  });
@@ -1,3 +1,4 @@
1
+ import { Injectable } from '@angular/core';
1
2
  import { Action, Selector, State, StateContext } from '@ngxs/store';
2
3
  import { SetAuthData } from './auth.actions';
3
4
 
@@ -21,6 +22,7 @@ export interface AuthenticationStateModel {
21
22
  roles: []
22
23
  }
23
24
  })
25
+ @Injectable()
24
26
  export class AuthState {
25
27
  @Selector()
26
28
  public static getAuthData(state: AuthenticationStateModel): AuthenticationStateModel {
@@ -1,5 +1,5 @@
1
- import { NgxsModule, Store } from '@ngxs/store';
2
- import { async, TestBed } from '@angular/core/testing';
1
+ import { <% if (isStandalone) { %> provideStore, <% } else { %> NgxsModule, <% } %> Store } from '@ngxs/store';
2
+ import { TestBed } from '@angular/core/testing';
3
3
  import { DictionaryState, DictionaryStateModel } from './dictionary.state';
4
4
  import { DictionaryReset, SetDictionaryData } from './dictionary.actions';
5
5
 
@@ -27,16 +27,17 @@ const data = [
27
27
  describe('[TEST]: Dictionary state', () => {
28
28
  let store: Store;
29
29
 
30
- beforeEach(async(() => {
30
+ beforeEach(() => {
31
31
  TestBed.configureTestingModule({
32
- imports: [NgxsModule.forRoot([DictionaryState])]
33
- })
34
- .compileComponents()
35
- .then();
36
- store = TestBed.get(Store);
37
- }));
32
+ <% if (isStandalone) { %> providers: [provideStore([DictionaryState])]
33
+ <% } else { %> imports: [NgxsModule.forRoot([DictionaryState])] <% } %>
34
+ });
35
+
36
+ store = TestBed.inject(Store);
37
+ });
38
38
 
39
39
  it('Should be correct dispatch and dictionary is empty', () => {
40
+ // Arrange
40
41
  const dictionary: DictionaryStateModel = {
41
42
  content: [],
42
43
  page: 0,
@@ -44,12 +45,17 @@ describe('[TEST]: Dictionary state', () => {
44
45
  totalPages: 0,
45
46
  totalElements: 0
46
47
  };
48
+
49
+ // Act
47
50
  store.dispatch(new SetDictionaryData(dictionary));
48
51
  const actual = store.selectSnapshot(DictionaryState.getDictionaryState);
52
+
53
+ // Assert
49
54
  expect(actual).toEqual(dictionary);
50
55
  });
51
56
 
52
57
  it('Should be state is filled DictionaryStateModel', () => {
58
+ // Arrange
53
59
  const dictionary: DictionaryStateModel = {
54
60
  content: data,
55
61
  page: 0,
@@ -57,12 +63,17 @@ describe('[TEST]: Dictionary state', () => {
57
63
  totalPages: 2,
58
64
  totalElements: 1
59
65
  };
66
+
67
+ // Act
60
68
  store.dispatch(new SetDictionaryData(dictionary));
61
69
  const actual = store.selectSnapshot(DictionaryState.getDictionaryState);
70
+
71
+ // Assert
62
72
  expect(actual).toEqual(dictionary);
63
73
  });
64
74
 
65
75
  it('should be reset state', function () {
76
+ // Arrange
66
77
  const dictionary: DictionaryStateModel = {
67
78
  content: [],
68
79
  page: 0,
@@ -70,8 +81,12 @@ describe('[TEST]: Dictionary state', () => {
70
81
  totalPages: 0,
71
82
  totalElements: 0
72
83
  };
84
+
85
+ // Act
73
86
  store.dispatch(new DictionaryReset());
74
87
  const actual = store.selectSnapshot(DictionaryState.getDictionaryState);
88
+
89
+ // Assert
75
90
  expect(actual).toEqual(dictionary);
76
91
  });
77
92
  });
@@ -1,3 +1,4 @@
1
+ import { Injectable } from '@angular/core';
1
2
  import { Action, Selector, State, StateContext } from '@ngxs/store';
2
3
  import { DictionaryReset, SetDictionaryData } from './dictionary.actions';
3
4
 
@@ -19,6 +20,7 @@ export interface DictionaryStateModel {
19
20
  totalElements: 0
20
21
  }
21
22
  })
23
+ @Injectable()
22
24
  export class DictionaryState {
23
25
  @Selector()
24
26
  public static getDictionaryState(state: DictionaryStateModel): DictionaryStateModel {
@@ -1,21 +1,22 @@
1
- import { NgxsModule, Store } from '@ngxs/store';
2
- import { async, TestBed } from '@angular/core/testing';
1
+ import { <% if (isStandalone) { %> provideStore, <% } else { %> NgxsModule, <% } %> Store } from '@ngxs/store';
2
+ import { TestBed } from '@angular/core/testing';
3
3
  import { UserStateModel, UserState } from './user.state';
4
4
  import { SetUser } from './user.actions';
5
5
 
6
6
  describe('[TEST]: User state', () => {
7
7
  let store: Store;
8
8
 
9
- beforeEach(async(() => {
9
+ beforeEach(() => {
10
10
  TestBed.configureTestingModule({
11
- imports: [NgxsModule.forRoot([UserState])]
12
- })
13
- .compileComponents()
14
- .then();
15
- store = TestBed.get(Store);
16
- }));
11
+ <% if (isStandalone) { %> providers: [provideStore([UserState])]
12
+ <% } else { %> imports: [NgxsModule.forRoot([UserState])] <% } %>
13
+ });
14
+
15
+ store = TestBed.inject(Store);
16
+ });
17
17
 
18
18
  it('Should be state is UserStateModel', () => {
19
+ // Arrange
19
20
  const user: UserStateModel = {
20
21
  userId: '',
21
22
  departmentCode: '',
@@ -27,13 +28,17 @@ describe('[TEST]: User state', () => {
27
28
  positionId: '',
28
29
  positionName: ''
29
30
  };
31
+
32
+ // Act
30
33
  store.dispatch(new SetUser(user));
31
34
  const actual = store.selectSnapshot(({ user }) => user);
32
35
 
36
+ // Assert
33
37
  expect(actual).toEqual(user);
34
38
  });
35
39
 
36
40
  it('Should be state is filled UserStateModel', () => {
41
+ // Arrange
37
42
  const user: UserStateModel = {
38
43
  userId: '12',
39
44
  departmentCode: '2392',
@@ -46,9 +51,11 @@ describe('[TEST]: User state', () => {
46
51
  positionName: 'admin'
47
52
  };
48
53
 
54
+ // Act
49
55
  store.dispatch(new SetUser(user));
50
56
  const actual = store.selectSnapshot<UserStateModel>(({ user }) => user);
51
57
 
58
+ // Assert
52
59
  expect(actual).toEqual(user);
53
60
  });
54
61
  });
@@ -1,3 +1,4 @@
1
+ import { Injectable } from '@angular/core';
1
2
  import { Action, Selector, State, StateContext } from '@ngxs/store';
2
3
  import { SetUser } from './user.actions';
3
4
 
@@ -27,6 +28,7 @@ export interface UserStateModel {
27
28
  departmentName: ''
28
29
  }
29
30
  })
31
+ @Injectable()
30
32
  export class UserState {
31
33
  @Selector()
32
34
  public static getUser(state: UserStateModel): UserStateModel {
@@ -2,11 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.starterKit = void 0;
4
4
  const schematics_1 = require("@angular-devkit/schematics");
5
- const normalize_options_1 = require("../utils/normalize-options");
6
5
  const generate_utils_1 = require("../utils/generate-utils");
6
+ const ng_ast_utils_1 = require("../utils/ng-utils/ng-ast-utils");
7
+ const project_1 = require("../utils/ng-utils/project");
8
+ const normalize_options_1 = require("../utils/normalize-options");
7
9
  function starterKit(options) {
8
- const normalizedPath = (0, normalize_options_1.normalizePath)(options.path);
9
- return (0, generate_utils_1.generateFiles)((0, schematics_1.url)('./files'), normalizedPath, options, options.spec);
10
+ return (host) => {
11
+ const mainFile = (0, project_1.getProjectMainFile)(host, options.project);
12
+ const isStandalone = (0, ng_ast_utils_1.isStandaloneApp)(host, mainFile);
13
+ const normalizedPath = (0, normalize_options_1.normalizePath)(options.path);
14
+ return (0, generate_utils_1.generateFiles)((0, schematics_1.url)('./files'), normalizedPath, Object.assign(Object.assign({}, options), { isStandalone }), options.spec);
15
+ };
10
16
  }
11
17
  exports.starterKit = starterKit;
12
18
  //# sourceMappingURL=starter-kit.factory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"starter-kit.factory.js","sourceRoot":"","sources":["../../../../../packages/store/schematics/src/starter-kit/starter-kit.factory.ts"],"names":[],"mappings":";;;AAAA,2DAAuD;AAEvD,kEAA2D;AAC3D,4DAAwD;AAExD,SAAgB,UAAU,CAAC,OAAyB;IAClD,MAAM,cAAc,GAAG,IAAA,iCAAa,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnD,OAAO,IAAA,8BAAa,EAAC,IAAA,gBAAG,EAAC,SAAS,CAAC,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;AAC9E,CAAC;AAJD,gCAIC"}
1
+ {"version":3,"file":"starter-kit.factory.js","sourceRoot":"","sources":["../../../../../packages/store/schematics/src/starter-kit/starter-kit.factory.ts"],"names":[],"mappings":";;;AAAA,2DAA6D;AAC7D,4DAAwD;AACxD,iEAAiE;AACjE,uDAA+D;AAC/D,kEAA2D;AAG3D,SAAgB,UAAU,CAAC,OAAyB;IAClD,OAAO,CAAC,IAAU,EAAE,EAAE;QACpB,MAAM,QAAQ,GAAG,IAAA,4BAAkB,EAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAC3D,MAAM,YAAY,GAAG,IAAA,8BAAe,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAErD,MAAM,cAAc,GAAG,IAAA,iCAAa,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAEnD,OAAO,IAAA,8BAAa,EAClB,IAAA,gBAAG,EAAC,SAAS,CAAC,EACd,cAAc,kCACT,OAAO,KAAE,YAAY,KAC1B,OAAO,CAAC,IAAI,CACb,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAdD,gCAcC"}
@@ -1,15 +1,18 @@
1
- import { TestBed, async } from '@angular/core/testing';
2
- import { NgxsModule, Store } from '@ngxs/store';
1
+ import { TestBed } from '@angular/core/testing';
2
+ import { <% if (isStandalone) { %> provideStore, <% } else { %> NgxsModule, <% } %> Store } from '@ngxs/store';
3
3
  import { <%= classify(name) %>State, <%= classify(name) %>StateModel } from './<%= dasherize(name) %>.state';
4
4
 
5
5
  describe('<%= classify(name) %> state', () => {
6
6
  let store: Store;
7
- beforeEach(async(() => {
8
- TestBed.configureTestingModule({
9
- imports: [NgxsModule.forRoot([<%= classify(name) %>State])]
10
- }).compileComponents();
11
- store = TestBed.get(Store);
12
- }));
7
+
8
+ beforeEach(() => {
9
+ TestBed.configureTestingModule({
10
+ <% if (isStandalone) { %> providers: [provideStore([<%= classify(name) %>State])]
11
+ <% } else { %> imports: [NgxsModule.forRoot([<%= classify(name) %>State])] <% } %>
12
+ });
13
+
14
+ store = TestBed.inject(Store);
15
+ });
13
16
 
14
17
  it('should create an empty state', () => {
15
18
  const actual = store.selectSnapshot(<%= classify(name) %>State.getState);
@@ -1,3 +1,4 @@
1
+ import { Injectable } from '@angular/core';
1
2
  import { State, Selector } from '@ngxs/store';
2
3
 
3
4
  export interface <%= classify(name) %>StateModel {
@@ -10,6 +11,7 @@ export interface <%= classify(name) %>StateModel {
10
11
  items: []
11
12
  }
12
13
  })
14
+ @Injectable()
13
15
  export class <%= classify(name) %>State {
14
16
 
15
17
  @Selector()
@@ -27,6 +27,10 @@
27
27
  "type": "boolean",
28
28
  "default": false,
29
29
  "description": "Flag to indicate if a dir is created."
30
+ },
31
+ "project": {
32
+ "type": "string",
33
+ "description": "The name of the project."
30
34
  }
31
35
  },
32
36
  "required": ["name"]
@@ -2,19 +2,25 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.state = void 0;
4
4
  const schematics_1 = require("@angular-devkit/schematics");
5
+ const path_1 = require("path");
5
6
  const properties_1 = require("../utils/common/properties");
6
- const normalize_options_1 = require("../utils/normalize-options");
7
7
  const generate_utils_1 = require("../utils/generate-utils");
8
- const path_1 = require("path");
8
+ const ng_ast_utils_1 = require("../utils/ng-utils/ng-ast-utils");
9
+ const project_1 = require("../utils/ng-utils/project");
10
+ const normalize_options_1 = require("../utils/normalize-options");
9
11
  function state(options) {
10
- if ((0, properties_1.isEmpty)(options.name)) {
11
- throw new schematics_1.SchematicsException('Invalid options, "name" is required.');
12
- }
13
- const normalizedOptions = (0, normalize_options_1.normalizeBaseOptions)(options);
14
- const path = options.flat
15
- ? normalizedOptions.path
16
- : (0, path_1.join)(normalizedOptions.path, normalizedOptions.name);
17
- return (0, generate_utils_1.generateFiles)((0, schematics_1.url)('./files'), path, options, options.spec);
12
+ return (host) => {
13
+ if ((0, properties_1.isEmpty)(options.name)) {
14
+ throw new schematics_1.SchematicsException('Invalid options, "name" is required.');
15
+ }
16
+ const mainFile = (0, project_1.getProjectMainFile)(host, options.project);
17
+ const isStandalone = (0, ng_ast_utils_1.isStandaloneApp)(host, mainFile);
18
+ const normalizedOptions = (0, normalize_options_1.normalizeBaseOptions)(options);
19
+ const path = options.flat
20
+ ? normalizedOptions.path
21
+ : (0, path_1.join)(normalizedOptions.path, normalizedOptions.name);
22
+ return (0, generate_utils_1.generateFiles)((0, schematics_1.url)('./files'), path, Object.assign(Object.assign({}, options), { isStandalone }), options.spec);
23
+ };
18
24
  }
19
25
  exports.state = state;
20
26
  //# sourceMappingURL=state.factory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"state.factory.js","sourceRoot":"","sources":["../../../../../packages/store/schematics/src/state/state.factory.ts"],"names":[],"mappings":";;;AAAA,2DAA4E;AAE5E,2DAAqD;AACrD,kEAAkE;AAClE,4DAAwD;AACxD,+BAA4B;AAE5B,SAAgB,KAAK,CAAC,OAAoB;IACxC,IAAI,IAAA,oBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACzB,MAAM,IAAI,gCAAmB,CAAC,sCAAsC,CAAC,CAAC;KACvE;IAED,MAAM,iBAAiB,GAAG,IAAA,wCAAoB,EAAC,OAAO,CAAC,CAAC;IACxD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI;QACvB,CAAC,CAAC,iBAAiB,CAAC,IAAI;QACxB,CAAC,CAAC,IAAA,WAAI,EAAC,iBAAiB,CAAC,IAAI,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAEzD,OAAO,IAAA,8BAAa,EAAC,IAAA,gBAAG,EAAC,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;AACpE,CAAC;AAXD,sBAWC"}
1
+ {"version":3,"file":"state.factory.js","sourceRoot":"","sources":["../../../../../packages/store/schematics/src/state/state.factory.ts"],"names":[],"mappings":";;;AAAA,2DAAkF;AAClF,+BAA4B;AAC5B,2DAAqD;AACrD,4DAAwD;AACxD,iEAAiE;AACjE,uDAA+D;AAC/D,kEAAkE;AAGlE,SAAgB,KAAK,CAAC,OAAoB;IACxC,OAAO,CAAC,IAAU,EAAE,EAAE;QACpB,IAAI,IAAA,oBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACzB,MAAM,IAAI,gCAAmB,CAAC,sCAAsC,CAAC,CAAC;SACvE;QAED,MAAM,QAAQ,GAAG,IAAA,4BAAkB,EAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAC3D,MAAM,YAAY,GAAG,IAAA,8BAAe,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAErD,MAAM,iBAAiB,GAAG,IAAA,wCAAoB,EAAC,OAAO,CAAC,CAAC;QACxD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI;YACvB,CAAC,CAAC,iBAAiB,CAAC,IAAI;YACxB,CAAC,CAAC,IAAA,WAAI,EAAC,iBAAiB,CAAC,IAAI,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAEzD,OAAO,IAAA,8BAAa,EAAC,IAAA,gBAAG,EAAC,SAAS,CAAC,EAAE,IAAI,kCAAO,OAAO,KAAE,YAAY,KAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzF,CAAC,CAAC;AACJ,CAAC;AAhBD,sBAgBC"}
@@ -1,16 +1,18 @@
1
- import { TestBed, async } from '@angular/core/testing';
2
- import { NgxsModule, Store } from '@ngxs/store';
1
+ import { TestBed } from '@angular/core/testing';
2
+ import { <% if (isStandalone) { %> provideStore, <% } else { %> NgxsModule, <% } %> Store } from '@ngxs/store';
3
3
  import { <%= classify(name) %>State, <%= classify(name) %>StateModel } from './<%= dasherize(name) %>.state';
4
4
  import { <%= classify(name) %>Action } from './<%= dasherize(name) %>.actions';
5
5
 
6
6
  describe('<%= classify(name) %> store', () => {
7
7
  let store: Store;
8
- beforeEach(async(() => {
8
+ beforeEach(() => {
9
9
  TestBed.configureTestingModule({
10
- imports: [NgxsModule.forRoot([<%= classify(name) %>State])]
11
- }).compileComponents();
12
- store = TestBed.get(Store);
13
- }));
10
+ <% if (isStandalone) { %> providers: [provideStore([<%= classify(name) %>State])]
11
+ <% } else { %> imports: [NgxsModule.forRoot([<%= classify(name) %>State])] <% } %>
12
+ });
13
+
14
+ store = TestBed.inject(Store);
15
+ });
14
16
 
15
17
  it('should create an action and add an item', () => {
16
18
  const expected: <%= classify(name) %>StateModel = {
@@ -1,3 +1,4 @@
1
+ import { Injectable } from '@angular/core';
1
2
  import { State, Action, Selector, StateContext } from '@ngxs/store';
2
3
  import { <%= classify(name) %>Action } from './<%= dasherize(name) %>.actions';
3
4
 
@@ -11,6 +12,7 @@ export interface <%= classify(name) %>StateModel {
11
12
  items: []
12
13
  }
13
14
  })
15
+ @Injectable()
14
16
  export class <%= classify(name) %>State {
15
17
 
16
18
  @Selector()
@@ -27,6 +27,10 @@
27
27
  "type": "boolean",
28
28
  "default": false,
29
29
  "description": "Flag to indicate if a dir is created."
30
+ },
31
+ "project": {
32
+ "type": "string",
33
+ "description": "The name of the project."
30
34
  }
31
35
  },
32
36
  "required": ["name"]
@@ -2,19 +2,25 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.store = void 0;
4
4
  const schematics_1 = require("@angular-devkit/schematics");
5
+ const path_1 = require("path");
5
6
  const properties_1 = require("../utils/common/properties");
6
- const normalize_options_1 = require("../utils/normalize-options");
7
7
  const generate_utils_1 = require("../utils/generate-utils");
8
- const path_1 = require("path");
8
+ const ng_ast_utils_1 = require("../utils/ng-utils/ng-ast-utils");
9
+ const project_1 = require("../utils/ng-utils/project");
10
+ const normalize_options_1 = require("../utils/normalize-options");
9
11
  function store(options) {
10
- if ((0, properties_1.isEmpty)(options.name)) {
11
- throw new schematics_1.SchematicsException('Invalid options, "name" is required.');
12
- }
13
- const normalizedOptions = (0, normalize_options_1.normalizeBaseOptions)(options);
14
- const path = options.flat
15
- ? normalizedOptions.path
16
- : (0, path_1.join)(normalizedOptions.path, normalizedOptions.name);
17
- return (0, generate_utils_1.generateFiles)((0, schematics_1.url)('./files'), path, options, options.spec);
12
+ return (host) => {
13
+ if ((0, properties_1.isEmpty)(options.name)) {
14
+ throw new schematics_1.SchematicsException('Invalid options, "name" is required.');
15
+ }
16
+ const mainFile = (0, project_1.getProjectMainFile)(host, options.project);
17
+ const isStandalone = (0, ng_ast_utils_1.isStandaloneApp)(host, mainFile);
18
+ const normalizedOptions = (0, normalize_options_1.normalizeBaseOptions)(options);
19
+ const path = options.flat
20
+ ? normalizedOptions.path
21
+ : (0, path_1.join)(normalizedOptions.path, normalizedOptions.name);
22
+ return (0, generate_utils_1.generateFiles)((0, schematics_1.url)('./files'), path, Object.assign(Object.assign({}, options), { isStandalone }), options.spec);
23
+ };
18
24
  }
19
25
  exports.store = store;
20
26
  //# sourceMappingURL=store.factory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"store.factory.js","sourceRoot":"","sources":["../../../../../packages/store/schematics/src/store/store.factory.ts"],"names":[],"mappings":";;;AAAA,2DAA4E;AAE5E,2DAAqD;AACrD,kEAAkE;AAClE,4DAAwD;AACxD,+BAA4B;AAE5B,SAAgB,KAAK,CAAC,OAAoB;IACxC,IAAI,IAAA,oBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACzB,MAAM,IAAI,gCAAmB,CAAC,sCAAsC,CAAC,CAAC;KACvE;IAED,MAAM,iBAAiB,GAAG,IAAA,wCAAoB,EAAC,OAAO,CAAC,CAAC;IACxD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI;QACvB,CAAC,CAAC,iBAAiB,CAAC,IAAI;QACxB,CAAC,CAAC,IAAA,WAAI,EAAC,iBAAiB,CAAC,IAAI,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAEzD,OAAO,IAAA,8BAAa,EAAC,IAAA,gBAAG,EAAC,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;AACpE,CAAC;AAXD,sBAWC"}
1
+ {"version":3,"file":"store.factory.js","sourceRoot":"","sources":["../../../../../packages/store/schematics/src/store/store.factory.ts"],"names":[],"mappings":";;;AAAA,2DAAkF;AAClF,+BAA4B;AAC5B,2DAAqD;AACrD,4DAAwD;AACxD,iEAAiE;AACjE,uDAA+D;AAC/D,kEAAkE;AAGlE,SAAgB,KAAK,CAAC,OAAoB;IACxC,OAAO,CAAC,IAAU,EAAE,EAAE;QACpB,IAAI,IAAA,oBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACzB,MAAM,IAAI,gCAAmB,CAAC,sCAAsC,CAAC,CAAC;SACvE;QAED,MAAM,QAAQ,GAAG,IAAA,4BAAkB,EAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAC3D,MAAM,YAAY,GAAG,IAAA,8BAAe,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAErD,MAAM,iBAAiB,GAAG,IAAA,wCAAoB,EAAC,OAAO,CAAC,CAAC;QACxD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI;YACvB,CAAC,CAAC,iBAAiB,CAAC,IAAI;YACxB,CAAC,CAAC,IAAA,WAAI,EAAC,iBAAiB,CAAC,IAAI,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAEzD,OAAO,IAAA,8BAAa,EAAC,IAAA,gBAAG,EAAC,SAAS,CAAC,EAAE,IAAI,kCAAO,OAAO,KAAE,YAAY,KAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzF,CAAC,CAAC;AACJ,CAAC;AAhBD,sBAgBC"}
@@ -1,3 +1,3 @@
1
1
  {
2
- "@ngxs/store": "3.8.1"
2
+ "@ngxs/store": "3.8.2"
3
3
  }