@ngxs/store 3.8.1 → 3.8.2-dev.master-a75608e

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 (284) hide show
  1. package/esm2020/internals/index.mjs +6 -0
  2. package/esm2020/internals/initial-state.mjs +18 -0
  3. package/esm2020/internals/internal-tokens.mjs +6 -0
  4. package/{esm2015/internals/ngxs-bootstrapper.js → esm2020/internals/ngxs-bootstrapper.mjs} +4 -4
  5. package/esm2020/internals/src/symbols.mjs +11 -0
  6. package/esm2020/internals/symbols.mjs +11 -0
  7. package/esm2020/internals/testing/fresh-platform.mjs +72 -0
  8. package/{esm2015/internals/testing/helpers/ngxs-test.component.js → esm2020/internals/testing/helpers/ngxs-test.component.mjs} +4 -4
  9. package/esm2020/internals/testing/helpers/ngxs-test.module.mjs +20 -0
  10. package/{esm2015/internals/testing/ngxs.setup.js → esm2020/internals/testing/ngxs.setup.mjs} +4 -2
  11. package/esm2020/internals/testing/symbol.mjs +2 -0
  12. package/esm2020/operators/patch.mjs +21 -0
  13. package/esm2020/src/actions/actions.mjs +16 -0
  14. package/{esm2015/src/actions-stream.js → esm2020/src/actions-stream.mjs} +7 -7
  15. package/esm2020/src/configs/messages.config.mjs +48 -0
  16. package/{esm2015/src/decorators/select/select-factory.js → esm2020/src/decorators/select/select-factory.mjs} +4 -4
  17. package/esm2020/src/decorators/selector/selector.mjs +32 -0
  18. package/esm2020/src/decorators/state.mjs +36 -0
  19. package/{esm2015/src/dev-features/ngxs-development.module.js → esm2020/src/dev-features/ngxs-development.module.mjs} +5 -5
  20. package/{esm2015/src/dev-features/ngxs-unhandled-actions-logger.js → esm2020/src/dev-features/ngxs-unhandled-actions-logger.mjs} +4 -4
  21. package/{esm2015/src/execution/dispatch-outside-zone-ngxs-execution-strategy.js → esm2020/src/execution/dispatch-outside-zone-ngxs-execution-strategy.mjs} +4 -4
  22. package/{esm2015/src/execution/internal-ngxs-execution-strategy.js → esm2020/src/execution/internal-ngxs-execution-strategy.mjs} +4 -4
  23. package/{esm2015/src/execution/noop-ngxs-execution-strategy.js → esm2020/src/execution/noop-ngxs-execution-strategy.mjs} +4 -4
  24. package/esm2020/src/execution/symbols.mjs +27 -0
  25. package/{esm2015/src/internal/custom-rxjs-subjects.js → esm2020/src/internal/custom-rxjs-subjects.mjs} +2 -2
  26. package/{esm2015/src/internal/dispatcher.js → esm2020/src/internal/dispatcher.mjs} +11 -11
  27. package/{esm2015/src/internal/error-handler.js → esm2020/src/internal/error-handler.mjs} +5 -5
  28. package/esm2020/src/internal/internals.mjs +248 -0
  29. package/esm2020/src/internal/lifecycle-state-manager.mjs +97 -0
  30. package/esm2020/src/internal/state-context-factory.mjs +68 -0
  31. package/esm2020/src/internal/state-factory.mjs +292 -0
  32. package/{esm2015/src/internal/state-operations.js → esm2020/src/internal/state-operations.mjs} +5 -5
  33. package/esm2020/src/internal/state-operators.mjs +20 -0
  34. package/esm2020/src/internal/state-stream.mjs +27 -0
  35. package/{esm2015/src/ivy/ivy-enabled-in-dev-mode.js → esm2020/src/ivy/ivy-enabled-in-dev-mode.mjs} +2 -2
  36. package/esm2020/src/module.mjs +27 -0
  37. package/esm2020/src/modules/ngxs-feature.module.mjs +18 -0
  38. package/esm2020/src/modules/ngxs-root.module.mjs +18 -0
  39. package/{esm2015/src/operators/of-action.js → esm2020/src/operators/of-action.mjs} +10 -10
  40. package/{esm2015/src/plugin-manager.js → esm2020/src/plugin-manager.mjs} +4 -4
  41. package/esm2020/src/public_api.mjs +28 -0
  42. package/esm2020/src/selectors/create-model-selector.mjs +30 -0
  43. package/esm2020/src/selectors/create-pick-selector.mjs +16 -0
  44. package/esm2020/src/selectors/create-property-selectors.mjs +20 -0
  45. package/esm2020/src/selectors/selector-metadata.mjs +35 -0
  46. package/esm2020/src/selectors/selector-types.util.mjs +2 -0
  47. package/esm2020/src/standalone-features/feature-providers.mjs +20 -0
  48. package/esm2020/src/standalone-features/index.mjs +4 -0
  49. package/esm2020/src/standalone-features/initializers.mjs +86 -0
  50. package/esm2020/src/standalone-features/plugin.mjs +20 -0
  51. package/esm2020/src/standalone-features/provide-states.mjs +26 -0
  52. package/esm2020/src/standalone-features/provide-store.mjs +26 -0
  53. package/esm2020/src/standalone-features/root-providers.mjs +47 -0
  54. package/{esm2015/src/store.js → esm2020/src/store.mjs} +6 -5
  55. package/esm2020/src/symbols.mjs +65 -0
  56. package/esm2020/src/utils/store-validators.mjs +25 -0
  57. package/esm2020/src/utils/utils.mjs +92 -0
  58. package/fesm2015/{ngxs-store-internals-testing.js → ngxs-store-internals-testing.mjs} +19 -13
  59. package/fesm2015/ngxs-store-internals-testing.mjs.map +1 -0
  60. package/fesm2015/{ngxs-store-internals.js → ngxs-store-internals.mjs} +21 -21
  61. package/fesm2015/ngxs-store-internals.mjs.map +1 -0
  62. package/fesm2015/{ngxs-store-operators.js → ngxs-store-operators.mjs} +2 -2
  63. package/fesm2015/ngxs-store-operators.mjs.map +1 -0
  64. package/fesm2015/ngxs-store.mjs +2454 -0
  65. package/fesm2015/ngxs-store.mjs.map +1 -0
  66. package/fesm2020/ngxs-store-internals-testing.mjs +180 -0
  67. package/fesm2020/ngxs-store-internals-testing.mjs.map +1 -0
  68. package/fesm2020/ngxs-store-internals.mjs +114 -0
  69. package/fesm2020/ngxs-store-internals.mjs.map +1 -0
  70. package/fesm2020/ngxs-store-operators.mjs +202 -0
  71. package/fesm2020/ngxs-store-operators.mjs.map +1 -0
  72. package/{fesm2015/ngxs-store.js → fesm2020/ngxs-store.mjs} +1190 -1036
  73. package/fesm2020/ngxs-store.mjs.map +1 -0
  74. package/internals/index.d.ts +1 -2
  75. package/internals/initial-state.d.ts +1 -1
  76. package/internals/src/symbols.d.ts +4 -1
  77. package/internals/symbols.d.ts +4 -1
  78. package/internals/testing/helpers/ngxs-test.component.d.ts +1 -1
  79. package/internals/testing/symbol.d.ts +2 -2
  80. package/package.json +49 -12
  81. package/schematics/collection.json +36 -0
  82. package/schematics/src/actions/actions.factory.d.ts +3 -0
  83. package/schematics/src/actions/actions.factory.js +22 -0
  84. package/schematics/src/actions/actions.factory.js.map +1 -0
  85. package/schematics/src/actions/files/__name__.actions.ts__template__ +4 -0
  86. package/schematics/src/actions/schema.json +28 -0
  87. package/schematics/src/ng-add/add-declaration.d.ts +4 -0
  88. package/schematics/src/ng-add/add-declaration.js +109 -0
  89. package/schematics/src/ng-add/add-declaration.js.map +1 -0
  90. package/schematics/src/ng-add/ng-add.factory.d.ts +9 -0
  91. package/schematics/src/ng-add/ng-add.factory.js +86 -0
  92. package/schematics/src/ng-add/ng-add.factory.js.map +1 -0
  93. package/schematics/src/ng-add/schema.json +72 -0
  94. package/schematics/src/starter-kit/files/store/auth/auth.actions.ts__template__ +7 -0
  95. package/schematics/src/starter-kit/files/store/auth/auth.state.spec.ts__template__ +54 -0
  96. package/schematics/src/starter-kit/files/store/auth/auth.state.ts__template__ +47 -0
  97. package/schematics/src/starter-kit/files/store/dashboard/index.ts__template__ +11 -0
  98. package/schematics/src/starter-kit/files/store/dashboard/states/dictionary/dictionary.actions.ts__template__ +13 -0
  99. package/schematics/src/starter-kit/files/store/dashboard/states/dictionary/dictionary.state.spec.ts__template__ +91 -0
  100. package/schematics/src/starter-kit/files/store/dashboard/states/dictionary/dictionary.state.ts__template__ +62 -0
  101. package/schematics/src/starter-kit/files/store/dashboard/states/user/user.actions.ts__template__ +6 -0
  102. package/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.spec.ts__template__ +60 -0
  103. package/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.ts__template__ +42 -0
  104. package/schematics/src/starter-kit/files/store/store.config.ts__template__ +38 -0
  105. package/schematics/src/starter-kit/files/store/store.module.ts__template__ +22 -0
  106. package/schematics/src/starter-kit/schema.json +18 -0
  107. package/schematics/src/starter-kit/starter-kit.factory.d.ts +3 -0
  108. package/schematics/src/starter-kit/starter-kit.factory.js +12 -0
  109. package/schematics/src/starter-kit/starter-kit.factory.js.map +1 -0
  110. package/schematics/src/state/files/__name__.state.spec.ts__template__ +24 -0
  111. package/schematics/src/state/files/__name__.state.ts__template__ +22 -0
  112. package/schematics/src/state/schema.json +33 -0
  113. package/schematics/src/state/state.factory.d.ts +3 -0
  114. package/schematics/src/state/state.factory.js +20 -0
  115. package/schematics/src/state/state.factory.js.map +1 -0
  116. package/schematics/src/store/files/__name__.actions.ts__template__ +4 -0
  117. package/schematics/src/store/files/__name__.state.spec.ts__template__ +25 -0
  118. package/schematics/src/store/files/__name__.state.ts__template__ +29 -0
  119. package/schematics/src/store/schema.json +33 -0
  120. package/schematics/src/store/store.factory.d.ts +3 -0
  121. package/schematics/src/store/store.factory.js +20 -0
  122. package/schematics/src/store/store.factory.js.map +1 -0
  123. package/schematics/src/utils/common/lib.config.d.ts +10 -0
  124. package/schematics/src/utils/common/lib.config.js +15 -0
  125. package/schematics/src/utils/common/lib.config.js.map +1 -0
  126. package/schematics/src/utils/common/project-files.config.d.ts +3 -0
  127. package/schematics/src/utils/common/project-files.config.js +7 -0
  128. package/schematics/src/utils/common/project-files.config.js.map +1 -0
  129. package/schematics/src/utils/common/properties.d.ts +1 -0
  130. package/schematics/src/utils/common/properties.js +8 -0
  131. package/schematics/src/utils/common/properties.js.map +1 -0
  132. package/schematics/src/utils/config.d.ts +119 -0
  133. package/schematics/src/utils/config.js +21 -0
  134. package/schematics/src/utils/config.js.map +1 -0
  135. package/schematics/src/utils/generate-utils.d.ts +4 -0
  136. package/schematics/src/utils/generate-utils.js +14 -0
  137. package/schematics/src/utils/generate-utils.js.map +1 -0
  138. package/schematics/src/utils/interfaces/package.interface.d.ts +7 -0
  139. package/schematics/src/utils/interfaces/package.interface.js +3 -0
  140. package/schematics/src/utils/interfaces/package.interface.js.map +1 -0
  141. package/schematics/src/utils/ng-utils/README.md +1 -0
  142. package/schematics/src/utils/ng-utils/ast-utils.d.ts +99 -0
  143. package/schematics/src/utils/ng-utils/ast-utils.js +517 -0
  144. package/schematics/src/utils/ng-utils/ast-utils.js.map +1 -0
  145. package/schematics/src/utils/ng-utils/ng-ast-utils.d.ts +5 -0
  146. package/schematics/src/utils/ng-utils/ng-ast-utils.js +67 -0
  147. package/schematics/src/utils/ng-utils/ng-ast-utils.js.map +1 -0
  148. package/schematics/src/utils/ng-utils/project.d.ts +2 -0
  149. package/schematics/src/utils/ng-utils/project.js +21 -0
  150. package/schematics/src/utils/ng-utils/project.js.map +1 -0
  151. package/schematics/src/utils/ng-utils/standalone/app_config.d.ts +16 -0
  152. package/schematics/src/utils/ng-utils/standalone/app_config.js +84 -0
  153. package/schematics/src/utils/ng-utils/standalone/app_config.js.map +1 -0
  154. package/schematics/src/utils/ng-utils/standalone/code_block.d.ts +46 -0
  155. package/schematics/src/utils/ng-utils/standalone/code_block.js +73 -0
  156. package/schematics/src/utils/ng-utils/standalone/code_block.js.map +1 -0
  157. package/schematics/src/utils/ng-utils/standalone/index.d.ts +1 -0
  158. package/schematics/src/utils/ng-utils/standalone/index.js +7 -0
  159. package/schematics/src/utils/ng-utils/standalone/index.js.map +1 -0
  160. package/schematics/src/utils/ng-utils/standalone/rules.d.ts +38 -0
  161. package/schematics/src/utils/ng-utils/standalone/rules.js +195 -0
  162. package/schematics/src/utils/ng-utils/standalone/rules.js.map +1 -0
  163. package/schematics/src/utils/ng-utils/standalone/util.d.ts +28 -0
  164. package/schematics/src/utils/ng-utils/standalone/util.js +138 -0
  165. package/schematics/src/utils/ng-utils/standalone/util.js.map +1 -0
  166. package/schematics/src/utils/normalize-options.d.ts +9 -0
  167. package/schematics/src/utils/normalize-options.js +24 -0
  168. package/schematics/src/utils/normalize-options.js.map +1 -0
  169. package/schematics/src/utils/project.d.ts +16 -0
  170. package/schematics/src/utils/project.js +40 -0
  171. package/schematics/src/utils/project.js.map +1 -0
  172. package/schematics/src/utils/versions.json +3 -0
  173. package/src/actions/actions.d.ts +2 -2
  174. package/src/configs/messages.config.d.ts +2 -0
  175. package/src/decorators/state.d.ts +2 -2
  176. package/src/execution/symbols.d.ts +8 -2
  177. package/src/internal/custom-rxjs-subjects.d.ts +1 -1
  178. package/src/internal/internals.d.ts +5 -5
  179. package/src/internal/lifecycle-state-manager.d.ts +3 -1
  180. package/src/internal/state-factory.d.ts +1 -1
  181. package/src/module.d.ts +3 -14
  182. package/src/modules/ngxs-feature.module.d.ts +2 -9
  183. package/src/modules/ngxs-root.module.d.ts +2 -9
  184. package/src/public_api.d.ts +5 -4
  185. package/src/selectors/selector-types.util.d.ts +3 -3
  186. package/src/standalone-features/feature-providers.d.ts +7 -0
  187. package/src/standalone-features/index.d.ts +3 -0
  188. package/src/standalone-features/initializers.d.ts +29 -0
  189. package/src/standalone-features/plugin.d.ts +17 -0
  190. package/src/standalone-features/provide-states.d.ts +18 -0
  191. package/src/standalone-features/provide-store.d.ts +22 -0
  192. package/src/standalone-features/root-providers.d.ts +8 -0
  193. package/src/symbols.d.ts +5 -8
  194. package/src/utils/store-validators.d.ts +3 -6
  195. package/bundles/ngxs-store-internals-testing.umd.js +0 -547
  196. package/bundles/ngxs-store-internals-testing.umd.js.map +0 -1
  197. package/bundles/ngxs-store-internals.umd.js +0 -155
  198. package/bundles/ngxs-store-internals.umd.js.map +0 -1
  199. package/bundles/ngxs-store-operators.umd.js +0 -224
  200. package/bundles/ngxs-store-operators.umd.js.map +0 -1
  201. package/bundles/ngxs-store.umd.js +0 -2960
  202. package/bundles/ngxs-store.umd.js.map +0 -1
  203. package/esm2015/internals/angular.js +0 -13
  204. package/esm2015/internals/index.js +0 -6
  205. package/esm2015/internals/initial-state.js +0 -17
  206. package/esm2015/internals/internal-tokens.js +0 -5
  207. package/esm2015/internals/src/symbols.js +0 -2
  208. package/esm2015/internals/symbols.js +0 -2
  209. package/esm2015/internals/testing/fresh-platform.js +0 -70
  210. package/esm2015/internals/testing/helpers/ngxs-test.module.js +0 -21
  211. package/esm2015/internals/testing/symbol.js +0 -2
  212. package/esm2015/operators/patch.js +0 -21
  213. package/esm2015/src/actions/actions.js +0 -22
  214. package/esm2015/src/configs/messages.config.js +0 -36
  215. package/esm2015/src/decorators/selector/selector.js +0 -32
  216. package/esm2015/src/decorators/state.js +0 -38
  217. package/esm2015/src/execution/symbols.js +0 -23
  218. package/esm2015/src/internal/internals.js +0 -248
  219. package/esm2015/src/internal/lifecycle-state-manager.js +0 -79
  220. package/esm2015/src/internal/state-context-factory.js +0 -70
  221. package/esm2015/src/internal/state-factory.js +0 -291
  222. package/esm2015/src/internal/state-operators.js +0 -20
  223. package/esm2015/src/internal/state-stream.js +0 -25
  224. package/esm2015/src/module.js +0 -88
  225. package/esm2015/src/modules/ngxs-feature.module.js +0 -45
  226. package/esm2015/src/modules/ngxs-root.module.js +0 -41
  227. package/esm2015/src/public_api.js +0 -27
  228. package/esm2015/src/selectors/create-model-selector.js +0 -28
  229. package/esm2015/src/selectors/create-pick-selector.js +0 -14
  230. package/esm2015/src/selectors/create-property-selectors.js +0 -18
  231. package/esm2015/src/selectors/selector-metadata.js +0 -30
  232. package/esm2015/src/selectors/selector-types.util.js +0 -2
  233. package/esm2015/src/symbols.js +0 -58
  234. package/esm2015/src/utils/store-validators.js +0 -27
  235. package/esm2015/src/utils/utils.js +0 -92
  236. package/fesm2015/ngxs-store-internals-testing.js.map +0 -1
  237. package/fesm2015/ngxs-store-internals.js.map +0 -1
  238. package/fesm2015/ngxs-store-operators.js.map +0 -1
  239. package/fesm2015/ngxs-store.js.map +0 -1
  240. package/internals/angular.d.ts +0 -1
  241. package/internals/ngxs-store-internals.d.ts +0 -5
  242. package/internals/package.json +0 -10
  243. package/internals/testing/ngxs-store-internals-testing.d.ts +0 -5
  244. package/internals/testing/package.json +0 -10
  245. package/ngxs-store.d.ts +0 -5
  246. package/operators/ngxs-store-operators.d.ts +0 -5
  247. package/operators/package.json +0 -10
  248. /package/{esm2015/index.js → esm2020/index.mjs} +0 -0
  249. /package/{esm2015/internals/memoize.js → esm2020/internals/memoize.mjs} +0 -0
  250. /package/{esm2015/internals/ngxs-store-internals.js → esm2020/internals/ngxs-store-internals.mjs} +0 -0
  251. /package/{esm2015/internals/testing/index.js → esm2020/internals/testing/index.mjs} +0 -0
  252. /package/{esm2015/internals/testing/ngxs-store-internals-testing.js → esm2020/internals/testing/ngxs-store-internals-testing.mjs} +0 -0
  253. /package/{esm2015/internals/testing/skip-console-logging.js → esm2020/internals/testing/skip-console-logging.mjs} +0 -0
  254. /package/{esm2015/ngxs-store.js → esm2020/ngxs-store.mjs} +0 -0
  255. /package/{esm2015/operators/append.js → esm2020/operators/append.mjs} +0 -0
  256. /package/{esm2015/operators/compose.js → esm2020/operators/compose.mjs} +0 -0
  257. /package/{esm2015/operators/iif.js → esm2020/operators/iif.mjs} +0 -0
  258. /package/{esm2015/operators/index.js → esm2020/operators/index.mjs} +0 -0
  259. /package/{esm2015/operators/insert-item.js → esm2020/operators/insert-item.mjs} +0 -0
  260. /package/{esm2015/operators/ngxs-store-operators.js → esm2020/operators/ngxs-store-operators.mjs} +0 -0
  261. /package/{esm2015/operators/remove-item.js → esm2020/operators/remove-item.mjs} +0 -0
  262. /package/{esm2015/operators/types.js → esm2020/operators/types.mjs} +0 -0
  263. /package/{esm2015/operators/update-item.js → esm2020/operators/update-item.mjs} +0 -0
  264. /package/{esm2015/operators/utils.js → esm2020/operators/utils.mjs} +0 -0
  265. /package/{esm2015/src/actions/symbols.js → esm2020/src/actions/symbols.mjs} +0 -0
  266. /package/{esm2015/src/decorators/action.js → esm2020/src/decorators/action.mjs} +0 -0
  267. /package/{esm2015/src/decorators/select/select.js → esm2020/src/decorators/select/select.mjs} +0 -0
  268. /package/{esm2015/src/decorators/select/symbols.js → esm2020/src/decorators/select/symbols.mjs} +0 -0
  269. /package/{esm2015/src/decorators/selector/symbols.js → esm2020/src/decorators/selector/symbols.mjs} +0 -0
  270. /package/{esm2015/src/decorators/selector-options.js → esm2020/src/decorators/selector-options.mjs} +0 -0
  271. /package/{esm2015/src/dev-features/symbols.js → esm2020/src/dev-features/symbols.mjs} +0 -0
  272. /package/{esm2015/src/operators/leave-ngxs.js → esm2020/src/operators/leave-ngxs.mjs} +0 -0
  273. /package/{esm2015/src/plugin_api.js → esm2020/src/plugin_api.mjs} +0 -0
  274. /package/{esm2015/src/private_api.js → esm2020/src/private_api.mjs} +0 -0
  275. /package/{esm2015/src/public_to_deprecate.js → esm2020/src/public_to_deprecate.mjs} +0 -0
  276. /package/{esm2015/src/selectors/create-selector.js → esm2020/src/selectors/create-selector.mjs} +0 -0
  277. /package/{esm2015/src/selectors/index.js → esm2020/src/selectors/index.mjs} +0 -0
  278. /package/{esm2015/src/selectors/selector-checks.util.js → esm2020/src/selectors/selector-checks.util.mjs} +0 -0
  279. /package/{esm2015/src/selectors/selector-models.js → esm2020/src/selectors/selector-models.mjs} +0 -0
  280. /package/{esm2015/src/selectors/selector-utils.js → esm2020/src/selectors/selector-utils.mjs} +0 -0
  281. /package/{esm2015/src/state-token/state-token.js → esm2020/src/state-token/state-token.mjs} +0 -0
  282. /package/{esm2015/src/state-token/symbols.js → esm2020/src/state-token/symbols.mjs} +0 -0
  283. /package/{esm2015/src/utils/compose.js → esm2020/src/utils/compose.mjs} +0 -0
  284. /package/{esm2015/src/utils/freeze.js → esm2020/src/utils/freeze.mjs} +0 -0
@@ -1,102 +1,26 @@
1
1
  import * as i0 from '@angular/core';
2
- import { NgZone, PLATFORM_ID, Injectable, Inject, InjectionToken, inject, INJECTOR, ɵglobal, ErrorHandler, Optional, SkipSelf, NgModule, APP_BOOTSTRAP_LISTENER } from '@angular/core';
2
+ import { Injectable, NgZone, PLATFORM_ID, Inject, InjectionToken, inject, INJECTOR, ɵglobal, ErrorHandler, Optional, SkipSelf, ENVIRONMENT_INITIALIZER, NgModule, APP_BOOTSTRAP_LISTENER, makeEnvironmentProviders } from '@angular/core';
3
+ import { Observable, Subject, BehaviorSubject, of, forkJoin, throwError, EMPTY, from, isObservable, ReplaySubject } from 'rxjs';
4
+ import { share, shareReplay, filter, take, exhaustMap, map, mergeMap, defaultIfEmpty, catchError, takeUntil, distinctUntilChanged, tap, startWith, pairwise } from 'rxjs/operators';
3
5
  import * as i5 from '@ngxs/store/internals';
4
- import { memoize, INITIAL_STATE_TOKEN, NgxsBootstrapper, ɵNGXS_STATE_CONTEXT_FACTORY, ɵNGXS_STATE_FACTORY } from '@ngxs/store/internals';
6
+ import { ɵMETA_KEY, ɵSELECTOR_META_KEY, memoize, INITIAL_STATE_TOKEN, NgxsBootstrapper, ɵNGXS_STATE_CONTEXT_FACTORY, ɵNGXS_STATE_FACTORY, ɵMETA_OPTIONS_KEY } from '@ngxs/store/internals';
5
7
  import { isPlatformServer } from '@angular/common';
6
- import { Observable, Subject, BehaviorSubject, of, forkJoin, throwError, EMPTY, from, isObservable } from 'rxjs';
7
- import { filter, map, share, shareReplay, take, exhaustMap, mergeMap, defaultIfEmpty, catchError, takeUntil, distinctUntilChanged, tap, startWith, pairwise } from 'rxjs/operators';
8
+ import { isStateOperator } from '@ngxs/store/operators';
8
9
 
9
- /**
10
- * Returns the type from an action instance/class.
11
- * @ignore
12
- */
13
- function getActionTypeFromInstance(action) {
14
- if (action.constructor && action.constructor.type) {
15
- return action.constructor.type;
10
+ class NoopNgxsExecutionStrategy {
11
+ enter(func) {
12
+ return func();
16
13
  }
17
- else {
18
- return action.type;
14
+ leave(func) {
15
+ return func();
19
16
  }
20
17
  }
21
- /**
22
- * Matches a action
23
- * @ignore
24
- */
25
- function actionMatcher(action1) {
26
- const type1 = getActionTypeFromInstance(action1);
27
- return function (action2) {
28
- return type1 === getActionTypeFromInstance(action2);
29
- };
30
- }
31
- /**
32
- * Set a deeply nested value. Example:
33
- *
34
- * setValue({ foo: { bar: { eat: false } } },
35
- * 'foo.bar.eat', true) //=> { foo: { bar: { eat: true } } }
36
- *
37
- * While it traverses it also creates new objects from top down.
38
- *
39
- * @ignore
40
- */
41
- const setValue = (obj, prop, val) => {
42
- obj = Object.assign({}, obj);
43
- const split = prop.split('.');
44
- const lastIndex = split.length - 1;
45
- split.reduce((acc, part, index) => {
46
- if (index === lastIndex) {
47
- acc[part] = val;
48
- }
49
- else {
50
- acc[part] = Array.isArray(acc[part]) ? acc[part].slice() : Object.assign({}, acc[part]);
51
- }
52
- return acc && acc[part];
53
- }, obj);
54
- return obj;
55
- };
56
- /**
57
- * Get a deeply nested value. Example:
58
- *
59
- * getValue({ foo: bar: [] }, 'foo.bar') //=> []
60
- *
61
- * @ignore
62
- */
63
- const getValue = (obj, prop) => prop.split('.').reduce((acc, part) => acc && acc[part], obj);
64
- /**
65
- * Simple object check.
66
- *
67
- * isObject({a:1}) //=> true
68
- * isObject(1) //=> false
69
- *
70
- * @ignore
71
- */
72
- const isObject$1 = (item) => {
73
- return item && typeof item === 'object' && !Array.isArray(item);
74
- };
75
- /**
76
- * Deep merge two objects.
77
- *
78
- * mergeDeep({a:1, b:{x: 1, y:2}}, {b:{x: 3}, c:4}) //=> {a:1, b:{x:3, y:2}, c:4}
79
- *
80
- * @param base base object onto which `sources` will be applied
81
- */
82
- const mergeDeep = (base, ...sources) => {
83
- if (!sources.length)
84
- return base;
85
- const source = sources.shift();
86
- if (isObject$1(base) && isObject$1(source)) {
87
- for (const key in source) {
88
- if (isObject$1(source[key])) {
89
- if (!base[key])
90
- Object.assign(base, { [key]: {} });
91
- mergeDeep(base[key], source[key]);
92
- }
93
- else {
94
- Object.assign(base, { [key]: source[key] });
95
- }
96
- }
97
- }
98
- return mergeDeep(base, ...sources);
99
- };
18
+ /** @nocollapse */ NoopNgxsExecutionStrategy.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NoopNgxsExecutionStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
19
+ /** @nocollapse */ NoopNgxsExecutionStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NoopNgxsExecutionStrategy, providedIn: 'root' });
20
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NoopNgxsExecutionStrategy, decorators: [{
21
+ type: Injectable,
22
+ args: [{ providedIn: 'root' }]
23
+ }] });
100
24
 
101
25
  function throwStateNameError(name) {
102
26
  throw new Error(`${name} is not a valid state name. It needs to be a valid object property name.`);
@@ -124,6 +48,18 @@ function getZoneWarningMessage() {
124
48
  function getUndecoratedStateInIvyWarningMessage(name) {
125
49
  return `'${name}' class should be decorated with @Injectable() right after the @State() decorator`;
126
50
  }
51
+ function getInvalidInitializationOrderMessage(addedStates) {
52
+ let message = 'You have an invalid state initialization order. This typically occurs when `NgxsModule.forFeature`\n' +
53
+ 'or `provideStates` is called before `NgxsModule.forRoot` or `provideStore`.\n' +
54
+ 'One example is when `NgxsRouterPluginModule.forRoot` is called before `NgxsModule.forRoot`.';
55
+ if (addedStates) {
56
+ const stateNames = Object.keys(addedStates).map(stateName => `"${stateName}"`);
57
+ message +=
58
+ '\nFeature states added before the store initialization is complete: ' +
59
+ `${stateNames.join(', ')}.`;
60
+ }
61
+ return message;
62
+ }
127
63
  function throwSelectFactoryNotConnectedError() {
128
64
  throw new Error('You have forgotten to import the NGXS module!');
129
65
  }
@@ -166,9 +102,9 @@ class DispatchOutsideZoneNgxsExecutionStrategy {
166
102
  return func();
167
103
  }
168
104
  }
169
- /** @nocollapse */ DispatchOutsideZoneNgxsExecutionStrategy.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, deps: [{ token: i0.NgZone }, { token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable });
170
- /** @nocollapse */ DispatchOutsideZoneNgxsExecutionStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, providedIn: 'root' });
171
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, decorators: [{
105
+ /** @nocollapse */ DispatchOutsideZoneNgxsExecutionStrategy.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, deps: [{ token: i0.NgZone }, { token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable });
106
+ /** @nocollapse */ DispatchOutsideZoneNgxsExecutionStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, providedIn: 'root' });
107
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, decorators: [{
172
108
  type: Injectable,
173
109
  args: [{ providedIn: 'root' }]
174
110
  }], ctorParameters: function () { return [{ type: i0.NgZone }, { type: undefined, decorators: [{
@@ -187,87 +123,22 @@ function verifyZoneIsNotNooped(ngZone) {
187
123
  console.warn(getZoneWarningMessage());
188
124
  }
189
125
 
190
- const ROOT_OPTIONS = new InjectionToken('ROOT_OPTIONS');
191
- const ROOT_STATE_TOKEN = new InjectionToken('ROOT_STATE_TOKEN');
192
- const FEATURE_STATE_TOKEN = new InjectionToken('FEATURE_STATE_TOKEN');
193
- const NGXS_PLUGINS = new InjectionToken('NGXS_PLUGINS');
194
- const META_KEY = 'NGXS_META';
195
- const META_OPTIONS_KEY = 'NGXS_OPTIONS_META';
196
- const SELECTOR_META_KEY = 'NGXS_SELECTOR_META';
126
+ const NG_DEV_MODE$4 = typeof ngDevMode === 'undefined' || ngDevMode;
197
127
  /**
198
- * The NGXS config settings.
199
- */
200
- class NgxsConfig {
201
- constructor() {
202
- /**
203
- * Defining the default state before module initialization
204
- * This is convenient if we need to create a define our own set of states.
205
- * @deprecated will be removed after v4
206
- * (default: {})
207
- */
208
- this.defaultsState = {};
209
- /**
210
- * Defining shared selector options
211
- */
212
- this.selectorOptions = {
213
- injectContainerState: true,
214
- suppressErrors: true // TODO: default is true in v3, will change in v4
215
- };
216
- this.compatibility = {
217
- strictContentSecurityPolicy: false
218
- };
219
- this.executionStrategy = DispatchOutsideZoneNgxsExecutionStrategy;
220
- }
221
- }
222
- /** @nocollapse */ NgxsConfig.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsConfig, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
223
- /** @nocollapse */ NgxsConfig.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsConfig, providedIn: 'root', useFactory: (options) => mergeDeep(new NgxsConfig(), options), deps: [{ token: ROOT_OPTIONS }] });
224
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsConfig, decorators: [{
225
- type: Injectable,
226
- args: [{
227
- providedIn: 'root',
228
- useFactory: (options) => mergeDeep(new NgxsConfig(), options),
229
- deps: [ROOT_OPTIONS]
230
- }]
231
- }], ctorParameters: function () { return []; } });
232
- /**
233
- * Represents a basic change from a previous to a new value for a single state instance.
234
- * Passed as a value in a NgxsSimpleChanges object to the ngxsOnChanges hook.
128
+ * Consumers have the option to utilize the execution strategy provided by
129
+ * `NgxsModule.forRoot({executionStrategy})` or `provideStore([], {executionStrategy})`.
235
130
  */
236
- class NgxsSimpleChange {
237
- constructor(previousValue, currentValue, firstChange) {
238
- this.previousValue = previousValue;
239
- this.currentValue = currentValue;
240
- this.firstChange = firstChange;
241
- }
242
- }
243
-
244
- class NoopNgxsExecutionStrategy {
245
- enter(func) {
246
- return func();
247
- }
248
- leave(func) {
249
- return func();
250
- }
251
- }
252
- /** @nocollapse */ NoopNgxsExecutionStrategy.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NoopNgxsExecutionStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
253
- /** @nocollapse */ NoopNgxsExecutionStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NoopNgxsExecutionStrategy, providedIn: 'root' });
254
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NoopNgxsExecutionStrategy, decorators: [{
255
- type: Injectable,
256
- args: [{ providedIn: 'root' }]
257
- }] });
258
-
131
+ const CUSTOM_NGXS_EXECUTION_STRATEGY = new InjectionToken(NG_DEV_MODE$4 ? 'CUSTOM_NGXS_EXECUTION_STRATEGY' : '');
259
132
  /**
260
- * The strategy that might be provided by users through `options.executionStrategy`.
133
+ * The injection token is used internally to resolve an instance of the execution
134
+ * strategy. It checks whether consumers have provided their own `executionStrategy`
135
+ * and also verifies if we are operating in a zone-aware environment.
261
136
  */
262
- const USER_PROVIDED_NGXS_EXECUTION_STRATEGY = new InjectionToken('USER_PROVIDED_NGXS_EXECUTION_STRATEGY');
263
- /*
264
- * Internal execution strategy injection token
265
- */
266
- const NGXS_EXECUTION_STRATEGY = new InjectionToken('NGXS_EXECUTION_STRATEGY', {
137
+ const NGXS_EXECUTION_STRATEGY = new InjectionToken(NG_DEV_MODE$4 ? 'NGXS_EXECUTION_STRATEGY' : '', {
267
138
  providedIn: 'root',
268
139
  factory: () => {
269
140
  const injector = inject(INJECTOR);
270
- const executionStrategy = injector.get(USER_PROVIDED_NGXS_EXECUTION_STRATEGY);
141
+ const executionStrategy = injector.get(CUSTOM_NGXS_EXECUTION_STRATEGY);
271
142
  return executionStrategy
272
143
  ? injector.get(executionStrategy)
273
144
  : injector.get(typeof ɵglobal.Zone !== 'undefined'
@@ -276,456 +147,195 @@ const NGXS_EXECUTION_STRATEGY = new InjectionToken('NGXS_EXECUTION_STRATEGY', {
276
147
  }
277
148
  });
278
149
 
279
- /**
280
- * Ensures metadata is attached to the class and returns it.
281
- *
282
- * @ignore
283
- */
284
- function ensureStoreMetadata$1(target) {
285
- if (!target.hasOwnProperty(META_KEY)) {
286
- const defaultMetadata = {
287
- name: null,
288
- actions: {},
289
- defaults: {},
290
- path: null,
291
- makeRootSelector(context) {
292
- return context.getStateGetter(defaultMetadata.name);
293
- },
294
- children: []
295
- };
296
- Object.defineProperty(target, META_KEY, { value: defaultMetadata });
150
+ class InternalNgxsExecutionStrategy {
151
+ constructor(_executionStrategy) {
152
+ this._executionStrategy = _executionStrategy;
153
+ }
154
+ enter(func) {
155
+ return this._executionStrategy.enter(func);
156
+ }
157
+ leave(func) {
158
+ return this._executionStrategy.leave(func);
297
159
  }
298
- return getStoreMetadata$1(target);
299
160
  }
161
+ /** @nocollapse */ InternalNgxsExecutionStrategy.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalNgxsExecutionStrategy, deps: [{ token: NGXS_EXECUTION_STRATEGY }], target: i0.ɵɵFactoryTarget.Injectable });
162
+ /** @nocollapse */ InternalNgxsExecutionStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalNgxsExecutionStrategy, providedIn: 'root' });
163
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalNgxsExecutionStrategy, decorators: [{
164
+ type: Injectable,
165
+ args: [{ providedIn: 'root' }]
166
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
167
+ type: Inject,
168
+ args: [NGXS_EXECUTION_STRATEGY]
169
+ }] }]; } });
170
+
300
171
  /**
301
- * Get the metadata attached to the state class if it exists.
172
+ * Composes a array of functions from left to right. Example:
302
173
  *
303
- * @ignore
304
- */
305
- function getStoreMetadata$1(target) {
306
- return target[META_KEY];
307
- }
308
- /**
309
- * Ensures metadata is attached to the selector and returns it.
174
+ * compose([fn, final])(state, action);
310
175
  *
311
- * @ignore
312
- */
313
- function ensureSelectorMetadata$1(target) {
314
- if (!target.hasOwnProperty(SELECTOR_META_KEY)) {
315
- const defaultMetadata = {
316
- makeRootSelector: null,
317
- originalFn: null,
318
- containerClass: null,
319
- selectorName: null,
320
- getSelectorOptions: () => ({})
321
- };
322
- Object.defineProperty(target, SELECTOR_META_KEY, { value: defaultMetadata });
323
- }
324
- return getSelectorMetadata$1(target);
325
- }
326
- /**
327
- * Get the metadata attached to the selector if it exists.
176
+ * then the funcs have a signature like:
328
177
  *
329
- * @ignore
330
- */
331
- function getSelectorMetadata$1(target) {
332
- return target[SELECTOR_META_KEY];
333
- }
334
- /**
335
- * Get a deeply nested value. Example:
178
+ * function fn (state, action, next) {
179
+ * console.log('here', state, action, next);
180
+ * return next(state, action);
181
+ * }
336
182
  *
337
- * getValue({ foo: bar: [] }, 'foo.bar') //=> []
183
+ * function final (state, action) {
184
+ * console.log('here', state, action);
185
+ * return state;
186
+ * }
338
187
  *
339
- * Note: This is not as fast as the `fastPropGetter` but is strict Content Security Policy compliant.
340
- * See perf hit: https://jsperf.com/fast-value-getter-given-path/1
188
+ * the last function should not call `next`.
341
189
  *
342
190
  * @ignore
343
191
  */
344
- function compliantPropGetter(paths) {
345
- const copyOfPaths = paths.slice();
346
- return obj => copyOfPaths.reduce((acc, part) => acc && acc[part], obj);
347
- }
192
+ const compose = (funcs) => (...args) => {
193
+ const curr = funcs.shift();
194
+ return curr(...args, (...nextArgs) => compose(funcs)(...nextArgs));
195
+ };
196
+
348
197
  /**
349
- * The generated function is faster than:
350
- * - pluck (Observable operator)
351
- * - memoize
352
- *
353
- * @ignore
198
+ * Returns operator that will run
199
+ * `subscribe` outside of the ngxs execution context
354
200
  */
355
- function fastPropGetter(paths) {
356
- const segments = paths;
357
- let seg = 'store.' + segments[0];
358
- let i = 0;
359
- const l = segments.length;
360
- let expr = seg;
361
- while (++i < l) {
362
- expr = expr + ' && ' + (seg = seg + '.' + segments[i]);
363
- }
364
- const fn = new Function('store', 'return ' + expr + ';');
365
- return fn;
366
- }
367
- /**
368
- * Get a deeply nested value. Example:
369
- *
370
- * getValue({ foo: bar: [] }, 'foo.bar') //=> []
371
- *
372
- * @ignore
373
- */
374
- function propGetter(paths, config) {
375
- if (config && config.compatibility && config.compatibility.strictContentSecurityPolicy) {
376
- return compliantPropGetter(paths);
377
- }
378
- else {
379
- return fastPropGetter(paths);
380
- }
381
- }
382
- /**
383
- * Given an array of states, it will return a object graph. Example:
384
- * const states = [
385
- * Cart,
386
- * CartSaved,
387
- * CartSavedItems
388
- * ]
389
- *
390
- * would return:
391
- *
392
- * const graph = {
393
- * cart: ['saved'],
394
- * saved: ['items'],
395
- * items: []
396
- * };
397
- *
398
- * @ignore
399
- */
400
- function buildGraph(stateClasses) {
401
- const findName = (stateClass) => {
402
- const meta = stateClasses.find(g => g === stateClass);
403
- // Caretaker note: we have still left the `typeof` condition in order to avoid
404
- // creating a breaking change for projects that still use the View Engine.
405
- if ((typeof ngDevMode === 'undefined' || ngDevMode) && !meta) {
406
- throw new Error(`Child state not found: ${stateClass}. \r\nYou may have forgotten to add states to module`);
407
- }
408
- return meta[META_KEY].name;
201
+ function leaveNgxs(ngxsExecutionStrategy) {
202
+ return (source) => {
203
+ return new Observable((sink) => {
204
+ return source.subscribe({
205
+ next(value) {
206
+ ngxsExecutionStrategy.leave(() => sink.next(value));
207
+ },
208
+ error(error) {
209
+ ngxsExecutionStrategy.leave(() => sink.error(error));
210
+ },
211
+ complete() {
212
+ ngxsExecutionStrategy.leave(() => sink.complete());
213
+ }
214
+ });
215
+ });
409
216
  };
410
- return stateClasses.reduce((result, stateClass) => {
411
- const { name, children } = stateClass[META_KEY];
412
- result[name] = (children || []).map(findName);
413
- return result;
414
- }, {});
415
- }
416
- /**
417
- * Given a states array, returns object graph
418
- * returning the name and state metadata. Example:
419
- *
420
- * const graph = {
421
- * cart: { metadata }
422
- * };
423
- *
424
- * @ignore
425
- */
426
- function nameToState(states) {
427
- return states.reduce((result, stateClass) => {
428
- const meta = stateClass[META_KEY];
429
- result[meta.name] = stateClass;
430
- return result;
431
- }, {});
432
217
  }
218
+
433
219
  /**
434
- * Given a object relationship graph will return the full path
435
- * for the child items. Example:
436
- *
437
- * const graph = {
438
- * cart: ['saved'],
439
- * saved: ['items'],
440
- * items: []
441
- * };
442
- *
443
- * would return:
444
- *
445
- * const r = {
446
- * cart: 'cart',
447
- * saved: 'cart.saved',
448
- * items: 'cart.saved.items'
449
- * };
450
- *
451
- * @ignore
220
+ * This operator is used for piping the observable result
221
+ * from the `dispatch()`. It has a "smart" error handling
222
+ * strategy that allows us to decide whether we propagate
223
+ * errors to Angular's `ErrorHandler` or enable users to
224
+ * handle them manually. We consider following cases:
225
+ * 1) `store.dispatch()` (no subscribe) -> call `handleError()`
226
+ * 2) `store.dispatch().subscribe()` (no error callback) -> call `handleError()`
227
+ * 3) `store.dispatch().subscribe({ error: ... })` -> don't call `handleError()`
228
+ * 4) `toPromise()` without `catch` -> do `handleError()`
229
+ * 5) `toPromise()` with `catch` -> don't `handleError()`
452
230
  */
453
- function findFullParentPath(obj, newObj = {}) {
454
- const visit = (child, keyToFind) => {
455
- for (const key in child) {
456
- if (child.hasOwnProperty(key) && child[key].indexOf(keyToFind) >= 0) {
457
- const parent = visit(child, key);
458
- return parent !== null ? `${parent}.${key}` : key;
231
+ function ngxsErrorHandler(internalErrorReporter, ngxsExecutionStrategy) {
232
+ return (source) => {
233
+ let subscribed = false;
234
+ source.subscribe({
235
+ error: error => {
236
+ // Do not trigger change detection for a microtask. This depends on the execution
237
+ // strategy being used, but the default `DispatchOutsideZoneNgxsExecutionStrategy`
238
+ // leaves the Angular zone.
239
+ ngxsExecutionStrategy.enter(() => Promise.resolve().then(() => {
240
+ if (!subscribed) {
241
+ ngxsExecutionStrategy.leave(() => internalErrorReporter.reportErrorSafely(error));
242
+ }
243
+ }));
459
244
  }
460
- }
461
- return null;
245
+ });
246
+ return new Observable(subscriber => {
247
+ subscribed = true;
248
+ return source.pipe(leaveNgxs(ngxsExecutionStrategy)).subscribe(subscriber);
249
+ });
462
250
  };
463
- for (const key in obj) {
464
- if (obj.hasOwnProperty(key)) {
465
- const parent = visit(obj, key);
466
- newObj[key] = parent ? `${parent}.${key}` : key;
251
+ }
252
+ class InternalErrorReporter {
253
+ constructor(_injector) {
254
+ this._injector = _injector;
255
+ /** Will be set lazily to be backward compatible. */
256
+ this._errorHandler = null;
257
+ }
258
+ reportErrorSafely(error) {
259
+ if (this._errorHandler === null) {
260
+ this._errorHandler = this._injector.get(ErrorHandler);
261
+ }
262
+ // The `try-catch` is used to avoid handling the error twice. Suppose we call
263
+ // `handleError` which re-throws the error internally. The re-thrown error will
264
+ // be caught by zone.js which will then get to the `zone.onError.emit()` and the
265
+ // `onError` subscriber will call `handleError` again.
266
+ try {
267
+ this._errorHandler.handleError(error);
467
268
  }
269
+ catch { }
468
270
  }
469
- return newObj;
470
271
  }
272
+ /** @nocollapse */ InternalErrorReporter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalErrorReporter, deps: [{ token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
273
+ /** @nocollapse */ InternalErrorReporter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalErrorReporter, providedIn: 'root' });
274
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalErrorReporter, decorators: [{
275
+ type: Injectable,
276
+ args: [{ providedIn: 'root' }]
277
+ }], ctorParameters: function () { return [{ type: i0.Injector }]; } });
278
+
471
279
  /**
472
- * Given a object graph, it will return the items topologically sorted Example:
473
- *
474
- * const graph = {
475
- * cart: ['saved'],
476
- * saved: ['items'],
477
- * items: []
478
- * };
479
- *
480
- * would return:
481
- *
482
- * const results = [
483
- * 'items',
484
- * 'saved',
485
- * 'cart'
486
- * ];
280
+ * This wraps the provided function, and will enforce the following:
281
+ * - The calls will execute in the order that they are made
282
+ * - A call will only be initiated when the previous call has completed
283
+ * - If there is a call currently executing then the new call will be added
284
+ * to the queue and the function will return immediately
487
285
  *
488
- * @ignore
286
+ * NOTE: The following assumptions about the operation must hold true:
287
+ * - The operation is synchronous in nature
288
+ * - If any asynchronous side effects of the call exist, it should not
289
+ * have any bearing on the correctness of the next call in the queue
290
+ * - The operation has a void return
291
+ * - The caller should not assume that the call has completed upon
292
+ * return of the function
293
+ * - The caller can assume that all the queued calls will complete
294
+ * within the current microtask
295
+ * - The only way that a call will encounter another call in the queue
296
+ * would be if the call at the front of the queue initiated this call
297
+ * as part of its synchronous execution
489
298
  */
490
- function topologicalSort(graph) {
491
- const sorted = [];
492
- const visited = {};
493
- const visit = (name, ancestors = []) => {
494
- if (!Array.isArray(ancestors)) {
495
- ancestors = [];
299
+ function orderedQueueOperation(operation) {
300
+ const callsQueue = [];
301
+ let busyPushingNext = false;
302
+ return function callOperation(...args) {
303
+ if (busyPushingNext) {
304
+ callsQueue.unshift(args);
305
+ return;
496
306
  }
497
- ancestors.push(name);
498
- visited[name] = true;
499
- graph[name].forEach((dep) => {
500
- // Caretaker note: we have still left the `typeof` condition in order to avoid
501
- // creating a breaking change for projects that still use the View Engine.
502
- if ((typeof ngDevMode === 'undefined' || ngDevMode) && ancestors.indexOf(dep) >= 0) {
503
- throw new Error(`Circular dependency '${dep}' is required by '${name}': ${ancestors.join(' -> ')}`);
504
- }
505
- if (visited[dep]) {
506
- return;
507
- }
508
- visit(dep, ancestors.slice(0));
509
- });
510
- if (sorted.indexOf(name) < 0) {
511
- sorted.push(name);
307
+ busyPushingNext = true;
308
+ operation(...args);
309
+ while (callsQueue.length > 0) {
310
+ const nextCallArgs = callsQueue.pop();
311
+ nextCallArgs && operation(...nextCallArgs);
512
312
  }
313
+ busyPushingNext = false;
513
314
  };
514
- Object.keys(graph).forEach(k => visit(k));
515
- return sorted.reverse();
516
315
  }
517
316
  /**
518
- * Returns if the parameter is a object or not.
519
- *
520
- * @ignore
317
+ * Custom Subject that ensures that subscribers are notified of values in the order that they arrived.
318
+ * A standard Subject does not have this guarantee.
319
+ * For example, given the following code:
320
+ * ```typescript
321
+ * const subject = new Subject<string>();
322
+ subject.subscribe(value => {
323
+ if (value === 'start') subject.next('end');
324
+ });
325
+ subject.subscribe(value => { });
326
+ subject.next('start');
327
+ * ```
328
+ * When `subject` is a standard `Subject<T>` the second subscriber would recieve `end` and then `start`.
329
+ * When `subject` is a `OrderedSubject<T>` the second subscriber would recieve `start` and then `end`.
521
330
  */
522
- function isObject(obj) {
523
- return (typeof obj === 'object' && obj !== null) || typeof obj === 'function';
524
- }
525
-
526
- /**
527
- * RxJS operator for selecting out specific actions.
528
- *
529
- * This will grab actions that have just been dispatched as well as actions that have completed
530
- */
531
- function ofAction(...allowedTypes) {
532
- return ofActionOperator(allowedTypes);
533
- }
534
- /**
535
- * RxJS operator for selecting out specific actions.
536
- *
537
- * This will ONLY grab actions that have just been dispatched
538
- */
539
- function ofActionDispatched(...allowedTypes) {
540
- return ofActionOperator(allowedTypes, ["DISPATCHED" /* Dispatched */]);
541
- }
542
- /**
543
- * RxJS operator for selecting out specific actions.
544
- *
545
- * This will ONLY grab actions that have just been successfully completed
546
- */
547
- function ofActionSuccessful(...allowedTypes) {
548
- return ofActionOperator(allowedTypes, ["SUCCESSFUL" /* Successful */]);
549
- }
550
- /**
551
- * RxJS operator for selecting out specific actions.
552
- *
553
- * This will ONLY grab actions that have just been canceled
554
- */
555
- function ofActionCanceled(...allowedTypes) {
556
- return ofActionOperator(allowedTypes, ["CANCELED" /* Canceled */]);
557
- }
558
- /**
559
- * RxJS operator for selecting out specific actions.
560
- *
561
- * This will ONLY grab actions that have just been completed
562
- */
563
- function ofActionCompleted(...allowedTypes) {
564
- const allowedStatuses = [
565
- "SUCCESSFUL" /* Successful */,
566
- "CANCELED" /* Canceled */,
567
- "ERRORED" /* Errored */
568
- ];
569
- return ofActionOperator(allowedTypes, allowedStatuses, mapActionResult);
570
- }
571
- /**
572
- * RxJS operator for selecting out specific actions.
573
- *
574
- * This will ONLY grab actions that have just thrown an error
575
- */
576
- function ofActionErrored(...allowedTypes) {
577
- return ofActionOperator(allowedTypes, ["ERRORED" /* Errored */]);
578
- }
579
- function ofActionOperator(allowedTypes, statuses,
580
- // This actually could've been `OperatorFunction<ActionContext, ActionCompletion | any>`,
581
- // since it maps either to `ctx.action` OR to `ActionCompletion`. But `ActionCompleteion | any`
582
- // defaults to `any`, thus there is no sense from union type.
583
- mapOperator = mapAction) {
584
- const allowedMap = createAllowedActionTypesMap(allowedTypes);
585
- const allowedStatusMap = statuses && createAllowedStatusesMap(statuses);
586
- return function (o) {
587
- return o.pipe(filterStatus(allowedMap, allowedStatusMap), mapOperator());
588
- };
589
- }
590
- function filterStatus(allowedTypes, allowedStatuses) {
591
- return filter((ctx) => {
592
- const actionType = getActionTypeFromInstance(ctx.action);
593
- const typeMatch = allowedTypes[actionType];
594
- const statusMatch = allowedStatuses ? allowedStatuses[ctx.status] : true;
595
- return typeMatch && statusMatch;
596
- });
597
- }
598
- function mapActionResult() {
599
- return map(({ action, status, error }) => {
600
- return {
601
- action,
602
- result: {
603
- successful: "SUCCESSFUL" /* Successful */ === status,
604
- canceled: "CANCELED" /* Canceled */ === status,
605
- error
606
- }
607
- };
608
- });
609
- }
610
- function mapAction() {
611
- return map((ctx) => ctx.action);
612
- }
613
- function createAllowedActionTypesMap(types) {
614
- return types.reduce((filterMap, klass) => {
615
- filterMap[getActionTypeFromInstance(klass)] = true;
616
- return filterMap;
617
- }, {});
618
- }
619
- function createAllowedStatusesMap(statuses) {
620
- return statuses.reduce((filterMap, status) => {
621
- filterMap[status] = true;
622
- return filterMap;
623
- }, {});
624
- }
625
-
626
- /**
627
- * Returns operator that will run
628
- * `subscribe` outside of the ngxs execution context
629
- */
630
- function leaveNgxs(ngxsExecutionStrategy) {
631
- return (source) => {
632
- return new Observable((sink) => {
633
- return source.subscribe({
634
- next(value) {
635
- ngxsExecutionStrategy.leave(() => sink.next(value));
636
- },
637
- error(error) {
638
- ngxsExecutionStrategy.leave(() => sink.error(error));
639
- },
640
- complete() {
641
- ngxsExecutionStrategy.leave(() => sink.complete());
642
- }
643
- });
644
- });
645
- };
646
- }
647
-
648
- class InternalNgxsExecutionStrategy {
649
- constructor(_executionStrategy) {
650
- this._executionStrategy = _executionStrategy;
651
- }
652
- enter(func) {
653
- return this._executionStrategy.enter(func);
654
- }
655
- leave(func) {
656
- return this._executionStrategy.leave(func);
657
- }
658
- }
659
- /** @nocollapse */ InternalNgxsExecutionStrategy.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalNgxsExecutionStrategy, deps: [{ token: NGXS_EXECUTION_STRATEGY }], target: i0.ɵɵFactoryTarget.Injectable });
660
- /** @nocollapse */ InternalNgxsExecutionStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalNgxsExecutionStrategy, providedIn: 'root' });
661
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalNgxsExecutionStrategy, decorators: [{
662
- type: Injectable,
663
- args: [{ providedIn: 'root' }]
664
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
665
- type: Inject,
666
- args: [NGXS_EXECUTION_STRATEGY]
667
- }] }]; } });
668
-
669
- /**
670
- * This wraps the provided function, and will enforce the following:
671
- * - The calls will execute in the order that they are made
672
- * - A call will only be initiated when the previous call has completed
673
- * - If there is a call currently executing then the new call will be added
674
- * to the queue and the function will return immediately
675
- *
676
- * NOTE: The following assumptions about the operation must hold true:
677
- * - The operation is synchronous in nature
678
- * - If any asynchronous side effects of the call exist, it should not
679
- * have any bearing on the correctness of the next call in the queue
680
- * - The operation has a void return
681
- * - The caller should not assume that the call has completed upon
682
- * return of the function
683
- * - The caller can assume that all the queued calls will complete
684
- * within the current microtask
685
- * - The only way that a call will encounter another call in the queue
686
- * would be if the call at the front of the queue initiated this call
687
- * as part of its synchronous execution
688
- */
689
- function orderedQueueOperation(operation) {
690
- const callsQueue = [];
691
- let busyPushingNext = false;
692
- return function callOperation(...args) {
693
- if (busyPushingNext) {
694
- callsQueue.unshift(args);
695
- return;
696
- }
697
- busyPushingNext = true;
698
- operation(...args);
699
- while (callsQueue.length > 0) {
700
- const nextCallArgs = callsQueue.pop();
701
- nextCallArgs && operation(...nextCallArgs);
702
- }
703
- busyPushingNext = false;
704
- };
705
- }
706
- /**
707
- * Custom Subject that ensures that subscribers are notified of values in the order that they arrived.
708
- * A standard Subject does not have this guarantee.
709
- * For example, given the following code:
710
- * ```typescript
711
- * const subject = new Subject<string>();
712
- subject.subscribe(value => {
713
- if (value === 'start') subject.next('end');
714
- });
715
- subject.subscribe(value => { });
716
- subject.next('start');
717
- * ```
718
- * When `subject` is a standard `Subject<T>` the second subscriber would recieve `end` and then `start`.
719
- * When `subject` is a `OrderedSubject<T>` the second subscriber would recieve `start` and then `end`.
720
- */
721
- class OrderedSubject extends Subject {
722
- constructor() {
723
- super(...arguments);
724
- this._orderedNext = orderedQueueOperation((value) => super.next(value));
725
- }
726
- next(value) {
727
- this._orderedNext(value);
728
- }
331
+ class OrderedSubject extends Subject {
332
+ constructor() {
333
+ super(...arguments);
334
+ this._orderedNext = orderedQueueOperation((value) => super.next(value));
335
+ }
336
+ next(value) {
337
+ this._orderedNext(value);
338
+ }
729
339
  }
730
340
  /**
731
341
  * Custom BehaviorSubject that ensures that subscribers are notified of values in the order that they arrived.
@@ -765,9 +375,9 @@ class InternalActions extends OrderedSubject {
765
375
  this.complete();
766
376
  }
767
377
  }
768
- /** @nocollapse */ InternalActions.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalActions, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
769
- /** @nocollapse */ InternalActions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalActions, providedIn: 'root' });
770
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalActions, decorators: [{
378
+ /** @nocollapse */ InternalActions.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalActions, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
379
+ /** @nocollapse */ InternalActions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalActions, providedIn: 'root' });
380
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalActions, decorators: [{
771
381
  type: Injectable,
772
382
  args: [{ providedIn: 'root' }]
773
383
  }] });
@@ -794,120 +404,189 @@ class Actions extends Observable {
794
404
  });
795
405
  }
796
406
  }
797
- /** @nocollapse */ Actions.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Actions, deps: [{ token: InternalActions }, { token: InternalNgxsExecutionStrategy }], target: i0.ɵɵFactoryTarget.Injectable });
798
- /** @nocollapse */ Actions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Actions, providedIn: 'root' });
799
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Actions, decorators: [{
407
+ /** @nocollapse */ Actions.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: Actions, deps: [{ token: InternalActions }, { token: InternalNgxsExecutionStrategy }], target: i0.ɵɵFactoryTarget.Injectable });
408
+ /** @nocollapse */ Actions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: Actions, providedIn: 'root' });
409
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: Actions, decorators: [{
800
410
  type: Injectable,
801
411
  args: [{ providedIn: 'root' }]
802
412
  }], ctorParameters: function () { return [{ type: InternalActions }, { type: InternalNgxsExecutionStrategy }]; } });
803
413
 
804
414
  /**
805
- * Composes a array of functions from left to right. Example:
806
- *
807
- * compose([fn, final])(state, action);
808
- *
809
- * then the funcs have a signature like:
810
- *
811
- * function fn (state, action, next) {
812
- * console.log('here', state, action, next);
813
- * return next(state, action);
814
- * }
815
- *
816
- * function final (state, action) {
817
- * console.log('here', state, action);
818
- * return state;
819
- * }
820
- *
821
- * the last function should not call `next`.
822
- *
415
+ * BehaviorSubject of the entire state.
823
416
  * @ignore
824
417
  */
825
- const compose = (funcs) => (...args) => {
826
- const curr = funcs.shift();
827
- return curr(...args, (...nextArgs) => compose(funcs)(...nextArgs));
828
- };
418
+ class StateStream extends OrderedBehaviorSubject {
419
+ constructor() {
420
+ super({});
421
+ }
422
+ ngOnDestroy() {
423
+ // The StateStream should never emit values once the root view is removed,
424
+ // such as when the `NgModuleRef.destroy()` method is called. This is crucial
425
+ // for preventing memory leaks in server-side rendered apps, where a new StateStream
426
+ // is created for each HTTP request. If users forget to unsubscribe from `store.select`
427
+ // or `store.subscribe`, it can result in significant memory leaks in SSR apps.
428
+ this.complete();
429
+ }
430
+ }
431
+ /** @nocollapse */ StateStream.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateStream, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
432
+ /** @nocollapse */ StateStream.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateStream, providedIn: 'root' });
433
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateStream, decorators: [{
434
+ type: Injectable,
435
+ args: [{ providedIn: 'root' }]
436
+ }], ctorParameters: function () { return []; } });
829
437
 
830
438
  /**
831
- * This operator is used for piping the observable result
832
- * from the `dispatch()`. It has a "smart" error handling
833
- * strategy that allows us to decide whether we propagate
834
- * errors to Angular's `ErrorHandler` or enable users to
835
- * handle them manually. We consider following cases:
836
- * 1) `store.dispatch()` (no subscribe) -> call `handleError()`
837
- * 2) `store.dispatch().subscribe()` (no error callback) -> call `handleError()`
838
- * 3) `store.dispatch().subscribe({ error: ... })` -> don't call `handleError()`
839
- * 4) `toPromise()` without `catch` -> do `handleError()`
840
- * 5) `toPromise()` with `catch` -> don't `handleError()`
439
+ * Returns the type from an action instance/class.
440
+ * @ignore
841
441
  */
842
- function ngxsErrorHandler(internalErrorReporter, ngxsExecutionStrategy) {
843
- return (source) => {
844
- let subscribed = false;
845
- source.subscribe({
846
- error: error => {
847
- // Do not trigger change detection for a microtask. This depends on the execution
848
- // strategy being used, but the default `DispatchOutsideZoneNgxsExecutionStrategy`
849
- // leaves the Angular zone.
850
- ngxsExecutionStrategy.enter(() => Promise.resolve().then(() => {
851
- if (!subscribed) {
852
- ngxsExecutionStrategy.leave(() => internalErrorReporter.reportErrorSafely(error));
853
- }
854
- }));
855
- }
856
- });
857
- return new Observable(subscriber => {
858
- subscribed = true;
859
- return source.pipe(leaveNgxs(ngxsExecutionStrategy)).subscribe(subscriber);
860
- });
861
- };
862
- }
863
- class InternalErrorReporter {
864
- constructor(_injector) {
865
- this._injector = _injector;
866
- /** Will be set lazily to be backward compatible. */
867
- this._errorHandler = null;
442
+ function getActionTypeFromInstance(action) {
443
+ if (action.constructor && action.constructor.type) {
444
+ return action.constructor.type;
868
445
  }
869
- reportErrorSafely(error) {
870
- if (this._errorHandler === null) {
871
- this._errorHandler = this._injector.get(ErrorHandler);
446
+ else {
447
+ return action.type;
448
+ }
449
+ }
450
+ /**
451
+ * Matches a action
452
+ * @ignore
453
+ */
454
+ function actionMatcher(action1) {
455
+ const type1 = getActionTypeFromInstance(action1);
456
+ return function (action2) {
457
+ return type1 === getActionTypeFromInstance(action2);
458
+ };
459
+ }
460
+ /**
461
+ * Set a deeply nested value. Example:
462
+ *
463
+ * setValue({ foo: { bar: { eat: false } } },
464
+ * 'foo.bar.eat', true) //=> { foo: { bar: { eat: true } } }
465
+ *
466
+ * While it traverses it also creates new objects from top down.
467
+ *
468
+ * @ignore
469
+ */
470
+ const setValue = (obj, prop, val) => {
471
+ obj = { ...obj };
472
+ const split = prop.split('.');
473
+ const lastIndex = split.length - 1;
474
+ split.reduce((acc, part, index) => {
475
+ if (index === lastIndex) {
476
+ acc[part] = val;
872
477
  }
873
- // The `try-catch` is used to avoid handling the error twice. Suppose we call
874
- // `handleError` which re-throws the error internally. The re-thrown error will
875
- // be caught by zone.js which will then get to the `zone.onError.emit()` and the
876
- // `onError` subscriber will call `handleError` again.
877
- try {
878
- this._errorHandler.handleError(error);
478
+ else {
479
+ acc[part] = Array.isArray(acc[part]) ? acc[part].slice() : { ...acc[part] };
480
+ }
481
+ return acc && acc[part];
482
+ }, obj);
483
+ return obj;
484
+ };
485
+ /**
486
+ * Get a deeply nested value. Example:
487
+ *
488
+ * getValue({ foo: bar: [] }, 'foo.bar') //=> []
489
+ *
490
+ * @ignore
491
+ */
492
+ const getValue = (obj, prop) => prop.split('.').reduce((acc, part) => acc && acc[part], obj);
493
+ /**
494
+ * Simple object check.
495
+ *
496
+ * isObject({a:1}) //=> true
497
+ * isObject(1) //=> false
498
+ *
499
+ * @ignore
500
+ */
501
+ const isObject$1 = (item) => {
502
+ return item && typeof item === 'object' && !Array.isArray(item);
503
+ };
504
+ /**
505
+ * Deep merge two objects.
506
+ *
507
+ * mergeDeep({a:1, b:{x: 1, y:2}}, {b:{x: 3}, c:4}) //=> {a:1, b:{x:3, y:2}, c:4}
508
+ *
509
+ * @param base base object onto which `sources` will be applied
510
+ */
511
+ const mergeDeep = (base, ...sources) => {
512
+ if (!sources.length)
513
+ return base;
514
+ const source = sources.shift();
515
+ if (isObject$1(base) && isObject$1(source)) {
516
+ for (const key in source) {
517
+ if (isObject$1(source[key])) {
518
+ if (!base[key])
519
+ Object.assign(base, { [key]: {} });
520
+ mergeDeep(base[key], source[key]);
521
+ }
522
+ else {
523
+ Object.assign(base, { [key]: source[key] });
524
+ }
879
525
  }
880
- catch (_a) { }
881
526
  }
882
- }
883
- /** @nocollapse */ InternalErrorReporter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalErrorReporter, deps: [{ token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
884
- /** @nocollapse */ InternalErrorReporter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalErrorReporter, providedIn: 'root' });
885
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalErrorReporter, decorators: [{
886
- type: Injectable,
887
- args: [{ providedIn: 'root' }]
888
- }], ctorParameters: function () { return [{ type: i0.Injector }]; } });
527
+ return mergeDeep(base, ...sources);
528
+ };
889
529
 
530
+ const NG_DEV_MODE$3 = typeof ngDevMode === 'undefined' || ngDevMode;
531
+ // The injection token is used to resolve a list of states provided at
532
+ // the root level through either `NgxsModule.forRoot` or `provideStore`.
533
+ const ROOT_STATE_TOKEN = new InjectionToken(NG_DEV_MODE$3 ? 'ROOT_STATE_TOKEN' : '');
534
+ // The injection token is used to resolve a list of states provided at
535
+ // the feature level through either `NgxsModule.forFeature` or `provideStates`.
536
+ // The Array<Array> is used to overload the resolved value of the token because
537
+ // it is a multi-provider token.
538
+ const FEATURE_STATE_TOKEN = new InjectionToken(NG_DEV_MODE$3 ? 'FEATURE_STATE_TOKEN' : '');
539
+ // The injection token is used to resolve to custom NGXS plugins provided
540
+ // at the root level through either `{provide}` scheme or `withNgxsPlugin`.
541
+ const NGXS_PLUGINS = new InjectionToken(NG_DEV_MODE$3 ? 'NGXS_PLUGINS' : '');
542
+ // The injection token is used to resolve to options provided at the root
543
+ // level through either `NgxsModule.forRoot` or `provideStore`.
544
+ const NGXS_OPTIONS = new InjectionToken(NG_DEV_MODE$3 ? 'NGXS_OPTIONS' : '');
890
545
  /**
891
- * BehaviorSubject of the entire state.
892
- * @ignore
546
+ * The NGXS config settings.
893
547
  */
894
- class StateStream extends OrderedBehaviorSubject {
548
+ class NgxsConfig {
895
549
  constructor() {
896
- super({});
897
- }
898
- ngOnDestroy() {
899
- // The `StateStream` should never emit values once the root view is removed, e.g. when the `NgModuleRef.destroy()` is called.
900
- // This will eliminate memory leaks in server-side rendered apps where the `StateStream` is created per each HTTP request, users
901
- // might forget to unsubscribe from `store.select` or `store.subscribe`, thus this will lead to huge memory leaks in SSR apps.
902
- this.complete();
550
+ /**
551
+ * Defining the default state before module initialization
552
+ * This is convenient if we need to create a define our own set of states.
553
+ * @deprecated will be removed after v4
554
+ * (default: {})
555
+ */
556
+ this.defaultsState = {};
557
+ /**
558
+ * Defining shared selector options
559
+ */
560
+ this.selectorOptions = {
561
+ injectContainerState: true,
562
+ suppressErrors: true // TODO: default is true in v3, will change in v4
563
+ };
564
+ this.compatibility = {
565
+ strictContentSecurityPolicy: false
566
+ };
567
+ this.executionStrategy = DispatchOutsideZoneNgxsExecutionStrategy;
903
568
  }
904
569
  }
905
- /** @nocollapse */ StateStream.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateStream, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
906
- /** @nocollapse */ StateStream.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateStream, providedIn: 'root' });
907
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateStream, decorators: [{
570
+ /** @nocollapse */ NgxsConfig.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsConfig, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
571
+ /** @nocollapse */ NgxsConfig.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsConfig, providedIn: 'root', useFactory: () => mergeDeep(new NgxsConfig(), inject(NGXS_OPTIONS)) });
572
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsConfig, decorators: [{
908
573
  type: Injectable,
909
- args: [{ providedIn: 'root' }]
574
+ args: [{
575
+ providedIn: 'root',
576
+ useFactory: () => mergeDeep(new NgxsConfig(), inject(NGXS_OPTIONS))
577
+ }]
910
578
  }], ctorParameters: function () { return []; } });
579
+ /**
580
+ * Represents a basic change from a previous to a new value for a single state instance.
581
+ * Passed as a value in a NgxsSimpleChanges object to the ngxsOnChanges hook.
582
+ */
583
+ class NgxsSimpleChange {
584
+ constructor(previousValue, currentValue, firstChange) {
585
+ this.previousValue = previousValue;
586
+ this.currentValue = currentValue;
587
+ this.firstChange = firstChange;
588
+ }
589
+ }
911
590
 
912
591
  class PluginManager {
913
592
  constructor(_parentManager, _pluginHandlers) {
@@ -928,9 +607,9 @@ class PluginManager {
928
607
  return handlers.map((plugin) => (plugin.handle ? plugin.handle.bind(plugin) : plugin));
929
608
  }
930
609
  }
931
- /** @nocollapse */ PluginManager.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PluginManager, deps: [{ token: PluginManager, optional: true, skipSelf: true }, { token: NGXS_PLUGINS, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
932
- /** @nocollapse */ PluginManager.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PluginManager });
933
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PluginManager, decorators: [{
610
+ /** @nocollapse */ PluginManager.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: PluginManager, deps: [{ token: PluginManager, optional: true, skipSelf: true }, { token: NGXS_PLUGINS, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
611
+ /** @nocollapse */ PluginManager.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: PluginManager });
612
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: PluginManager, decorators: [{
934
613
  type: Injectable
935
614
  }], ctorParameters: function () { return [{ type: PluginManager, decorators: [{
936
615
  type: Optional
@@ -951,9 +630,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
951
630
  */
952
631
  class InternalDispatchedActionResults extends Subject {
953
632
  }
954
- /** @nocollapse */ InternalDispatchedActionResults.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatchedActionResults, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
955
- /** @nocollapse */ InternalDispatchedActionResults.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatchedActionResults, providedIn: 'root' });
956
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatchedActionResults, decorators: [{
633
+ /** @nocollapse */ InternalDispatchedActionResults.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalDispatchedActionResults, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
634
+ /** @nocollapse */ InternalDispatchedActionResults.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalDispatchedActionResults, providedIn: 'root' });
635
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalDispatchedActionResults, decorators: [{
957
636
  type: Injectable,
958
637
  args: [{ providedIn: 'root' }]
959
638
  }] });
@@ -1001,21 +680,21 @@ class InternalDispatcher {
1001
680
  }
1002
681
  const actionResult$ = this.getActionResultStream(nextAction);
1003
682
  actionResult$.subscribe(ctx => this._actions.next(ctx));
1004
- this._actions.next({ action: nextAction, status: "DISPATCHED" /* Dispatched */ });
683
+ this._actions.next({ action: nextAction, status: "DISPATCHED" /* ActionStatus.Dispatched */ });
1005
684
  return this.createDispatchObservable(actionResult$);
1006
685
  }
1007
686
  ])(prevState, action).pipe(shareReplay());
1008
687
  }
1009
688
  getActionResultStream(action) {
1010
- return this._actionResults.pipe(filter((ctx) => ctx.action === action && ctx.status !== "DISPATCHED" /* Dispatched */), take(1), shareReplay());
689
+ return this._actionResults.pipe(filter((ctx) => ctx.action === action && ctx.status !== "DISPATCHED" /* ActionStatus.Dispatched */), take(1), shareReplay());
1011
690
  }
1012
691
  createDispatchObservable(actionResult$) {
1013
692
  return actionResult$
1014
693
  .pipe(exhaustMap((ctx) => {
1015
694
  switch (ctx.status) {
1016
- case "SUCCESSFUL" /* Successful */:
695
+ case "SUCCESSFUL" /* ActionStatus.Successful */:
1017
696
  return of(this._stateStream.getValue());
1018
- case "ERRORED" /* Errored */:
697
+ case "ERRORED" /* ActionStatus.Errored */:
1019
698
  return throwError(ctx.error);
1020
699
  default:
1021
700
  return EMPTY;
@@ -1024,9 +703,9 @@ class InternalDispatcher {
1024
703
  .pipe(shareReplay());
1025
704
  }
1026
705
  }
1027
- /** @nocollapse */ InternalDispatcher.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatcher, deps: [{ token: InternalActions }, { token: InternalDispatchedActionResults }, { token: PluginManager }, { token: StateStream }, { token: InternalNgxsExecutionStrategy }, { token: InternalErrorReporter }], target: i0.ɵɵFactoryTarget.Injectable });
1028
- /** @nocollapse */ InternalDispatcher.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatcher, providedIn: 'root' });
1029
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatcher, decorators: [{
706
+ /** @nocollapse */ InternalDispatcher.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalDispatcher, deps: [{ token: InternalActions }, { token: InternalDispatchedActionResults }, { token: PluginManager }, { token: StateStream }, { token: InternalNgxsExecutionStrategy }, { token: InternalErrorReporter }], target: i0.ɵɵFactoryTarget.Injectable });
707
+ /** @nocollapse */ InternalDispatcher.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalDispatcher, providedIn: 'root' });
708
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalDispatcher, decorators: [{
1030
709
  type: Injectable,
1031
710
  args: [{ providedIn: 'root' }]
1032
711
  }], ctorParameters: function () { return [{ type: InternalActions }, { type: InternalDispatchedActionResults }, { type: PluginManager }, { type: StateStream }, { type: InternalNgxsExecutionStrategy }, { type: InternalErrorReporter }]; } });
@@ -1083,27 +762,446 @@ class InternalStateOperations {
1083
762
  // Get our current stream
1084
763
  const currentState = stateOperations.getState();
1085
764
  // Set the state to the current + new
1086
- stateOperations.setState(Object.assign(Object.assign({}, currentState), results.defaults));
765
+ stateOperations.setState({ ...currentState, ...results.defaults });
766
+ }
767
+ }
768
+ /** @nocollapse */ InternalStateOperations.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalStateOperations, deps: [{ token: StateStream }, { token: InternalDispatcher }, { token: NgxsConfig }], target: i0.ɵɵFactoryTarget.Injectable });
769
+ /** @nocollapse */ InternalStateOperations.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalStateOperations, providedIn: 'root' });
770
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalStateOperations, decorators: [{
771
+ type: Injectable,
772
+ args: [{ providedIn: 'root' }]
773
+ }], ctorParameters: function () { return [{ type: StateStream }, { type: InternalDispatcher }, { type: NgxsConfig }]; } });
774
+ function ensureStateAndActionsAreImmutable(root) {
775
+ return {
776
+ getState: () => root.getState(),
777
+ setState: value => {
778
+ const frozenValue = deepFreeze(value);
779
+ return root.setState(frozenValue);
780
+ },
781
+ dispatch: actions => {
782
+ return root.dispatch(actions);
783
+ }
784
+ };
785
+ }
786
+
787
+ /**
788
+ * Ensures metadata is attached to the class and returns it.
789
+ *
790
+ * @ignore
791
+ */
792
+ function ensureStoreMetadata$1(target) {
793
+ if (!target.hasOwnProperty(ɵMETA_KEY)) {
794
+ const defaultMetadata = {
795
+ name: null,
796
+ actions: {},
797
+ defaults: {},
798
+ path: null,
799
+ makeRootSelector(context) {
800
+ return context.getStateGetter(defaultMetadata.name);
801
+ },
802
+ children: []
803
+ };
804
+ Object.defineProperty(target, ɵMETA_KEY, { value: defaultMetadata });
805
+ }
806
+ return getStoreMetadata$1(target);
807
+ }
808
+ /**
809
+ * Get the metadata attached to the state class if it exists.
810
+ *
811
+ * @ignore
812
+ */
813
+ function getStoreMetadata$1(target) {
814
+ return target[ɵMETA_KEY];
815
+ }
816
+ /**
817
+ * Ensures metadata is attached to the selector and returns it.
818
+ *
819
+ * @ignore
820
+ */
821
+ function ensureSelectorMetadata$1(target) {
822
+ if (!target.hasOwnProperty(ɵSELECTOR_META_KEY)) {
823
+ const defaultMetadata = {
824
+ makeRootSelector: null,
825
+ originalFn: null,
826
+ containerClass: null,
827
+ selectorName: null,
828
+ getSelectorOptions: () => ({})
829
+ };
830
+ Object.defineProperty(target, ɵSELECTOR_META_KEY, { value: defaultMetadata });
831
+ }
832
+ return getSelectorMetadata$1(target);
833
+ }
834
+ /**
835
+ * Get the metadata attached to the selector if it exists.
836
+ *
837
+ * @ignore
838
+ */
839
+ function getSelectorMetadata$1(target) {
840
+ return target[ɵSELECTOR_META_KEY];
841
+ }
842
+ /**
843
+ * Get a deeply nested value. Example:
844
+ *
845
+ * getValue({ foo: bar: [] }, 'foo.bar') //=> []
846
+ *
847
+ * Note: This is not as fast as the `fastPropGetter` but is strict Content Security Policy compliant.
848
+ * See perf hit: https://jsperf.com/fast-value-getter-given-path/1
849
+ *
850
+ * @ignore
851
+ */
852
+ function compliantPropGetter(paths) {
853
+ const copyOfPaths = paths.slice();
854
+ return obj => copyOfPaths.reduce((acc, part) => acc && acc[part], obj);
855
+ }
856
+ /**
857
+ * The generated function is faster than:
858
+ * - pluck (Observable operator)
859
+ * - memoize
860
+ *
861
+ * @ignore
862
+ */
863
+ function fastPropGetter(paths) {
864
+ const segments = paths;
865
+ let seg = 'store.' + segments[0];
866
+ let i = 0;
867
+ const l = segments.length;
868
+ let expr = seg;
869
+ while (++i < l) {
870
+ expr = expr + ' && ' + (seg = seg + '.' + segments[i]);
871
+ }
872
+ const fn = new Function('store', 'return ' + expr + ';');
873
+ return fn;
874
+ }
875
+ /**
876
+ * Get a deeply nested value. Example:
877
+ *
878
+ * getValue({ foo: bar: [] }, 'foo.bar') //=> []
879
+ *
880
+ * @ignore
881
+ */
882
+ function propGetter(paths, config) {
883
+ if (config && config.compatibility && config.compatibility.strictContentSecurityPolicy) {
884
+ return compliantPropGetter(paths);
885
+ }
886
+ else {
887
+ return fastPropGetter(paths);
888
+ }
889
+ }
890
+ /**
891
+ * Given an array of states, it will return a object graph. Example:
892
+ * const states = [
893
+ * Cart,
894
+ * CartSaved,
895
+ * CartSavedItems
896
+ * ]
897
+ *
898
+ * would return:
899
+ *
900
+ * const graph = {
901
+ * cart: ['saved'],
902
+ * saved: ['items'],
903
+ * items: []
904
+ * };
905
+ *
906
+ * @ignore
907
+ */
908
+ function buildGraph(stateClasses) {
909
+ const findName = (stateClass) => {
910
+ const meta = stateClasses.find(g => g === stateClass);
911
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
912
+ // creating a breaking change for projects that still use the View Engine.
913
+ if ((typeof ngDevMode === 'undefined' || ngDevMode) && !meta) {
914
+ throw new Error(`Child state not found: ${stateClass}. \r\nYou may have forgotten to add states to module`);
915
+ }
916
+ return meta[ɵMETA_KEY].name;
917
+ };
918
+ return stateClasses.reduce((result, stateClass) => {
919
+ const { name, children } = stateClass[ɵMETA_KEY];
920
+ result[name] = (children || []).map(findName);
921
+ return result;
922
+ }, {});
923
+ }
924
+ /**
925
+ * Given a states array, returns object graph
926
+ * returning the name and state metadata. Example:
927
+ *
928
+ * const graph = {
929
+ * cart: { metadata }
930
+ * };
931
+ *
932
+ * @ignore
933
+ */
934
+ function nameToState(states) {
935
+ return states.reduce((result, stateClass) => {
936
+ const meta = stateClass[ɵMETA_KEY];
937
+ result[meta.name] = stateClass;
938
+ return result;
939
+ }, {});
940
+ }
941
+ /**
942
+ * Given a object relationship graph will return the full path
943
+ * for the child items. Example:
944
+ *
945
+ * const graph = {
946
+ * cart: ['saved'],
947
+ * saved: ['items'],
948
+ * items: []
949
+ * };
950
+ *
951
+ * would return:
952
+ *
953
+ * const r = {
954
+ * cart: 'cart',
955
+ * saved: 'cart.saved',
956
+ * items: 'cart.saved.items'
957
+ * };
958
+ *
959
+ * @ignore
960
+ */
961
+ function findFullParentPath(obj, newObj = {}) {
962
+ const visit = (child, keyToFind) => {
963
+ for (const key in child) {
964
+ if (child.hasOwnProperty(key) && child[key].indexOf(keyToFind) >= 0) {
965
+ const parent = visit(child, key);
966
+ return parent !== null ? `${parent}.${key}` : key;
967
+ }
968
+ }
969
+ return null;
970
+ };
971
+ for (const key in obj) {
972
+ if (obj.hasOwnProperty(key)) {
973
+ const parent = visit(obj, key);
974
+ newObj[key] = parent ? `${parent}.${key}` : key;
975
+ }
1087
976
  }
977
+ return newObj;
978
+ }
979
+ /**
980
+ * Given a object graph, it will return the items topologically sorted Example:
981
+ *
982
+ * const graph = {
983
+ * cart: ['saved'],
984
+ * saved: ['items'],
985
+ * items: []
986
+ * };
987
+ *
988
+ * would return:
989
+ *
990
+ * const results = [
991
+ * 'items',
992
+ * 'saved',
993
+ * 'cart'
994
+ * ];
995
+ *
996
+ * @ignore
997
+ */
998
+ function topologicalSort(graph) {
999
+ const sorted = [];
1000
+ const visited = {};
1001
+ const visit = (name, ancestors = []) => {
1002
+ if (!Array.isArray(ancestors)) {
1003
+ ancestors = [];
1004
+ }
1005
+ ancestors.push(name);
1006
+ visited[name] = true;
1007
+ graph[name].forEach((dep) => {
1008
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
1009
+ // creating a breaking change for projects that still use the View Engine.
1010
+ if ((typeof ngDevMode === 'undefined' || ngDevMode) && ancestors.indexOf(dep) >= 0) {
1011
+ throw new Error(`Circular dependency '${dep}' is required by '${name}': ${ancestors.join(' -> ')}`);
1012
+ }
1013
+ if (visited[dep]) {
1014
+ return;
1015
+ }
1016
+ visit(dep, ancestors.slice(0));
1017
+ });
1018
+ if (sorted.indexOf(name) < 0) {
1019
+ sorted.push(name);
1020
+ }
1021
+ };
1022
+ Object.keys(graph).forEach(k => visit(k));
1023
+ return sorted.reverse();
1024
+ }
1025
+ /**
1026
+ * Returns if the parameter is a object or not.
1027
+ *
1028
+ * @ignore
1029
+ */
1030
+ function isObject(obj) {
1031
+ return (typeof obj === 'object' && obj !== null) || typeof obj === 'function';
1032
+ }
1033
+
1034
+ function createRootSelectorFactory(selectorMetaData, selectors, memoizedSelectorFn) {
1035
+ return (context) => {
1036
+ const { argumentSelectorFunctions, selectorOptions } = getRuntimeSelectorInfo(context, selectorMetaData, selectors);
1037
+ return function selectFromRoot(rootState) {
1038
+ // Determine arguments from the app state using the selectors
1039
+ const results = argumentSelectorFunctions.map((argFn) => argFn(rootState));
1040
+ // if the lambda tries to access a something on the
1041
+ // state that doesn't exist, it will throw a TypeError.
1042
+ // since this is quite usual behaviour, we simply return undefined if so.
1043
+ try {
1044
+ return memoizedSelectorFn(...results);
1045
+ }
1046
+ catch (ex) {
1047
+ if (ex instanceof TypeError && selectorOptions.suppressErrors) {
1048
+ return undefined;
1049
+ }
1050
+ throw ex;
1051
+ }
1052
+ };
1053
+ };
1054
+ }
1055
+ function createMemoizedSelectorFn(originalFn, creationMetadata) {
1056
+ const containerClass = creationMetadata && creationMetadata.containerClass;
1057
+ const wrappedFn = function wrappedSelectorFn(...args) {
1058
+ const returnValue = originalFn.apply(containerClass, args);
1059
+ if (returnValue instanceof Function) {
1060
+ const innerMemoizedFn = memoize.apply(null, [returnValue]);
1061
+ return innerMemoizedFn;
1062
+ }
1063
+ return returnValue;
1064
+ };
1065
+ const memoizedFn = memoize(wrappedFn);
1066
+ Object.setPrototypeOf(memoizedFn, originalFn);
1067
+ return memoizedFn;
1068
+ }
1069
+ function getRuntimeSelectorInfo(context, selectorMetaData, selectors = []) {
1070
+ const localSelectorOptions = selectorMetaData.getSelectorOptions();
1071
+ const selectorOptions = context.getSelectorOptions(localSelectorOptions);
1072
+ const selectorsToApply = getSelectorsToApply(selectors, selectorOptions, selectorMetaData.containerClass);
1073
+ const argumentSelectorFunctions = selectorsToApply.map((selector) => {
1074
+ const factory = getRootSelectorFactory(selector);
1075
+ return factory(context);
1076
+ });
1077
+ return {
1078
+ selectorOptions,
1079
+ argumentSelectorFunctions,
1080
+ };
1081
+ }
1082
+ function getSelectorsToApply(selectors = [], selectorOptions, containerClass) {
1083
+ const selectorsToApply = [];
1084
+ const canInjectContainerState = selectors.length === 0 || selectorOptions.injectContainerState;
1085
+ if (containerClass && canInjectContainerState) {
1086
+ // If we are on a state class, add it as the first selector parameter
1087
+ const metadata = getStoreMetadata$1(containerClass);
1088
+ if (metadata) {
1089
+ selectorsToApply.push(containerClass);
1090
+ }
1091
+ }
1092
+ if (selectors) {
1093
+ selectorsToApply.push(...selectors);
1094
+ }
1095
+ return selectorsToApply;
1096
+ }
1097
+ /**
1098
+ * This function gets the factory function to create the selector to get the selected slice from the app state
1099
+ * @ignore
1100
+ */
1101
+ function getRootSelectorFactory(selector) {
1102
+ const metadata = getSelectorMetadata$1(selector) || getStoreMetadata$1(selector);
1103
+ return (metadata && metadata.makeRootSelector) || (() => selector);
1104
+ }
1105
+
1106
+ /**
1107
+ * RxJS operator for selecting out specific actions.
1108
+ *
1109
+ * This will grab actions that have just been dispatched as well as actions that have completed
1110
+ */
1111
+ function ofAction(...allowedTypes) {
1112
+ return ofActionOperator(allowedTypes);
1113
+ }
1114
+ /**
1115
+ * RxJS operator for selecting out specific actions.
1116
+ *
1117
+ * This will ONLY grab actions that have just been dispatched
1118
+ */
1119
+ function ofActionDispatched(...allowedTypes) {
1120
+ return ofActionOperator(allowedTypes, ["DISPATCHED" /* ActionStatus.Dispatched */]);
1121
+ }
1122
+ /**
1123
+ * RxJS operator for selecting out specific actions.
1124
+ *
1125
+ * This will ONLY grab actions that have just been successfully completed
1126
+ */
1127
+ function ofActionSuccessful(...allowedTypes) {
1128
+ return ofActionOperator(allowedTypes, ["SUCCESSFUL" /* ActionStatus.Successful */]);
1129
+ }
1130
+ /**
1131
+ * RxJS operator for selecting out specific actions.
1132
+ *
1133
+ * This will ONLY grab actions that have just been canceled
1134
+ */
1135
+ function ofActionCanceled(...allowedTypes) {
1136
+ return ofActionOperator(allowedTypes, ["CANCELED" /* ActionStatus.Canceled */]);
1137
+ }
1138
+ /**
1139
+ * RxJS operator for selecting out specific actions.
1140
+ *
1141
+ * This will ONLY grab actions that have just been completed
1142
+ */
1143
+ function ofActionCompleted(...allowedTypes) {
1144
+ const allowedStatuses = [
1145
+ "SUCCESSFUL" /* ActionStatus.Successful */,
1146
+ "CANCELED" /* ActionStatus.Canceled */,
1147
+ "ERRORED" /* ActionStatus.Errored */
1148
+ ];
1149
+ return ofActionOperator(allowedTypes, allowedStatuses, mapActionResult);
1150
+ }
1151
+ /**
1152
+ * RxJS operator for selecting out specific actions.
1153
+ *
1154
+ * This will ONLY grab actions that have just thrown an error
1155
+ */
1156
+ function ofActionErrored(...allowedTypes) {
1157
+ return ofActionOperator(allowedTypes, ["ERRORED" /* ActionStatus.Errored */]);
1088
1158
  }
1089
- /** @nocollapse */ InternalStateOperations.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalStateOperations, deps: [{ token: StateStream }, { token: InternalDispatcher }, { token: NgxsConfig }], target: i0.ɵɵFactoryTarget.Injectable });
1090
- /** @nocollapse */ InternalStateOperations.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalStateOperations, providedIn: 'root' });
1091
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalStateOperations, decorators: [{
1092
- type: Injectable,
1093
- args: [{ providedIn: 'root' }]
1094
- }], ctorParameters: function () { return [{ type: StateStream }, { type: InternalDispatcher }, { type: NgxsConfig }]; } });
1095
- function ensureStateAndActionsAreImmutable(root) {
1096
- return {
1097
- getState: () => root.getState(),
1098
- setState: value => {
1099
- const frozenValue = deepFreeze(value);
1100
- return root.setState(frozenValue);
1101
- },
1102
- dispatch: actions => {
1103
- return root.dispatch(actions);
1104
- }
1159
+ function ofActionOperator(allowedTypes, statuses,
1160
+ // This actually could've been `OperatorFunction<ActionContext, ActionCompletion | any>`,
1161
+ // since it maps either to `ctx.action` OR to `ActionCompletion`. But `ActionCompleteion | any`
1162
+ // defaults to `any`, thus there is no sense from union type.
1163
+ mapOperator = mapAction) {
1164
+ const allowedMap = createAllowedActionTypesMap(allowedTypes);
1165
+ const allowedStatusMap = statuses && createAllowedStatusesMap(statuses);
1166
+ return function (o) {
1167
+ return o.pipe(filterStatus(allowedMap, allowedStatusMap), mapOperator());
1105
1168
  };
1106
1169
  }
1170
+ function filterStatus(allowedTypes, allowedStatuses) {
1171
+ return filter((ctx) => {
1172
+ const actionType = getActionTypeFromInstance(ctx.action);
1173
+ const typeMatch = allowedTypes[actionType];
1174
+ const statusMatch = allowedStatuses ? allowedStatuses[ctx.status] : true;
1175
+ return typeMatch && statusMatch;
1176
+ });
1177
+ }
1178
+ function mapActionResult() {
1179
+ return map(({ action, status, error }) => {
1180
+ return {
1181
+ action,
1182
+ result: {
1183
+ successful: "SUCCESSFUL" /* ActionStatus.Successful */ === status,
1184
+ canceled: "CANCELED" /* ActionStatus.Canceled */ === status,
1185
+ error
1186
+ }
1187
+ };
1188
+ });
1189
+ }
1190
+ function mapAction() {
1191
+ return map((ctx) => ctx.action);
1192
+ }
1193
+ function createAllowedActionTypesMap(types) {
1194
+ return types.reduce((filterMap, klass) => {
1195
+ filterMap[getActionTypeFromInstance(klass)] = true;
1196
+ return filterMap;
1197
+ }, {});
1198
+ }
1199
+ function createAllowedStatusesMap(statuses) {
1200
+ return statuses.reduce((filterMap, status) => {
1201
+ filterMap[status] = true;
1202
+ return filterMap;
1203
+ }, {});
1204
+ }
1107
1205
 
1108
1206
  function simplePatch(value) {
1109
1207
  return (existingState) => {
@@ -1115,7 +1213,7 @@ function simplePatch(value) {
1115
1213
  throwPatchingPrimitiveError();
1116
1214
  }
1117
1215
  }
1118
- const newState = Object.assign({}, existingState);
1216
+ const newState = { ...existingState };
1119
1217
  for (const key in value) {
1120
1218
  // deep clone for patch compatibility
1121
1219
  newState[key] = value[key];
@@ -1137,43 +1235,21 @@ class StateContextFactory {
1137
1235
  */
1138
1236
  createStateContext(mappedStore) {
1139
1237
  const root = this._internalStateOperations.getRootStateOperations();
1140
- function getState(currentAppState) {
1141
- return getValue(currentAppState, mappedStore.path);
1142
- }
1143
- function setStateValue(currentAppState, newValue) {
1144
- const newAppState = setValue(currentAppState, mappedStore.path, newValue);
1145
- root.setState(newAppState);
1146
- return newAppState;
1147
- // In doing this refactoring I noticed that there is a 'bug' where the
1148
- // application state is returned instead of this state slice.
1149
- // This has worked this way since the beginning see:
1150
- // https://github.com/ngxs/store/blame/324c667b4b7debd8eb979006c67ca0ae347d88cd/src/state-factory.ts
1151
- // This needs to be fixed, but is a 'breaking' change.
1152
- // I will do this fix in a subsequent PR and we can decide how to handle it.
1153
- }
1154
- function setStateFromOperator(currentAppState, stateOperator) {
1155
- const local = getState(currentAppState);
1156
- const newValue = stateOperator(local);
1157
- return setStateValue(currentAppState, newValue);
1158
- }
1159
- function isStateOperator(value) {
1160
- return typeof value === 'function';
1161
- }
1162
1238
  return {
1163
1239
  getState() {
1164
1240
  const currentAppState = root.getState();
1165
- return getState(currentAppState);
1241
+ return getState(currentAppState, mappedStore.path);
1166
1242
  },
1167
1243
  patchState(val) {
1168
1244
  const currentAppState = root.getState();
1169
1245
  const patchOperator = simplePatch(val);
1170
- return setStateFromOperator(currentAppState, patchOperator);
1246
+ return setStateFromOperator(root, currentAppState, patchOperator, mappedStore.path);
1171
1247
  },
1172
1248
  setState(val) {
1173
1249
  const currentAppState = root.getState();
1174
1250
  return isStateOperator(val)
1175
- ? setStateFromOperator(currentAppState, val)
1176
- : setStateValue(currentAppState, val);
1251
+ ? setStateFromOperator(root, currentAppState, val, mappedStore.path)
1252
+ : setStateValue(root, currentAppState, val, mappedStore.path);
1177
1253
  },
1178
1254
  dispatch(actions) {
1179
1255
  return root.dispatch(actions);
@@ -1181,37 +1257,54 @@ class StateContextFactory {
1181
1257
  };
1182
1258
  }
1183
1259
  }
1184
- /** @nocollapse */ StateContextFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateContextFactory, deps: [{ token: InternalStateOperations }], target: i0.ɵɵFactoryTarget.Injectable });
1185
- /** @nocollapse */ StateContextFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateContextFactory, providedIn: 'root' });
1186
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateContextFactory, decorators: [{
1260
+ /** @nocollapse */ StateContextFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateContextFactory, deps: [{ token: InternalStateOperations }], target: i0.ɵɵFactoryTarget.Injectable });
1261
+ /** @nocollapse */ StateContextFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateContextFactory, providedIn: 'root' });
1262
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateContextFactory, decorators: [{
1187
1263
  type: Injectable,
1188
1264
  args: [{ providedIn: 'root' }]
1189
1265
  }], ctorParameters: function () { return [{ type: InternalStateOperations }]; } });
1266
+ function setStateValue(root, currentAppState, newValue, path) {
1267
+ const newAppState = setValue(currentAppState, path, newValue);
1268
+ root.setState(newAppState);
1269
+ return newAppState;
1270
+ // In doing this refactoring I noticed that there is a 'bug' where the
1271
+ // application state is returned instead of this state slice.
1272
+ // This has worked this way since the beginning see:
1273
+ // https://github.com/ngxs/store/blame/324c667b4b7debd8eb979006c67ca0ae347d88cd/src/state-factory.ts
1274
+ // This needs to be fixed, but is a 'breaking' change.
1275
+ // I will do this fix in a subsequent PR and we can decide how to handle it.
1276
+ }
1277
+ function setStateFromOperator(root, currentAppState, stateOperator, path) {
1278
+ const local = getState(currentAppState, path);
1279
+ const newValue = stateOperator(local);
1280
+ return setStateValue(root, currentAppState, newValue, path);
1281
+ }
1282
+ function getState(currentAppState, path) {
1283
+ return getValue(currentAppState, path);
1284
+ }
1190
1285
 
1191
- class StoreValidators {
1192
- static checkThatStateIsNamedCorrectly(name) {
1193
- if (!name) {
1194
- throwStateNamePropertyError();
1195
- }
1196
- else if (!this.stateNameRegex.test(name)) {
1197
- throwStateNameError(name);
1198
- }
1286
+ const stateNameRegex = new RegExp('^[a-zA-Z0-9_]+$');
1287
+ function ensureStateNameIsValid(name) {
1288
+ if (!name) {
1289
+ throwStateNamePropertyError();
1199
1290
  }
1200
- static checkThatStateNameIsUnique(stateName, state, statesByName) {
1201
- const existingState = statesByName[stateName];
1202
- if (existingState && existingState !== state) {
1203
- throwStateUniqueError(stateName, state.name, existingState.name);
1204
- }
1291
+ else if (!stateNameRegex.test(name)) {
1292
+ throwStateNameError(name);
1205
1293
  }
1206
- static checkThatStateClassesHaveBeenDecorated(stateClasses) {
1207
- stateClasses.forEach((stateClass) => {
1208
- if (!getStoreMetadata$1(stateClass)) {
1209
- throwStateDecoratorError(stateClass.name);
1210
- }
1211
- });
1294
+ }
1295
+ function ensureStateNameIsUnique(stateName, state, statesByName) {
1296
+ const existingState = statesByName[stateName];
1297
+ if (existingState && existingState !== state) {
1298
+ throwStateUniqueError(stateName, state.name, existingState.name);
1212
1299
  }
1213
1300
  }
1214
- StoreValidators.stateNameRegex = new RegExp('^[a-zA-Z0-9_]+$');
1301
+ function ensureStatesAreDecorated(stateClasses) {
1302
+ stateClasses.forEach((stateClass) => {
1303
+ if (!getStoreMetadata$1(stateClass)) {
1304
+ throwStateDecoratorError(stateClass.name);
1305
+ }
1306
+ });
1307
+ }
1215
1308
 
1216
1309
  /**
1217
1310
  * All provided or injected tokens must have `@Injectable` decorator
@@ -1234,18 +1327,15 @@ function aot_hasNgInjectableDef(stateClass) {
1234
1327
  function jit_hasInjectableAnnotation(stateClass) {
1235
1328
  // `ɵprov` doesn't exist in JIT mode (for instance when running unit tests with Jest).
1236
1329
  const annotations = stateClass.__annotations__ || [];
1237
- return annotations.some((annotation) => (annotation === null || annotation === void 0 ? void 0 : annotation.ngMetadataName) === 'Injectable');
1330
+ return annotations.some((annotation) => annotation?.ngMetadataName === 'Injectable');
1238
1331
  }
1239
1332
 
1240
1333
  /**
1241
1334
  * Init action
1242
1335
  */
1243
1336
  class InitState {
1244
- static get type() {
1245
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
1246
- return '@@INIT';
1247
- }
1248
1337
  }
1338
+ InitState.type = '@@INIT';
1249
1339
  /**
1250
1340
  * Update action
1251
1341
  */
@@ -1253,11 +1343,8 @@ class UpdateState {
1253
1343
  constructor(addedStates) {
1254
1344
  this.addedStates = addedStates;
1255
1345
  }
1256
- static get type() {
1257
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
1258
- return '@@UPDATE_STATE';
1259
- }
1260
1346
  }
1347
+ UpdateState.type = '@@UPDATE_STATE';
1261
1348
 
1262
1349
  const NGXS_DEVELOPMENT_OPTIONS = new InjectionToken('NGXS_DEVELOPMENT_OPTIONS', {
1263
1350
  providedIn: 'root',
@@ -1296,16 +1383,16 @@ class NgxsUnhandledActionsLogger {
1296
1383
  console.warn(`The ${action} action has been dispatched but hasn't been handled. This may happen if the state with an action handler for this action is not registered.`);
1297
1384
  }
1298
1385
  }
1299
- /** @nocollapse */ NgxsUnhandledActionsLogger.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsUnhandledActionsLogger, deps: [{ token: NGXS_DEVELOPMENT_OPTIONS }], target: i0.ɵɵFactoryTarget.Injectable });
1300
- /** @nocollapse */ NgxsUnhandledActionsLogger.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsUnhandledActionsLogger });
1301
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsUnhandledActionsLogger, decorators: [{
1386
+ /** @nocollapse */ NgxsUnhandledActionsLogger.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsUnhandledActionsLogger, deps: [{ token: NGXS_DEVELOPMENT_OPTIONS }], target: i0.ɵɵFactoryTarget.Injectable });
1387
+ /** @nocollapse */ NgxsUnhandledActionsLogger.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsUnhandledActionsLogger });
1388
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsUnhandledActionsLogger, decorators: [{
1302
1389
  type: Injectable
1303
1390
  }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1304
1391
  type: Inject,
1305
1392
  args: [NGXS_DEVELOPMENT_OPTIONS]
1306
1393
  }] }]; } });
1307
1394
 
1308
- const NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;
1395
+ const NG_DEV_MODE$2 = typeof ngDevMode === 'undefined' || ngDevMode;
1309
1396
  /**
1310
1397
  * The `StateFactory` class adds root and feature states to the graph.
1311
1398
  * This extracts state names from state classes, checks if they already
@@ -1343,21 +1430,26 @@ class StateFactory {
1343
1430
  ? this._parentFactory.getRuntimeSelectorContext()
1344
1431
  : {
1345
1432
  getStateGetter(key) {
1346
- let getter = resolveGetter(key);
1433
+ // Use `@__INLINE__` annotation to forcely inline `resolveGetter`.
1434
+ // This is a Terser annotation, which will function only in the production mode.
1435
+ let getter = /*@__INLINE__*/ resolveGetter(key);
1347
1436
  if (getter) {
1348
1437
  return getter;
1349
1438
  }
1350
1439
  return (...args) => {
1351
1440
  // Late loaded getter
1352
1441
  if (!getter) {
1353
- getter = resolveGetter(key);
1442
+ getter = /*@__INLINE__*/ resolveGetter(key);
1354
1443
  }
1355
1444
  return getter ? getter(...args) : undefined;
1356
1445
  };
1357
1446
  },
1358
1447
  getSelectorOptions(localOptions) {
1359
1448
  const globalSelectorOptions = stateFactory._config.selectorOptions;
1360
- return Object.assign(Object.assign({}, globalSelectorOptions), (localOptions || {}));
1449
+ return {
1450
+ ...globalSelectorOptions,
1451
+ ...(localOptions || {})
1452
+ };
1361
1453
  }
1362
1454
  };
1363
1455
  return context;
@@ -1372,32 +1464,28 @@ class StateFactory {
1372
1464
  get statePaths() {
1373
1465
  return this._parentFactory ? this._parentFactory.statePaths : this._statePaths;
1374
1466
  }
1375
- static cloneDefaults(defaults) {
1376
- let value = {};
1467
+ static _cloneDefaults(defaults) {
1468
+ let value = defaults;
1377
1469
  if (Array.isArray(defaults)) {
1378
1470
  value = defaults.slice();
1379
1471
  }
1380
1472
  else if (isObject(defaults)) {
1381
- value = Object.assign({}, defaults);
1473
+ value = { ...defaults };
1382
1474
  }
1383
1475
  else if (defaults === undefined) {
1384
1476
  value = {};
1385
1477
  }
1386
- else {
1387
- value = defaults;
1388
- }
1389
1478
  return value;
1390
1479
  }
1391
1480
  ngOnDestroy() {
1392
- var _a;
1393
- (_a = this._actionsSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
1481
+ this._actionsSubscription?.unsubscribe();
1394
1482
  }
1395
1483
  /**
1396
1484
  * Add a new state to the global defs.
1397
1485
  */
1398
1486
  add(stateClasses) {
1399
- if (NG_DEV_MODE) {
1400
- StoreValidators.checkThatStateClassesHaveBeenDecorated(stateClasses);
1487
+ if (NG_DEV_MODE$2) {
1488
+ ensureStatesAreDecorated(stateClasses);
1401
1489
  }
1402
1490
  const { newStates } = this.addToStatesMap(stateClasses);
1403
1491
  if (!newStates.length)
@@ -1410,13 +1498,13 @@ class StateFactory {
1410
1498
  for (const name of sortedStates) {
1411
1499
  const stateClass = nameGraph[name];
1412
1500
  const path = paths[name];
1413
- const meta = stateClass[META_KEY];
1501
+ const meta = stateClass[ɵMETA_KEY];
1414
1502
  this.addRuntimeInfoToMeta(meta, path);
1415
1503
  // Note: previously we called `ensureStateClassIsInjectable` within the
1416
1504
  // `State` decorator. This check is moved here because the `ɵprov` property
1417
1505
  // will not exist on the class in JIT mode (because it's set asynchronously
1418
1506
  // during JIT compilation through `Object.defineProperty`).
1419
- if (typeof ngDevMode === 'undefined' || ngDevMode) {
1507
+ if (NG_DEV_MODE$2) {
1420
1508
  ensureStateClassIsInjectable(stateClass);
1421
1509
  }
1422
1510
  const stateMap = {
@@ -1425,7 +1513,7 @@ class StateFactory {
1425
1513
  isInitialised: false,
1426
1514
  actions: meta.actions,
1427
1515
  instance: this._injector.get(stateClass),
1428
- defaults: StateFactory.cloneDefaults(meta.defaults)
1516
+ defaults: StateFactory._cloneDefaults(meta.defaults)
1429
1517
  };
1430
1518
  // ensure our store hasn't already been added
1431
1519
  // but don't throw since it could be lazy
@@ -1455,10 +1543,10 @@ class StateFactory {
1455
1543
  }
1456
1544
  const dispatched$ = new Subject();
1457
1545
  this._actionsSubscription = this._actions
1458
- .pipe(filter((ctx) => ctx.status === "DISPATCHED" /* Dispatched */), mergeMap(ctx => {
1546
+ .pipe(filter((ctx) => ctx.status === "DISPATCHED" /* ActionStatus.Dispatched */), mergeMap(ctx => {
1459
1547
  dispatched$.next(ctx);
1460
1548
  const action = ctx.action;
1461
- return this.invokeActions(dispatched$, action).pipe(map(() => ({ action, status: "SUCCESSFUL" /* Successful */ })), defaultIfEmpty({ action, status: "CANCELED" /* Canceled */ }), catchError(error => of({ action, status: "ERRORED" /* Errored */, error })));
1549
+ return this.invokeActions(dispatched$, action).pipe(map(() => ({ action, status: "SUCCESSFUL" /* ActionStatus.Successful */ })), defaultIfEmpty({ action, status: "CANCELED" /* ActionStatus.Canceled */ }), catchError(error => of({ action, status: "ERRORED" /* ActionStatus.Errored */, error })));
1462
1550
  }))
1463
1551
  .subscribe(ctx => this._actionResults.next(ctx));
1464
1552
  }
@@ -1518,7 +1606,7 @@ class StateFactory {
1518
1606
  }
1519
1607
  // The `NgxsUnhandledActionsLogger` is a tree-shakable class which functions
1520
1608
  // only during development.
1521
- if (NG_DEV_MODE && !actionHasBeenHandled) {
1609
+ if (NG_DEV_MODE$2 && !actionHasBeenHandled) {
1522
1610
  const unhandledActionsLogger = this._injector.get(NgxsUnhandledActionsLogger, null);
1523
1611
  // The `NgxsUnhandledActionsLogger` will not be resolved by the injector if the
1524
1612
  // `NgxsDevelopmentModule` is not provided. It's enough to check whether the `injector.get`
@@ -1537,8 +1625,8 @@ class StateFactory {
1537
1625
  const statesMap = this.statesByName;
1538
1626
  for (const stateClass of stateClasses) {
1539
1627
  const stateName = getStoreMetadata$1(stateClass).name;
1540
- if (NG_DEV_MODE) {
1541
- StoreValidators.checkThatStateNameIsUnique(stateName, stateClass, statesMap);
1628
+ if (NG_DEV_MODE$2) {
1629
+ ensureStateNameIsUnique(stateName, stateClass, statesMap);
1542
1630
  }
1543
1631
  const unmountedState = !statesMap[stateName];
1544
1632
  if (unmountedState) {
@@ -1562,9 +1650,9 @@ class StateFactory {
1562
1650
  return this.statesByName[name] && valueIsBootstrappedInInitialState;
1563
1651
  }
1564
1652
  }
1565
- /** @nocollapse */ StateFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateFactory, deps: [{ token: i0.Injector }, { token: NgxsConfig }, { token: StateFactory, optional: true, skipSelf: true }, { token: InternalActions }, { token: InternalDispatchedActionResults }, { token: StateContextFactory }, { token: INITIAL_STATE_TOKEN, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
1566
- /** @nocollapse */ StateFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateFactory });
1567
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateFactory, decorators: [{
1653
+ /** @nocollapse */ StateFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateFactory, deps: [{ token: i0.Injector }, { token: NgxsConfig }, { token: StateFactory, optional: true, skipSelf: true }, { token: InternalActions }, { token: InternalDispatchedActionResults }, { token: StateContextFactory }, { token: INITIAL_STATE_TOKEN, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
1654
+ /** @nocollapse */ StateFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateFactory });
1655
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateFactory, decorators: [{
1568
1656
  type: Injectable
1569
1657
  }], ctorParameters: function () { return [{ type: i0.Injector }, { type: NgxsConfig }, { type: StateFactory, decorators: [{
1570
1658
  type: Optional
@@ -1577,78 +1665,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
1577
1665
  args: [INITIAL_STATE_TOKEN]
1578
1666
  }] }]; } });
1579
1667
 
1580
- function createRootSelectorFactory(selectorMetaData, selectors, memoizedSelectorFn) {
1581
- return (context) => {
1582
- const { argumentSelectorFunctions, selectorOptions } = getRuntimeSelectorInfo(context, selectorMetaData, selectors);
1583
- return function selectFromRoot(rootState) {
1584
- // Determine arguments from the app state using the selectors
1585
- const results = argumentSelectorFunctions.map((argFn) => argFn(rootState));
1586
- // if the lambda tries to access a something on the
1587
- // state that doesn't exist, it will throw a TypeError.
1588
- // since this is quite usual behaviour, we simply return undefined if so.
1589
- try {
1590
- return memoizedSelectorFn(...results);
1591
- }
1592
- catch (ex) {
1593
- if (ex instanceof TypeError && selectorOptions.suppressErrors) {
1594
- return undefined;
1595
- }
1596
- throw ex;
1597
- }
1598
- };
1599
- };
1600
- }
1601
- function createMemoizedSelectorFn(originalFn, creationMetadata) {
1602
- const containerClass = creationMetadata && creationMetadata.containerClass;
1603
- const wrappedFn = function wrappedSelectorFn(...args) {
1604
- const returnValue = originalFn.apply(containerClass, args);
1605
- if (returnValue instanceof Function) {
1606
- const innerMemoizedFn = memoize.apply(null, [returnValue]);
1607
- return innerMemoizedFn;
1608
- }
1609
- return returnValue;
1610
- };
1611
- const memoizedFn = memoize(wrappedFn);
1612
- Object.setPrototypeOf(memoizedFn, originalFn);
1613
- return memoizedFn;
1614
- }
1615
- function getRuntimeSelectorInfo(context, selectorMetaData, selectors = []) {
1616
- const localSelectorOptions = selectorMetaData.getSelectorOptions();
1617
- const selectorOptions = context.getSelectorOptions(localSelectorOptions);
1618
- const selectorsToApply = getSelectorsToApply(selectors, selectorOptions, selectorMetaData.containerClass);
1619
- const argumentSelectorFunctions = selectorsToApply.map((selector) => {
1620
- const factory = getRootSelectorFactory(selector);
1621
- return factory(context);
1622
- });
1623
- return {
1624
- selectorOptions,
1625
- argumentSelectorFunctions,
1626
- };
1627
- }
1628
- function getSelectorsToApply(selectors = [], selectorOptions, containerClass) {
1629
- const selectorsToApply = [];
1630
- const canInjectContainerState = selectors.length === 0 || selectorOptions.injectContainerState;
1631
- if (containerClass && canInjectContainerState) {
1632
- // If we are on a state class, add it as the first selector parameter
1633
- const metadata = getStoreMetadata$1(containerClass);
1634
- if (metadata) {
1635
- selectorsToApply.push(containerClass);
1636
- }
1637
- }
1638
- if (selectors) {
1639
- selectorsToApply.push(...selectors);
1640
- }
1641
- return selectorsToApply;
1642
- }
1643
- /**
1644
- * This function gets the factory function to create the selector to get the selected slice from the app state
1645
- * @ignore
1646
- */
1647
- function getRootSelectorFactory(selector) {
1648
- const metadata = getSelectorMetadata$1(selector) || getStoreMetadata$1(selector);
1649
- return (metadata && metadata.makeRootSelector) || (() => selector);
1650
- }
1651
-
1652
1668
  // tslint:disable:unified-signatures
1653
1669
  class Store {
1654
1670
  constructor(_stateStream, _internalStateOperations, _config, _internalExecutionStrategy, _stateFactory, initialStateValue) {
@@ -1722,14 +1738,15 @@ class Store {
1722
1738
  if (storeIsEmpty) {
1723
1739
  const defaultStateNotEmpty = Object.keys(this._config.defaultsState).length > 0;
1724
1740
  const storeValues = defaultStateNotEmpty
1725
- ? Object.assign(Object.assign({}, this._config.defaultsState), initialStateValue) : initialStateValue;
1741
+ ? { ...this._config.defaultsState, ...initialStateValue }
1742
+ : initialStateValue;
1726
1743
  this._stateStream.next(storeValues);
1727
1744
  }
1728
1745
  }
1729
1746
  }
1730
- /** @nocollapse */ Store.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Store, deps: [{ token: StateStream }, { token: InternalStateOperations }, { token: NgxsConfig }, { token: InternalNgxsExecutionStrategy }, { token: StateFactory }, { token: INITIAL_STATE_TOKEN, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
1731
- /** @nocollapse */ Store.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Store, providedIn: 'root' });
1732
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Store, decorators: [{
1747
+ /** @nocollapse */ Store.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: Store, deps: [{ token: StateStream }, { token: InternalStateOperations }, { token: NgxsConfig }, { token: InternalNgxsExecutionStrategy }, { token: StateFactory }, { token: INITIAL_STATE_TOKEN, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
1748
+ /** @nocollapse */ Store.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: Store, providedIn: 'root' });
1749
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: Store, decorators: [{
1733
1750
  type: Injectable,
1734
1751
  args: [{ providedIn: 'root' }]
1735
1752
  }], ctorParameters: function () { return [{ type: StateStream }, { type: InternalStateOperations }, { type: NgxsConfig }, { type: InternalNgxsExecutionStrategy }, { type: StateFactory }, { type: undefined, decorators: [{
@@ -1755,13 +1772,14 @@ class SelectFactory {
1755
1772
  }
1756
1773
  SelectFactory.store = null;
1757
1774
  SelectFactory.config = null;
1758
- /** @nocollapse */ SelectFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SelectFactory, deps: [{ token: Store }, { token: NgxsConfig }], target: i0.ɵɵFactoryTarget.Injectable });
1759
- /** @nocollapse */ SelectFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SelectFactory, providedIn: 'root' });
1760
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SelectFactory, decorators: [{
1775
+ /** @nocollapse */ SelectFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: SelectFactory, deps: [{ token: Store }, { token: NgxsConfig }], target: i0.ɵɵFactoryTarget.Injectable });
1776
+ /** @nocollapse */ SelectFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: SelectFactory, providedIn: 'root' });
1777
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: SelectFactory, decorators: [{
1761
1778
  type: Injectable,
1762
1779
  args: [{ providedIn: 'root' }]
1763
1780
  }], ctorParameters: function () { return [{ type: Store }, { type: NgxsConfig }]; } });
1764
1781
 
1782
+ const NG_DEV_MODE$1 = typeof ngDevMode === 'undefined' || ngDevMode;
1765
1783
  class LifecycleStateManager {
1766
1784
  constructor(_store, _internalErrorReporter, _internalStateOperations, _stateContextFactory, _bootstrapper) {
1767
1785
  this._store = _store;
@@ -1769,12 +1787,27 @@ class LifecycleStateManager {
1769
1787
  this._internalStateOperations = _internalStateOperations;
1770
1788
  this._stateContextFactory = _stateContextFactory;
1771
1789
  this._bootstrapper = _bootstrapper;
1772
- this._destroy$ = new Subject();
1790
+ this._destroy$ = new ReplaySubject(1);
1773
1791
  }
1774
1792
  ngOnDestroy() {
1775
1793
  this._destroy$.next();
1776
1794
  }
1777
1795
  ngxsBootstrap(action, results) {
1796
+ if (NG_DEV_MODE$1) {
1797
+ if (action instanceof InitState) {
1798
+ this._initStateHasBeenDispatched = true;
1799
+ }
1800
+ else if (
1801
+ // This is a dev mode-only check that ensures the correct order of
1802
+ // state initialization. The `NgxsModule.forRoot` or `provideStore` should
1803
+ // always come first, followed by `forFeature` and `provideStates`. If the
1804
+ // `UpdateState` is dispatched before the `InitState` is dispatched, it indicates
1805
+ // that modules or providers are in an invalid order.
1806
+ action instanceof UpdateState &&
1807
+ !this._initStateHasBeenDispatched) {
1808
+ console.error(getInvalidInitializationOrderMessage(action.addedStates));
1809
+ }
1810
+ }
1778
1811
  this._internalStateOperations
1779
1812
  .getRootStateOperations()
1780
1813
  .dispatch(action)
@@ -1818,148 +1851,196 @@ class LifecycleStateManager {
1818
1851
  return this._stateContextFactory.createStateContext(mappedStore);
1819
1852
  }
1820
1853
  }
1821
- /** @nocollapse */ LifecycleStateManager.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LifecycleStateManager, deps: [{ token: Store }, { token: InternalErrorReporter }, { token: InternalStateOperations }, { token: StateContextFactory }, { token: i5.NgxsBootstrapper }], target: i0.ɵɵFactoryTarget.Injectable });
1822
- /** @nocollapse */ LifecycleStateManager.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LifecycleStateManager, providedIn: 'root' });
1823
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LifecycleStateManager, decorators: [{
1854
+ /** @nocollapse */ LifecycleStateManager.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: LifecycleStateManager, deps: [{ token: Store }, { token: InternalErrorReporter }, { token: InternalStateOperations }, { token: StateContextFactory }, { token: i5.NgxsBootstrapper }], target: i0.ɵɵFactoryTarget.Injectable });
1855
+ /** @nocollapse */ LifecycleStateManager.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: LifecycleStateManager, providedIn: 'root' });
1856
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: LifecycleStateManager, decorators: [{
1824
1857
  type: Injectable,
1825
1858
  args: [{ providedIn: 'root' }]
1826
1859
  }], ctorParameters: function () { return [{ type: Store }, { type: InternalErrorReporter }, { type: InternalStateOperations }, { type: StateContextFactory }, { type: i5.NgxsBootstrapper }]; } });
1827
1860
 
1861
+ const NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;
1862
+ /**
1863
+ * This function is shared by both NgModule and standalone features.
1864
+ * When using `NgxsModule.forRoot` and `provideStore`, we can depend on the
1865
+ * same initialization functionality.
1866
+ */
1867
+ function rootStoreInitializer() {
1868
+ const factory = inject(StateFactory);
1869
+ const internalStateOperations = inject(InternalStateOperations);
1870
+ inject(Store);
1871
+ inject(SelectFactory);
1872
+ const states = inject(ROOT_STATE_TOKEN, { optional: true }) || [];
1873
+ const lifecycleStateManager = inject(LifecycleStateManager);
1874
+ // Add stores to the state graph and return their defaults.
1875
+ const results = factory.addAndReturnDefaults(states);
1876
+ internalStateOperations.setStateToTheCurrentWithNew(results);
1877
+ // Connect our actions stream.
1878
+ factory.connectActionHandlers();
1879
+ // Dispatch the init action and invoke init and bootstrap functions after.
1880
+ lifecycleStateManager.ngxsBootstrap(new InitState(), results);
1881
+ }
1882
+ /**
1883
+ * This function is utilized by both NgModule and standalone features.
1884
+ * When using `NgxsModule.forFeature` and `provideStates`, we can depend on
1885
+ * the same initialization functionality.
1886
+ */
1887
+ function featureStatesInitializer() {
1888
+ inject(Store);
1889
+ const internalStateOperations = inject(InternalStateOperations);
1890
+ const factory = inject(StateFactory);
1891
+ const states = inject(FEATURE_STATE_TOKEN, { optional: true }) || [];
1892
+ const lifecycleStateManager = inject(LifecycleStateManager);
1893
+ // Since FEATURE_STATE_TOKEN is a multi token, we need to
1894
+ // flatten it [[Feature1State, Feature2State], [Feature3State]].
1895
+ const flattenedStates = states.reduce((total, values) => total.concat(values), []);
1896
+ // add stores to the state graph and return their defaults.
1897
+ const results = factory.addAndReturnDefaults(flattenedStates);
1898
+ if (results.states.length) {
1899
+ internalStateOperations.setStateToTheCurrentWithNew(results);
1900
+ // Dispatch the update action and invoke init and bootstrap functions after.
1901
+ lifecycleStateManager.ngxsBootstrap(new UpdateState(results.defaults), results);
1902
+ }
1903
+ }
1904
+ /**
1905
+ * InjectionToken that registers the global Store.
1906
+ */
1907
+ const NGXS_ROOT_STORE_INITIALIZER = new InjectionToken(NG_DEV_MODE ? 'NGXS_ROOT_STORE_INITIALIZER' : '');
1908
+ /**
1909
+ * InjectionToken that registers feature states.
1910
+ */
1911
+ const NGXS_FEATURE_STORE_INITIALIZER = new InjectionToken(NG_DEV_MODE ? 'NGXS_FEATURE_STORE_INITIALIZER' : '');
1912
+ const NGXS_ROOT_ENVIRONMENT_INITIALIZER = [
1913
+ { provide: NGXS_ROOT_STORE_INITIALIZER, useFactory: rootStoreInitializer },
1914
+ {
1915
+ provide: ENVIRONMENT_INITIALIZER,
1916
+ multi: true,
1917
+ useFactory() {
1918
+ return () => inject(NGXS_ROOT_STORE_INITIALIZER);
1919
+ }
1920
+ }
1921
+ ];
1922
+ /**
1923
+ * The `NGXS_FEATURE_ENVIRONMENT_INITIALIZER` functions as an environment initializer
1924
+ * at the `Route` level. Angular Router creates an environment route injector for each
1925
+ * matched route where navigation occurs. The injector is created once, ensuring that
1926
+ * the feature states initialization only happens once as well.
1927
+ */
1928
+ const NGXS_FEATURE_ENVIRONMENT_INITIALIZER = [
1929
+ { provide: NGXS_FEATURE_STORE_INITIALIZER, useFactory: featureStatesInitializer },
1930
+ {
1931
+ provide: ENVIRONMENT_INITIALIZER,
1932
+ multi: true,
1933
+ useFactory() {
1934
+ return () => inject(NGXS_FEATURE_STORE_INITIALIZER);
1935
+ }
1936
+ }
1937
+ ];
1938
+
1828
1939
  /**
1829
- * Root module
1830
1940
  * @ignore
1831
1941
  */
1832
1942
  class NgxsRootModule {
1833
- constructor(factory, internalStateOperations, _store, _select, states = [], lifecycleStateManager) {
1834
- // Add stores to the state graph and return their defaults
1835
- const results = factory.addAndReturnDefaults(states);
1836
- internalStateOperations.setStateToTheCurrentWithNew(results);
1837
- // Connect our actions stream
1838
- factory.connectActionHandlers();
1839
- // Dispatch the init action and invoke init and bootstrap functions after
1840
- lifecycleStateManager.ngxsBootstrap(new InitState(), results);
1943
+ constructor() {
1944
+ rootStoreInitializer();
1841
1945
  }
1842
1946
  }
1843
- /** @nocollapse */ NgxsRootModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsRootModule, deps: [{ token: StateFactory }, { token: InternalStateOperations }, { token: Store }, { token: SelectFactory }, { token: ROOT_STATE_TOKEN, optional: true }, { token: LifecycleStateManager }], target: i0.ɵɵFactoryTarget.NgModule });
1844
- /** @nocollapse */ NgxsRootModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsRootModule });
1845
- /** @nocollapse */ NgxsRootModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsRootModule });
1846
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsRootModule, decorators: [{
1947
+ /** @nocollapse */ NgxsRootModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsRootModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1948
+ /** @nocollapse */ NgxsRootModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.4", ngImport: i0, type: NgxsRootModule });
1949
+ /** @nocollapse */ NgxsRootModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsRootModule });
1950
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsRootModule, decorators: [{
1847
1951
  type: NgModule
1848
- }], ctorParameters: function () { return [{ type: StateFactory }, { type: InternalStateOperations }, { type: Store }, { type: SelectFactory }, { type: undefined, decorators: [{
1849
- type: Optional
1850
- }, {
1851
- type: Inject,
1852
- args: [ROOT_STATE_TOKEN]
1853
- }] }, { type: LifecycleStateManager }]; } });
1952
+ }], ctorParameters: function () { return []; } });
1854
1953
 
1855
1954
  /**
1856
- * Feature module
1857
1955
  * @ignore
1858
1956
  */
1859
1957
  class NgxsFeatureModule {
1860
- constructor(_store, internalStateOperations, factory, states = [], lifecycleStateManager) {
1861
- // Since FEATURE_STATE_TOKEN is a multi token, we need to
1862
- // flatten it [[Feature1State, Feature2State], [Feature3State]]
1863
- const flattenedStates = NgxsFeatureModule.flattenStates(states);
1864
- // add stores to the state graph and return their defaults
1865
- const results = factory.addAndReturnDefaults(flattenedStates);
1866
- if (results.states.length) {
1867
- internalStateOperations.setStateToTheCurrentWithNew(results);
1868
- // dispatch the update action and invoke init and bootstrap functions after
1869
- lifecycleStateManager.ngxsBootstrap(new UpdateState(results.defaults), results);
1870
- }
1871
- }
1872
- static flattenStates(states = []) {
1873
- return states.reduce((total, values) => total.concat(values), []);
1958
+ constructor() {
1959
+ featureStatesInitializer();
1874
1960
  }
1875
1961
  }
1876
- /** @nocollapse */ NgxsFeatureModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsFeatureModule, deps: [{ token: Store }, { token: InternalStateOperations }, { token: StateFactory }, { token: FEATURE_STATE_TOKEN, optional: true }, { token: LifecycleStateManager }], target: i0.ɵɵFactoryTarget.NgModule });
1877
- /** @nocollapse */ NgxsFeatureModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsFeatureModule });
1878
- /** @nocollapse */ NgxsFeatureModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsFeatureModule });
1879
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsFeatureModule, decorators: [{
1962
+ /** @nocollapse */ NgxsFeatureModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsFeatureModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1963
+ /** @nocollapse */ NgxsFeatureModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.4", ngImport: i0, type: NgxsFeatureModule });
1964
+ /** @nocollapse */ NgxsFeatureModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsFeatureModule });
1965
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsFeatureModule, decorators: [{
1880
1966
  type: NgModule
1881
- }], ctorParameters: function () { return [{ type: Store }, { type: InternalStateOperations }, { type: StateFactory }, { type: undefined, decorators: [{
1882
- type: Optional
1883
- }, {
1884
- type: Inject,
1885
- args: [FEATURE_STATE_TOKEN]
1886
- }] }, { type: LifecycleStateManager }]; } });
1967
+ }], ctorParameters: function () { return []; } });
1968
+
1969
+ /**
1970
+ * This function provides the required providers when invoking `NgxsModule.forRoot`
1971
+ * or `provideStore`. It is shared between the NgModule and standalone APIs.
1972
+ */
1973
+ function getRootProviders(states, options) {
1974
+ return [
1975
+ StateFactory,
1976
+ PluginManager,
1977
+ ...states,
1978
+ {
1979
+ provide: ROOT_STATE_TOKEN,
1980
+ useValue: states
1981
+ },
1982
+ {
1983
+ provide: APP_BOOTSTRAP_LISTENER,
1984
+ useFactory: () => {
1985
+ const bootstrapper = inject(NgxsBootstrapper);
1986
+ return () => bootstrapper.bootstrap();
1987
+ },
1988
+ multi: true
1989
+ },
1990
+ {
1991
+ provide: NGXS_OPTIONS,
1992
+ useValue: options
1993
+ },
1994
+ {
1995
+ provide: CUSTOM_NGXS_EXECUTION_STRATEGY,
1996
+ useValue: options.executionStrategy
1997
+ },
1998
+ {
1999
+ provide: ɵNGXS_STATE_CONTEXT_FACTORY,
2000
+ useExisting: StateContextFactory
2001
+ },
2002
+ {
2003
+ provide: ɵNGXS_STATE_FACTORY,
2004
+ useExisting: StateFactory
2005
+ }
2006
+ ];
2007
+ }
1887
2008
 
1888
2009
  /**
1889
- * Ngxs Module
2010
+ * This function provides the required providers when calling `NgxsModule.forFeature`
2011
+ * or `provideStates`. It is shared between the NgModule and standalone APIs.
1890
2012
  */
2013
+ function getFeatureProviders(states) {
2014
+ return [
2015
+ StateFactory,
2016
+ PluginManager,
2017
+ ...states,
2018
+ {
2019
+ provide: FEATURE_STATE_TOKEN,
2020
+ multi: true,
2021
+ useValue: states
2022
+ }
2023
+ ];
2024
+ }
2025
+
1891
2026
  class NgxsModule {
1892
- /**
1893
- * Root module factory
1894
- */
1895
2027
  static forRoot(states = [], options = {}) {
1896
2028
  return {
1897
2029
  ngModule: NgxsRootModule,
1898
- providers: [
1899
- StateFactory,
1900
- PluginManager,
1901
- ...states,
1902
- ...NgxsModule.ngxsTokenProviders(states, options)
1903
- ]
2030
+ providers: getRootProviders(states, options)
1904
2031
  };
1905
2032
  }
1906
- /**
1907
- * Feature module factory
1908
- */
1909
2033
  static forFeature(states = []) {
1910
2034
  return {
1911
2035
  ngModule: NgxsFeatureModule,
1912
- providers: [
1913
- // This is required on the feature level, see comments in `state-factory.ts`.
1914
- StateFactory,
1915
- PluginManager,
1916
- ...states,
1917
- {
1918
- provide: FEATURE_STATE_TOKEN,
1919
- multi: true,
1920
- useValue: states
1921
- }
1922
- ]
2036
+ providers: getFeatureProviders(states)
1923
2037
  };
1924
2038
  }
1925
- static ngxsTokenProviders(states, options) {
1926
- return [
1927
- {
1928
- provide: USER_PROVIDED_NGXS_EXECUTION_STRATEGY,
1929
- useValue: options.executionStrategy
1930
- },
1931
- {
1932
- provide: ROOT_STATE_TOKEN,
1933
- useValue: states
1934
- },
1935
- {
1936
- provide: ROOT_OPTIONS,
1937
- useValue: options
1938
- },
1939
- {
1940
- provide: APP_BOOTSTRAP_LISTENER,
1941
- useFactory: NgxsModule.appBootstrapListenerFactory,
1942
- multi: true,
1943
- deps: [NgxsBootstrapper]
1944
- },
1945
- {
1946
- provide: ɵNGXS_STATE_CONTEXT_FACTORY,
1947
- useExisting: StateContextFactory
1948
- },
1949
- {
1950
- provide: ɵNGXS_STATE_FACTORY,
1951
- useExisting: StateFactory
1952
- }
1953
- ];
1954
- }
1955
- static appBootstrapListenerFactory(bootstrapper) {
1956
- return () => bootstrapper.bootstrap();
1957
- }
1958
2039
  }
1959
- /** @nocollapse */ NgxsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1960
- /** @nocollapse */ NgxsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsModule });
1961
- /** @nocollapse */ NgxsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsModule });
1962
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsModule, decorators: [{
2040
+ /** @nocollapse */ NgxsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2041
+ /** @nocollapse */ NgxsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.4", ngImport: i0, type: NgxsModule });
2042
+ /** @nocollapse */ NgxsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsModule });
2043
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsModule, decorators: [{
1963
2044
  type: NgModule
1964
2045
  }] });
1965
2046
 
@@ -1998,36 +2079,34 @@ function Action(actions, options) {
1998
2079
  * Decorates a class with ngxs state information.
1999
2080
  */
2000
2081
  function State(options) {
2001
- function getStateOptions(inheritedStateClass) {
2002
- const inheritanceOptions = inheritedStateClass[META_OPTIONS_KEY] || {};
2003
- return Object.assign(Object.assign({}, inheritanceOptions), options);
2004
- }
2005
- function mutateMetaData(params) {
2006
- const { meta, inheritedStateClass, optionsWithInheritance } = params;
2007
- const { children, defaults, name } = optionsWithInheritance;
2008
- const stateName = typeof name === 'string' ? name : (name && name.getName()) || null;
2009
- // Caretaker note: we have still left the `typeof` condition in order to avoid
2010
- // creating a breaking change for projects that still use the View Engine.
2011
- if (typeof ngDevMode === 'undefined' || ngDevMode) {
2012
- StoreValidators.checkThatStateIsNamedCorrectly(stateName);
2013
- }
2014
- if (inheritedStateClass.hasOwnProperty(META_KEY)) {
2015
- const inheritedMeta = inheritedStateClass[META_KEY] || {};
2016
- meta.actions = Object.assign(Object.assign({}, meta.actions), inheritedMeta.actions);
2017
- }
2018
- meta.children = children;
2019
- meta.defaults = defaults;
2020
- meta.name = stateName;
2021
- }
2022
2082
  return (target) => {
2023
2083
  const stateClass = target;
2024
2084
  const meta = ensureStoreMetadata$1(stateClass);
2025
2085
  const inheritedStateClass = Object.getPrototypeOf(stateClass);
2026
- const optionsWithInheritance = getStateOptions(inheritedStateClass);
2086
+ const optionsWithInheritance = getStateOptions(inheritedStateClass, options);
2027
2087
  mutateMetaData({ meta, inheritedStateClass, optionsWithInheritance });
2028
- stateClass[META_OPTIONS_KEY] = optionsWithInheritance;
2088
+ stateClass[ɵMETA_OPTIONS_KEY] = optionsWithInheritance;
2029
2089
  };
2030
2090
  }
2091
+ function getStateOptions(inheritedStateClass, options) {
2092
+ const inheritanceOptions = inheritedStateClass[ɵMETA_OPTIONS_KEY] || {};
2093
+ return { ...inheritanceOptions, ...options };
2094
+ }
2095
+ function mutateMetaData(params) {
2096
+ const { meta, inheritedStateClass, optionsWithInheritance } = params;
2097
+ const { children, defaults, name } = optionsWithInheritance;
2098
+ const stateName = typeof name === 'string' ? name : (name && name.getName()) || null;
2099
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
2100
+ ensureStateNameIsValid(stateName);
2101
+ }
2102
+ if (inheritedStateClass.hasOwnProperty(ɵMETA_KEY)) {
2103
+ const inheritedMeta = inheritedStateClass[ɵMETA_KEY] || {};
2104
+ meta.actions = { ...meta.actions, ...inheritedMeta.actions };
2105
+ }
2106
+ meta.children = children;
2107
+ meta.defaults = defaults;
2108
+ meta.name = stateName;
2109
+ }
2031
2110
 
2032
2111
  const DOLLAR_CHAR_CODE = 36;
2033
2112
  function createSelectObservable(selector) {
@@ -2101,12 +2180,17 @@ function setupSelectorMetadata(originalFn, creationMetadata) {
2101
2180
  getExplicitSelectorOptions =
2102
2181
  creationMetadata.getSelectorOptions || getExplicitSelectorOptions;
2103
2182
  }
2104
- const selectorMetaDataClone = Object.assign({}, selectorMetaData);
2183
+ const selectorMetaDataClone = { ...selectorMetaData };
2105
2184
  selectorMetaData.getSelectorOptions = () => getLocalSelectorOptions(selectorMetaDataClone, getExplicitSelectorOptions());
2106
2185
  return selectorMetaData;
2107
2186
  }
2108
2187
  function getLocalSelectorOptions(selectorMetaData, explicitOptions) {
2109
- return Object.assign(Object.assign(Object.assign(Object.assign({}, (selectorOptionsMetaAccessor.getOptions(selectorMetaData.containerClass) || {})), (selectorOptionsMetaAccessor.getOptions(selectorMetaData.originalFn) || {})), (selectorMetaData.getSelectorOptions() || {})), explicitOptions);
2188
+ return {
2189
+ ...(selectorOptionsMetaAccessor.getOptions(selectorMetaData.containerClass) || {}),
2190
+ ...(selectorOptionsMetaAccessor.getOptions(selectorMetaData.originalFn) || {}),
2191
+ ...(selectorMetaData.getSelectorOptions() || {}),
2192
+ ...explicitOptions,
2193
+ };
2110
2194
  }
2111
2195
 
2112
2196
  /**
@@ -2152,7 +2236,7 @@ function createSelector(selectors, projector, creationMetadata) {
2152
2236
  function Selector(selectors) {
2153
2237
  return (target, key, descriptor) => {
2154
2238
  descriptor || (descriptor = Object.getOwnPropertyDescriptor(target, key));
2155
- const originalFn = descriptor === null || descriptor === void 0 ? void 0 : descriptor.value;
2239
+ const originalFn = descriptor?.value;
2156
2240
  // Caretaker note: we have still left the `typeof` condition in order to avoid
2157
2241
  // creating a breaking change for projects that still use the View Engine.
2158
2242
  if (typeof ngDevMode === 'undefined' || ngDevMode) {
@@ -2206,10 +2290,10 @@ class NgxsDevelopmentModule {
2206
2290
  };
2207
2291
  }
2208
2292
  }
2209
- /** @nocollapse */ NgxsDevelopmentModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsDevelopmentModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2210
- /** @nocollapse */ NgxsDevelopmentModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsDevelopmentModule });
2211
- /** @nocollapse */ NgxsDevelopmentModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsDevelopmentModule });
2212
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsDevelopmentModule, decorators: [{
2293
+ /** @nocollapse */ NgxsDevelopmentModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsDevelopmentModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2294
+ /** @nocollapse */ NgxsDevelopmentModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.4", ngImport: i0, type: NgxsDevelopmentModule });
2295
+ /** @nocollapse */ NgxsDevelopmentModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsDevelopmentModule });
2296
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsDevelopmentModule, decorators: [{
2213
2297
  type: NgModule
2214
2298
  }] });
2215
2299
 
@@ -2233,12 +2317,14 @@ function ensureValueProvided(value, context = {}) {
2233
2317
  function createModelSelector(selectorMap) {
2234
2318
  const selectorKeys = Object.keys(selectorMap);
2235
2319
  const selectors = Object.values(selectorMap);
2236
- ensureValidSelectorMap({
2237
- prefix: '[createModelSelector]',
2238
- selectorMap,
2239
- selectorKeys,
2240
- selectors,
2241
- });
2320
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
2321
+ ensureValidSelectorMap({
2322
+ prefix: '[createModelSelector]',
2323
+ selectorMap,
2324
+ selectorKeys,
2325
+ selectors
2326
+ });
2327
+ }
2242
2328
  return createSelector(selectors, (...args) => {
2243
2329
  return selectorKeys.reduce((obj, key, index) => {
2244
2330
  obj[key] = args[index];
@@ -2246,20 +2332,22 @@ function createModelSelector(selectorMap) {
2246
2332
  }, {});
2247
2333
  });
2248
2334
  }
2249
- function ensureValidSelectorMap({ prefix, selectorMap, selectorKeys, selectors, }) {
2335
+ function ensureValidSelectorMap({ prefix, selectorMap, selectorKeys, selectors }) {
2250
2336
  ensureValueProvided(selectorMap, { prefix, noun: 'selector map' });
2251
2337
  ensureValueProvided(typeof selectorMap === 'object', { prefix, noun: 'valid selector map' });
2252
2338
  ensureValueProvided(selectorKeys.length, { prefix, noun: 'non-empty selector map' });
2253
2339
  selectors.forEach((selector, index) => ensureValidSelector(selector, {
2254
2340
  prefix,
2255
- noun: `selector for the '${selectorKeys[index]}' property`,
2341
+ noun: `selector for the '${selectorKeys[index]}' property`
2256
2342
  }));
2257
2343
  }
2258
2344
 
2259
2345
  function createPickSelector(selector, keys) {
2260
- ensureValidSelector(selector, { prefix: '[createPickSelector]' });
2346
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
2347
+ ensureValidSelector(selector, { prefix: '[createPickSelector]' });
2348
+ }
2261
2349
  const validKeys = keys.filter(Boolean);
2262
- const selectors = validKeys.map((key) => createSelector([selector], (s) => s[key]));
2350
+ const selectors = validKeys.map(key => createSelector([selector], (s) => s[key]));
2263
2351
  return createSelector([...selectors], (...props) => {
2264
2352
  return validKeys.reduce((acc, key, index) => {
2265
2353
  acc[key] = props[index];
@@ -2269,21 +2357,87 @@ function createPickSelector(selector, keys) {
2269
2357
  }
2270
2358
 
2271
2359
  function createPropertySelectors(parentSelector) {
2272
- ensureValidSelector(parentSelector, {
2273
- prefix: '[createPropertySelectors]',
2274
- noun: 'parent selector',
2275
- });
2360
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
2361
+ ensureValidSelector(parentSelector, {
2362
+ prefix: '[createPropertySelectors]',
2363
+ noun: 'parent selector'
2364
+ });
2365
+ }
2276
2366
  const cache = {};
2277
2367
  return new Proxy({}, {
2278
2368
  get(_target, prop) {
2279
2369
  const selector = cache[prop] ||
2280
- createSelector([parentSelector], (s) => s === null || s === void 0 ? void 0 : s[prop]);
2370
+ createSelector([parentSelector], (s) => s?.[prop]);
2281
2371
  cache[prop] = selector;
2282
2372
  return selector;
2283
- },
2373
+ }
2284
2374
  });
2285
2375
  }
2286
2376
 
2377
+ function provideStore(states = [], ...optionsAndFeatures) {
2378
+ const features = [];
2379
+ // Options are empty by default (see `forRoot`).
2380
+ let options = {};
2381
+ if (optionsAndFeatures.length > 0) {
2382
+ if (isEnvironmentProvider(optionsAndFeatures[0])) {
2383
+ features.push(...optionsAndFeatures);
2384
+ }
2385
+ else {
2386
+ options = optionsAndFeatures[0];
2387
+ features.push(...optionsAndFeatures.slice(1));
2388
+ }
2389
+ }
2390
+ return makeEnvironmentProviders([
2391
+ ...getRootProviders(states, options),
2392
+ features,
2393
+ NGXS_ROOT_ENVIRONMENT_INITIALIZER
2394
+ ]);
2395
+ }
2396
+ function isEnvironmentProvider(target) {
2397
+ return !!target.ɵproviders;
2398
+ }
2399
+
2400
+ /**
2401
+ * This version serves as a standalone alternative to `NgxsModule.forFeature`.
2402
+ * It can be used in a similar manner to register feature states, but at the
2403
+ * `Route` providers level:
2404
+ *
2405
+ * ```ts
2406
+ * const routes: Routes = [
2407
+ * {
2408
+ * path: 'products',
2409
+ * loadComponent: async () => {...},
2410
+ * providers: [provideStates([ProductsState])]
2411
+ * }
2412
+ * ];
2413
+ * ```
2414
+ */
2415
+ function provideStates(states, ...features) {
2416
+ return makeEnvironmentProviders([
2417
+ ...getFeatureProviders(states),
2418
+ features,
2419
+ NGXS_FEATURE_ENVIRONMENT_INITIALIZER
2420
+ ]);
2421
+ }
2422
+
2423
+ /**
2424
+ * This function registers a custom global plugin for the state.
2425
+ *
2426
+ * ```ts
2427
+ * bootstrapApplication(AppComponent, {
2428
+ * providers: [
2429
+ * provideStore(
2430
+ * [CountriesState],
2431
+ * withNgxsPlugin(logoutPlugin)
2432
+ * )
2433
+ * ]
2434
+ * });
2435
+ * ```
2436
+ */
2437
+ function withNgxsPlugin(plugin) {
2438
+ return makeEnvironmentProviders([{ provide: NGXS_PLUGINS, useClass: plugin, multi: true }]);
2439
+ }
2440
+
2287
2441
  /**
2288
2442
  * The public api for consumers of @ngxs/store
2289
2443
  */
@@ -2292,5 +2446,5 @@ function createPropertySelectors(parentSelector) {
2292
2446
  * Generated bundle index. Do not edit.
2293
2447
  */
2294
2448
 
2295
- export { Action, Actions, InitState, NGXS_PLUGINS, NgxsDevelopmentModule, NgxsModule, NgxsSimpleChange, NgxsUnhandledActionsLogger, NoopNgxsExecutionStrategy, Select, Selector, SelectorOptions, State, StateStream, StateToken, Store, UpdateState, actionMatcher, createModelSelector, createPickSelector, createPropertySelectors, createSelector, ensureSelectorMetadata, ensureStoreMetadata, getActionTypeFromInstance, getSelectorMetadata, getStoreMetadata, getValue, ofAction, ofActionCanceled, ofActionCompleted, ofActionDispatched, ofActionErrored, ofActionSuccessful, setValue, NgxsFeatureModule as ɵNgxsFeatureModule, NgxsRootModule as ɵNgxsRootModule };
2296
- //# sourceMappingURL=ngxs-store.js.map
2449
+ export { Action, Actions, InitState, NGXS_PLUGINS, NgxsDevelopmentModule, NgxsModule, NgxsSimpleChange, NgxsUnhandledActionsLogger, NoopNgxsExecutionStrategy, Select, Selector, SelectorOptions, State, StateStream, StateToken, Store, UpdateState, actionMatcher, createModelSelector, createPickSelector, createPropertySelectors, createSelector, ensureSelectorMetadata, ensureStoreMetadata, getActionTypeFromInstance, getSelectorMetadata, getStoreMetadata, getValue, ofAction, ofActionCanceled, ofActionCompleted, ofActionDispatched, ofActionErrored, ofActionSuccessful, provideStates, provideStore, setValue, withNgxsPlugin, NgxsFeatureModule as ɵNgxsFeatureModule, NgxsRootModule as ɵNgxsRootModule };
2450
+ //# sourceMappingURL=ngxs-store.mjs.map