@flarehr/apollo-super-selection 1.3.54428 → 1.3.54543

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 (253) hide show
  1. package/package.json +1 -1
  2. package/dist/lib/apollo-super-selection/apollo-super-selection.css +0 -1
  3. package/dist/lib/apollo-super-selection/apollo-super-selection.esm.js +0 -1
  4. package/dist/lib/apollo-super-selection/apollo-super-selection.js +0 -130
  5. package/dist/lib/apollo-super-selection/assets/icon-exclamation.svg +0 -3
  6. package/dist/lib/apollo-super-selection/assets/icon-information-circle.svg +0 -3
  7. package/dist/lib/apollo-super-selection/index.esm.js +0 -0
  8. package/dist/lib/apollo-super-selection/p-02f24922.system.entry.js +0 -1
  9. package/dist/lib/apollo-super-selection/p-071b8545.entry.js +0 -1
  10. package/dist/lib/apollo-super-selection/p-14885f78.system.js +0 -15
  11. package/dist/lib/apollo-super-selection/p-15f0e5eb.system.js +0 -1
  12. package/dist/lib/apollo-super-selection/p-23cfdd82.entry.js +0 -1
  13. package/dist/lib/apollo-super-selection/p-29c11183.js +0 -15
  14. package/dist/lib/apollo-super-selection/p-44bec843.system.js +0 -1
  15. package/dist/lib/apollo-super-selection/p-50ea2036.system.js +0 -1
  16. package/dist/lib/apollo-super-selection/p-51aefdb1.system.entry.js +0 -1
  17. package/dist/lib/apollo-super-selection/p-51c6dd08.js +0 -1
  18. package/dist/lib/apollo-super-selection/p-6ac8791e.system.entry.js +0 -1
  19. package/dist/lib/apollo-super-selection/p-7768c4df.entry.js +0 -14
  20. package/dist/lib/apollo-super-selection/p-7a89efaf.js +0 -1
  21. package/dist/lib/apollo-super-selection/p-80178f87.system.js +0 -1
  22. package/dist/lib/apollo-super-selection/p-86e3e03f.js +0 -1
  23. package/dist/lib/apollo-super-selection/p-8e934c3c.system.entry.js +0 -69
  24. package/dist/lib/apollo-super-selection/p-9c855634.entry.js +0 -1
  25. package/dist/lib/apollo-super-selection/p-b89b68db.entry.js +0 -1
  26. package/dist/lib/apollo-super-selection/p-bdcfc026.system.js +0 -1
  27. package/dist/lib/apollo-super-selection/p-ef3afa00.system.entry.js +0 -1
  28. package/dist/lib/apollo-super-selection/p-f29066b9.system.entry.js +0 -1
  29. package/dist/lib/apollo-super-selection/p-fcb4050d.entry.js +0 -1
  30. package/dist/lib/cjs/active-router-1f555f75.js +0 -75
  31. package/dist/lib/cjs/apollo-super-selection.cjs.js +0 -22
  32. package/dist/lib/cjs/app-globals-b1125d8c.js +0 -25
  33. package/dist/lib/cjs/context-consumer.cjs.entry.js +0 -29
  34. package/dist/lib/cjs/datorama-akita-6c9cb8fb.js +0 -3641
  35. package/dist/lib/cjs/index-eb4f212f.js +0 -1766
  36. package/dist/lib/cjs/index.cjs.js +0 -2
  37. package/dist/lib/cjs/loader.cjs.js +0 -24
  38. package/dist/lib/cjs/sss-button_31.cjs.entry.js +0 -17977
  39. package/dist/lib/cjs/stencil-async-content.cjs.entry.js +0 -32
  40. package/dist/lib/cjs/stencil-route-title.cjs.entry.js +0 -32
  41. package/dist/lib/cjs/stencil-router-prompt.cjs.entry.js +0 -59
  42. package/dist/lib/cjs/stencil-router-redirect.cjs.entry.js +0 -32
  43. package/dist/lib/collection/apollo-super-selection.css +0 -1
  44. package/dist/lib/collection/collection-manifest.json +0 -95
  45. package/dist/lib/collection/components/app-host/loading-page.js +0 -9
  46. package/dist/lib/collection/components/app-host/services/app-configuration.query.js +0 -18
  47. package/dist/lib/collection/components/app-host/services/app-configuration.service.js +0 -25
  48. package/dist/lib/collection/components/app-host/services/app-parameters.query.js +0 -13
  49. package/dist/lib/collection/components/app-host/services/app-parameters.service.js +0 -14
  50. package/dist/lib/collection/components/app-host/services/appinsights.service.js +0 -46
  51. package/dist/lib/collection/components/app-host/services/authentication.query.js +0 -21
  52. package/dist/lib/collection/components/app-host/services/authentication.service.js +0 -50
  53. package/dist/lib/collection/components/app-host/services/interop/host-interop.service.js +0 -31
  54. package/dist/lib/collection/components/app-host/services/interop/iframe-interop.service.js +0 -30
  55. package/dist/lib/collection/components/app-host/services/interop/react-native-interop.service.js +0 -20
  56. package/dist/lib/collection/components/app-host/services/interop.query.js +0 -26
  57. package/dist/lib/collection/components/app-host/services/session.store.js +0 -38
  58. package/dist/lib/collection/components/app-host/super-selection-app-host.css +0 -24
  59. package/dist/lib/collection/components/app-host/super-selection-app-host.js +0 -87
  60. package/dist/lib/collection/components/external-loading-page/external-loading-page.js +0 -29
  61. package/dist/lib/collection/components/super-campaign/super-campaign-types.js +0 -6
  62. package/dist/lib/collection/components/super-campaign/super-campaign.js +0 -361
  63. package/dist/lib/collection/components/super-selection-app/api/api-client.js +0 -14
  64. package/dist/lib/collection/components/super-selection-app/api/event-tracking.api.js +0 -9
  65. package/dist/lib/collection/components/super-selection-app/api/super-campaign-errors-api.js +0 -9
  66. package/dist/lib/collection/components/super-selection-app/api/super-campaign-errors.api.dtos.js +0 -1
  67. package/dist/lib/collection/components/super-selection-app/api/super-selection-events.model.js +0 -16
  68. package/dist/lib/collection/components/super-selection-app/api/super-selection.api.dto.js +0 -179
  69. package/dist/lib/collection/components/super-selection-app/api/super-selection.api.js +0 -69
  70. package/dist/lib/collection/components/super-selection-app/app-state-pages/success.js +0 -36
  71. package/dist/lib/collection/components/super-selection-app/assets/icon-exclamation.svg +0 -3
  72. package/dist/lib/collection/components/super-selection-app/assets/icon-information-circle.svg +0 -3
  73. package/dist/lib/collection/components/super-selection-app/existing-choice/existing-choice.js +0 -163
  74. package/dist/lib/collection/components/super-selection-app/footer-section/footer-section.js +0 -39
  75. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/api/custom-fund-choice.api.dto.js +0 -1
  76. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/api/custom-fund-choice.api.js +0 -50
  77. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/custom-fund.js +0 -86
  78. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/custom-fund.store.js +0 -53
  79. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/default-fund/default-fund.js +0 -114
  80. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/member-name-input.js +0 -162
  81. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/my-own-fund/my-own-fund-inputs.js +0 -143
  82. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/my-own-fund/my-own-fund.js +0 -118
  83. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/self-managed-fund/abn-validation.js +0 -11
  84. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/self-managed-fund/bankBsbNumbers.js +0 -111
  85. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/self-managed-fund/self-managed-fund-inputs.js +0 -253
  86. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/self-managed-fund/self-managed-fund.form.js +0 -1
  87. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/self-managed-fund/self-managed-fund.js +0 -121
  88. package/dist/lib/collection/components/super-selection-app/funds/promoted-fund/api/promoted-fund-choice.api.dto.js +0 -1
  89. package/dist/lib/collection/components/super-selection-app/funds/promoted-fund/api/promoted-fund-choice.api.js +0 -31
  90. package/dist/lib/collection/components/super-selection-app/funds/slate-super/api/slate-choice.api.dto.js +0 -1
  91. package/dist/lib/collection/components/super-selection-app/funds/slate-super/api/slate-choice.api.js +0 -13
  92. package/dist/lib/collection/components/super-selection-app/funds/slate-super/api/slate.js +0 -4
  93. package/dist/lib/collection/components/super-selection-app/header-section/header-section.js +0 -53
  94. package/dist/lib/collection/components/super-selection-app/misc/button.js +0 -195
  95. package/dist/lib/collection/components/super-selection-app/misc/dropdown-async.css +0 -7
  96. package/dist/lib/collection/components/super-selection-app/misc/dropdown-async.js +0 -390
  97. package/dist/lib/collection/components/super-selection-app/misc/loading-indicator.js +0 -52
  98. package/dist/lib/collection/components/super-selection-app/prefill-fund/prefill-common.js +0 -22
  99. package/dist/lib/collection/components/super-selection-app/prefill-fund/prefill-display-field.js +0 -42
  100. package/dist/lib/collection/components/super-selection-app/prefill-fund/prefill-error-box.js +0 -66
  101. package/dist/lib/collection/components/super-selection-app/prefill-fund/prefill-invalid-my-own-fund.js +0 -121
  102. package/dist/lib/collection/components/super-selection-app/prefill-fund/prefill-invalid-smsf.js +0 -145
  103. package/dist/lib/collection/components/super-selection-app/prefill-fund/prefill-my-own-fund.js +0 -223
  104. package/dist/lib/collection/components/super-selection-app/prefill-fund/prefill-smsf.js +0 -398
  105. package/dist/lib/collection/components/super-selection-app/prefill-fund/prefill-types.js +0 -288
  106. package/dist/lib/collection/components/super-selection-app/prefill-fund/prefill-warning-box.js +0 -37
  107. package/dist/lib/collection/components/super-selection-app/prefill-fund/prefill.js +0 -81
  108. package/dist/lib/collection/components/super-selection-app/services/australian-fund-lookup.service.js +0 -15
  109. package/dist/lib/collection/components/super-selection-app/services/event-tracking.service.js +0 -97
  110. package/dist/lib/collection/components/super-selection-app/services/existing-super-choice-info.service.js +0 -134
  111. package/dist/lib/collection/components/super-selection-app/services/misc.service.js +0 -7
  112. package/dist/lib/collection/components/super-selection-app/services/navigation.service.js +0 -31
  113. package/dist/lib/collection/components/super-selection-app/services/super-selection-app.routes.js +0 -32
  114. package/dist/lib/collection/components/super-selection-app/services/super-selection-app.service.js +0 -146
  115. package/dist/lib/collection/components/super-selection-app/services/super-selection.store.js +0 -42
  116. package/dist/lib/collection/components/super-selection-app/standard-choice/standard-choice-form.js +0 -155
  117. package/dist/lib/collection/components/super-selection-app/standard-choice/standard-choice-form.store.js +0 -11
  118. package/dist/lib/collection/components/super-selection-app/super-selection-app.css +0 -27
  119. package/dist/lib/collection/components/super-selection-app/super-selection-app.js +0 -291
  120. package/dist/lib/collection/global/init-host.js +0 -25
  121. package/dist/lib/collection/global/main.dev.js +0 -29
  122. package/dist/lib/collection/global/main.js +0 -11
  123. package/dist/lib/collection/global/stencil-router-workaround.js +0 -12
  124. package/dist/lib/collection/index.js +0 -2
  125. package/dist/lib/collection/utils/config.js +0 -2
  126. package/dist/lib/collection/utils/gtm.js +0 -5
  127. package/dist/lib/collection/utils/iframe.js +0 -33
  128. package/dist/lib/collection/utils/index.js +0 -11
  129. package/dist/lib/collection/utils/lazy.js +0 -29
  130. package/dist/lib/collection/utils/storage.js +0 -5
  131. package/dist/lib/esm/active-router-5e40c0f8.js +0 -73
  132. package/dist/lib/esm/apollo-super-selection.js +0 -20
  133. package/dist/lib/esm/app-globals-c1f89805.js +0 -23
  134. package/dist/lib/esm/context-consumer.entry.js +0 -25
  135. package/dist/lib/esm/datorama-akita-127aea91.js +0 -3624
  136. package/dist/lib/esm/index-189b2180.js +0 -1732
  137. package/dist/lib/esm/index.js +0 -1
  138. package/dist/lib/esm/loader.js +0 -20
  139. package/dist/lib/esm/polyfills/core-js.js +0 -11
  140. package/dist/lib/esm/polyfills/css-shim.js +0 -1
  141. package/dist/lib/esm/polyfills/dom.js +0 -79
  142. package/dist/lib/esm/polyfills/es5-html-element.js +0 -1
  143. package/dist/lib/esm/polyfills/index.js +0 -34
  144. package/dist/lib/esm/polyfills/system.js +0 -6
  145. package/dist/lib/esm/sss-button_31.entry.js +0 -17923
  146. package/dist/lib/esm/stencil-async-content.entry.js +0 -28
  147. package/dist/lib/esm/stencil-route-title.entry.js +0 -28
  148. package/dist/lib/esm/stencil-router-prompt.entry.js +0 -55
  149. package/dist/lib/esm/stencil-router-redirect.entry.js +0 -28
  150. package/dist/lib/esm-es5/active-router-5e40c0f8.js +0 -1
  151. package/dist/lib/esm-es5/apollo-super-selection.js +0 -1
  152. package/dist/lib/esm-es5/app-globals-c1f89805.js +0 -1
  153. package/dist/lib/esm-es5/context-consumer.entry.js +0 -1
  154. package/dist/lib/esm-es5/datorama-akita-127aea91.js +0 -15
  155. package/dist/lib/esm-es5/index-189b2180.js +0 -1
  156. package/dist/lib/esm-es5/index.js +0 -0
  157. package/dist/lib/esm-es5/loader.js +0 -1
  158. package/dist/lib/esm-es5/sss-button_31.entry.js +0 -69
  159. package/dist/lib/esm-es5/stencil-async-content.entry.js +0 -1
  160. package/dist/lib/esm-es5/stencil-route-title.entry.js +0 -1
  161. package/dist/lib/esm-es5/stencil-router-prompt.entry.js +0 -1
  162. package/dist/lib/esm-es5/stencil-router-redirect.entry.js +0 -1
  163. package/dist/lib/index.cjs.js +0 -1
  164. package/dist/lib/index.js +0 -1
  165. package/dist/lib/loader/cdn.js +0 -3
  166. package/dist/lib/loader/index.cjs.js +0 -3
  167. package/dist/lib/loader/index.d.ts +0 -13
  168. package/dist/lib/loader/index.es2017.js +0 -3
  169. package/dist/lib/loader/index.js +0 -4
  170. package/dist/lib/loader/package.json +0 -10
  171. package/dist/lib/node_modules/@stencil/router/dist/collection/components/route/route.css +0 -3
  172. package/dist/lib/types/components/app-host/loading-page.d.ts +0 -3
  173. package/dist/lib/types/components/app-host/services/app-configuration.query.d.ts +0 -11
  174. package/dist/lib/types/components/app-host/services/app-configuration.service.d.ts +0 -9
  175. package/dist/lib/types/components/app-host/services/app-parameters.query.d.ts +0 -10
  176. package/dist/lib/types/components/app-host/services/app-parameters.service.d.ts +0 -6
  177. package/dist/lib/types/components/app-host/services/appinsights.service.d.ts +0 -15
  178. package/dist/lib/types/components/app-host/services/authentication.query.d.ts +0 -13
  179. package/dist/lib/types/components/app-host/services/authentication.service.d.ts +0 -9
  180. package/dist/lib/types/components/app-host/services/interop/host-interop.service.d.ts +0 -7
  181. package/dist/lib/types/components/app-host/services/interop/iframe-interop.service.d.ts +0 -5
  182. package/dist/lib/types/components/app-host/services/interop/react-native-interop.service.d.ts +0 -7
  183. package/dist/lib/types/components/app-host/services/interop.query.d.ts +0 -11
  184. package/dist/lib/types/components/app-host/services/session.store.d.ts +0 -31
  185. package/dist/lib/types/components/app-host/super-selection-app-host.d.ts +0 -15
  186. package/dist/lib/types/components/super-campaign/super-campaign-types.d.ts +0 -96
  187. package/dist/lib/types/components/super-campaign/super-campaign.d.ts +0 -37
  188. package/dist/lib/types/components/super-selection-app/api/api-client.d.ts +0 -2
  189. package/dist/lib/types/components/super-selection-app/api/event-tracking.api.d.ts +0 -6
  190. package/dist/lib/types/components/super-selection-app/api/super-campaign-errors-api.d.ts +0 -6
  191. package/dist/lib/types/components/super-selection-app/api/super-campaign-errors.api.dtos.d.ts +0 -7
  192. package/dist/lib/types/components/super-selection-app/api/super-selection-events.model.d.ts +0 -149
  193. package/dist/lib/types/components/super-selection-app/api/super-selection.api.d.ts +0 -16
  194. package/dist/lib/types/components/super-selection-app/api/super-selection.api.dto.d.ts +0 -233
  195. package/dist/lib/types/components/super-selection-app/app-state-pages/success.d.ts +0 -7
  196. package/dist/lib/types/components/super-selection-app/existing-choice/existing-choice.d.ts +0 -12
  197. package/dist/lib/types/components/super-selection-app/footer-section/footer-section.d.ts +0 -5
  198. package/dist/lib/types/components/super-selection-app/funds/custom-fund/api/custom-fund-choice.api.d.ts +0 -10
  199. package/dist/lib/types/components/super-selection-app/funds/custom-fund/api/custom-fund-choice.api.dto.d.ts +0 -43
  200. package/dist/lib/types/components/super-selection-app/funds/custom-fund/custom-fund.d.ts +0 -9
  201. package/dist/lib/types/components/super-selection-app/funds/custom-fund/custom-fund.store.d.ts +0 -30
  202. package/dist/lib/types/components/super-selection-app/funds/custom-fund/default-fund/default-fund.d.ts +0 -13
  203. package/dist/lib/types/components/super-selection-app/funds/custom-fund/member-name-input.d.ts +0 -14
  204. package/dist/lib/types/components/super-selection-app/funds/custom-fund/my-own-fund/my-own-fund-inputs.d.ts +0 -16
  205. package/dist/lib/types/components/super-selection-app/funds/custom-fund/my-own-fund/my-own-fund.d.ts +0 -13
  206. package/dist/lib/types/components/super-selection-app/funds/custom-fund/self-managed-fund/abn-validation.d.ts +0 -1
  207. package/dist/lib/types/components/super-selection-app/funds/custom-fund/self-managed-fund/bankBsbNumbers.d.ts +0 -112
  208. package/dist/lib/types/components/super-selection-app/funds/custom-fund/self-managed-fund/self-managed-fund-inputs.d.ts +0 -29
  209. package/dist/lib/types/components/super-selection-app/funds/custom-fund/self-managed-fund/self-managed-fund.d.ts +0 -14
  210. package/dist/lib/types/components/super-selection-app/funds/custom-fund/self-managed-fund/self-managed-fund.form.d.ts +0 -15
  211. package/dist/lib/types/components/super-selection-app/funds/promoted-fund/api/promoted-fund-choice.api.d.ts +0 -8
  212. package/dist/lib/types/components/super-selection-app/funds/promoted-fund/api/promoted-fund-choice.api.dto.d.ts +0 -25
  213. package/dist/lib/types/components/super-selection-app/funds/slate-super/api/slate-choice.api.d.ts +0 -6
  214. package/dist/lib/types/components/super-selection-app/funds/slate-super/api/slate-choice.api.dto.d.ts +0 -8
  215. package/dist/lib/types/components/super-selection-app/funds/slate-super/api/slate.d.ts +0 -4
  216. package/dist/lib/types/components/super-selection-app/header-section/header-section.d.ts +0 -4
  217. package/dist/lib/types/components/super-selection-app/misc/button.d.ts +0 -14
  218. package/dist/lib/types/components/super-selection-app/misc/dropdown-async.d.ts +0 -52
  219. package/dist/lib/types/components/super-selection-app/misc/loading-indicator.d.ts +0 -5
  220. package/dist/lib/types/components/super-selection-app/prefill-fund/prefill-common.d.ts +0 -9
  221. package/dist/lib/types/components/super-selection-app/prefill-fund/prefill-display-field.d.ts +0 -5
  222. package/dist/lib/types/components/super-selection-app/prefill-fund/prefill-error-box.d.ts +0 -5
  223. package/dist/lib/types/components/super-selection-app/prefill-fund/prefill-invalid-my-own-fund.d.ts +0 -18
  224. package/dist/lib/types/components/super-selection-app/prefill-fund/prefill-invalid-smsf.d.ts +0 -28
  225. package/dist/lib/types/components/super-selection-app/prefill-fund/prefill-my-own-fund.d.ts +0 -30
  226. package/dist/lib/types/components/super-selection-app/prefill-fund/prefill-smsf.d.ts +0 -52
  227. package/dist/lib/types/components/super-selection-app/prefill-fund/prefill-types.d.ts +0 -95
  228. package/dist/lib/types/components/super-selection-app/prefill-fund/prefill-warning-box.d.ts +0 -4
  229. package/dist/lib/types/components/super-selection-app/prefill-fund/prefill.d.ts +0 -14
  230. package/dist/lib/types/components/super-selection-app/services/australian-fund-lookup.service.d.ts +0 -8
  231. package/dist/lib/types/components/super-selection-app/services/event-tracking.service.d.ts +0 -21
  232. package/dist/lib/types/components/super-selection-app/services/existing-super-choice-info.service.d.ts +0 -75
  233. package/dist/lib/types/components/super-selection-app/services/misc.service.d.ts +0 -6
  234. package/dist/lib/types/components/super-selection-app/services/navigation.service.d.ts +0 -17
  235. package/dist/lib/types/components/super-selection-app/services/super-selection-app.routes.d.ts +0 -16
  236. package/dist/lib/types/components/super-selection-app/services/super-selection-app.service.d.ts +0 -38
  237. package/dist/lib/types/components/super-selection-app/services/super-selection.store.d.ts +0 -34
  238. package/dist/lib/types/components/super-selection-app/standard-choice/standard-choice-form.d.ts +0 -16
  239. package/dist/lib/types/components/super-selection-app/standard-choice/standard-choice-form.store.d.ts +0 -42
  240. package/dist/lib/types/components/super-selection-app/super-selection-app.d.ts +0 -27
  241. package/dist/lib/types/components.d.ts +0 -503
  242. package/dist/lib/types/global/init-host.d.ts +0 -1
  243. package/dist/lib/types/global/main.d.ts +0 -1
  244. package/dist/lib/types/global/main.dev.d.ts +0 -1
  245. package/dist/lib/types/global/stencil-router-workaround.d.ts +0 -1
  246. package/dist/lib/types/index.d.ts +0 -2
  247. package/dist/lib/types/stencil-public-runtime.d.ts +0 -1555
  248. package/dist/lib/types/utils/config.d.ts +0 -2
  249. package/dist/lib/types/utils/gtm.d.ts +0 -7
  250. package/dist/lib/types/utils/iframe.d.ts +0 -13
  251. package/dist/lib/types/utils/index.d.ts +0 -4
  252. package/dist/lib/types/utils/lazy.d.ts +0 -12
  253. package/dist/lib/types/utils/storage.d.ts +0 -4
@@ -1,3641 +0,0 @@
1
- 'use strict';
2
-
3
- /*! *****************************************************************************
4
- Copyright (c) Microsoft Corporation.
5
-
6
- Permission to use, copy, modify, and/or distribute this software for any
7
- purpose with or without fee is hereby granted.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
- PERFORMANCE OF THIS SOFTWARE.
16
- ***************************************************************************** */
17
-
18
- function __rest(s, e) {
19
- var t = {};
20
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
21
- t[p] = s[p];
22
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
23
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
24
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
25
- t[p[i]] = s[p[i]];
26
- }
27
- return t;
28
- }
29
-
30
- function __decorate(decorators, target, key, desc) {
31
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
32
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
33
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
34
- return c > 3 && r && Object.defineProperty(target, key, r), r;
35
- }
36
-
37
- function __metadata(metadataKey, metadataValue) {
38
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
39
- }
40
-
41
- function isFunction(x) {
42
- return typeof x === 'function';
43
- }
44
-
45
- let _enable_super_gross_mode_that_will_cause_bad_things = false;
46
- const config = {
47
- Promise: undefined,
48
- set useDeprecatedSynchronousErrorHandling(value) {
49
- if (value) {
50
- const error = new Error();
51
- console.warn('DEPRECATED! RxJS was set to use deprecated synchronous error handling behavior by code at: \n' + error.stack);
52
- }
53
- else if (_enable_super_gross_mode_that_will_cause_bad_things) {
54
- console.log('RxJS: Back to a better error behavior. Thank you. <3');
55
- }
56
- _enable_super_gross_mode_that_will_cause_bad_things = value;
57
- },
58
- get useDeprecatedSynchronousErrorHandling() {
59
- return _enable_super_gross_mode_that_will_cause_bad_things;
60
- },
61
- };
62
-
63
- function hostReportError(err) {
64
- setTimeout(() => { throw err; }, 0);
65
- }
66
-
67
- const empty = {
68
- closed: true,
69
- next(value) { },
70
- error(err) {
71
- if (config.useDeprecatedSynchronousErrorHandling) {
72
- throw err;
73
- }
74
- else {
75
- hostReportError(err);
76
- }
77
- },
78
- complete() { }
79
- };
80
-
81
- const isArray = (() => Array.isArray || ((x) => x && typeof x.length === 'number'))();
82
-
83
- function isObject(x) {
84
- return x !== null && typeof x === 'object';
85
- }
86
-
87
- const UnsubscriptionErrorImpl = (() => {
88
- function UnsubscriptionErrorImpl(errors) {
89
- Error.call(this);
90
- this.message = errors ?
91
- `${errors.length} errors occurred during unsubscription:
92
- ${errors.map((err, i) => `${i + 1}) ${err.toString()}`).join('\n ')}` : '';
93
- this.name = 'UnsubscriptionError';
94
- this.errors = errors;
95
- return this;
96
- }
97
- UnsubscriptionErrorImpl.prototype = Object.create(Error.prototype);
98
- return UnsubscriptionErrorImpl;
99
- })();
100
- const UnsubscriptionError = UnsubscriptionErrorImpl;
101
-
102
- class Subscription {
103
- constructor(unsubscribe) {
104
- this.closed = false;
105
- this._parentOrParents = null;
106
- this._subscriptions = null;
107
- if (unsubscribe) {
108
- this._ctorUnsubscribe = true;
109
- this._unsubscribe = unsubscribe;
110
- }
111
- }
112
- unsubscribe() {
113
- let errors;
114
- if (this.closed) {
115
- return;
116
- }
117
- let { _parentOrParents, _ctorUnsubscribe, _unsubscribe, _subscriptions } = this;
118
- this.closed = true;
119
- this._parentOrParents = null;
120
- this._subscriptions = null;
121
- if (_parentOrParents instanceof Subscription) {
122
- _parentOrParents.remove(this);
123
- }
124
- else if (_parentOrParents !== null) {
125
- for (let index = 0; index < _parentOrParents.length; ++index) {
126
- const parent = _parentOrParents[index];
127
- parent.remove(this);
128
- }
129
- }
130
- if (isFunction(_unsubscribe)) {
131
- if (_ctorUnsubscribe) {
132
- this._unsubscribe = undefined;
133
- }
134
- try {
135
- _unsubscribe.call(this);
136
- }
137
- catch (e) {
138
- errors = e instanceof UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [e];
139
- }
140
- }
141
- if (isArray(_subscriptions)) {
142
- let index = -1;
143
- let len = _subscriptions.length;
144
- while (++index < len) {
145
- const sub = _subscriptions[index];
146
- if (isObject(sub)) {
147
- try {
148
- sub.unsubscribe();
149
- }
150
- catch (e) {
151
- errors = errors || [];
152
- if (e instanceof UnsubscriptionError) {
153
- errors = errors.concat(flattenUnsubscriptionErrors(e.errors));
154
- }
155
- else {
156
- errors.push(e);
157
- }
158
- }
159
- }
160
- }
161
- }
162
- if (errors) {
163
- throw new UnsubscriptionError(errors);
164
- }
165
- }
166
- add(teardown) {
167
- let subscription = teardown;
168
- if (!teardown) {
169
- return Subscription.EMPTY;
170
- }
171
- switch (typeof teardown) {
172
- case 'function':
173
- subscription = new Subscription(teardown);
174
- case 'object':
175
- if (subscription === this || subscription.closed || typeof subscription.unsubscribe !== 'function') {
176
- return subscription;
177
- }
178
- else if (this.closed) {
179
- subscription.unsubscribe();
180
- return subscription;
181
- }
182
- else if (!(subscription instanceof Subscription)) {
183
- const tmp = subscription;
184
- subscription = new Subscription();
185
- subscription._subscriptions = [tmp];
186
- }
187
- break;
188
- default: {
189
- throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.');
190
- }
191
- }
192
- let { _parentOrParents } = subscription;
193
- if (_parentOrParents === null) {
194
- subscription._parentOrParents = this;
195
- }
196
- else if (_parentOrParents instanceof Subscription) {
197
- if (_parentOrParents === this) {
198
- return subscription;
199
- }
200
- subscription._parentOrParents = [_parentOrParents, this];
201
- }
202
- else if (_parentOrParents.indexOf(this) === -1) {
203
- _parentOrParents.push(this);
204
- }
205
- else {
206
- return subscription;
207
- }
208
- const subscriptions = this._subscriptions;
209
- if (subscriptions === null) {
210
- this._subscriptions = [subscription];
211
- }
212
- else {
213
- subscriptions.push(subscription);
214
- }
215
- return subscription;
216
- }
217
- remove(subscription) {
218
- const subscriptions = this._subscriptions;
219
- if (subscriptions) {
220
- const subscriptionIndex = subscriptions.indexOf(subscription);
221
- if (subscriptionIndex !== -1) {
222
- subscriptions.splice(subscriptionIndex, 1);
223
- }
224
- }
225
- }
226
- }
227
- Subscription.EMPTY = (function (empty) {
228
- empty.closed = true;
229
- return empty;
230
- }(new Subscription()));
231
- function flattenUnsubscriptionErrors(errors) {
232
- return errors.reduce((errs, err) => errs.concat((err instanceof UnsubscriptionError) ? err.errors : err), []);
233
- }
234
-
235
- const rxSubscriber = (() => typeof Symbol === 'function'
236
- ? Symbol('rxSubscriber')
237
- : '@@rxSubscriber_' + Math.random())();
238
-
239
- class Subscriber extends Subscription {
240
- constructor(destinationOrNext, error, complete) {
241
- super();
242
- this.syncErrorValue = null;
243
- this.syncErrorThrown = false;
244
- this.syncErrorThrowable = false;
245
- this.isStopped = false;
246
- switch (arguments.length) {
247
- case 0:
248
- this.destination = empty;
249
- break;
250
- case 1:
251
- if (!destinationOrNext) {
252
- this.destination = empty;
253
- break;
254
- }
255
- if (typeof destinationOrNext === 'object') {
256
- if (destinationOrNext instanceof Subscriber) {
257
- this.syncErrorThrowable = destinationOrNext.syncErrorThrowable;
258
- this.destination = destinationOrNext;
259
- destinationOrNext.add(this);
260
- }
261
- else {
262
- this.syncErrorThrowable = true;
263
- this.destination = new SafeSubscriber(this, destinationOrNext);
264
- }
265
- break;
266
- }
267
- default:
268
- this.syncErrorThrowable = true;
269
- this.destination = new SafeSubscriber(this, destinationOrNext, error, complete);
270
- break;
271
- }
272
- }
273
- [rxSubscriber]() { return this; }
274
- static create(next, error, complete) {
275
- const subscriber = new Subscriber(next, error, complete);
276
- subscriber.syncErrorThrowable = false;
277
- return subscriber;
278
- }
279
- next(value) {
280
- if (!this.isStopped) {
281
- this._next(value);
282
- }
283
- }
284
- error(err) {
285
- if (!this.isStopped) {
286
- this.isStopped = true;
287
- this._error(err);
288
- }
289
- }
290
- complete() {
291
- if (!this.isStopped) {
292
- this.isStopped = true;
293
- this._complete();
294
- }
295
- }
296
- unsubscribe() {
297
- if (this.closed) {
298
- return;
299
- }
300
- this.isStopped = true;
301
- super.unsubscribe();
302
- }
303
- _next(value) {
304
- this.destination.next(value);
305
- }
306
- _error(err) {
307
- this.destination.error(err);
308
- this.unsubscribe();
309
- }
310
- _complete() {
311
- this.destination.complete();
312
- this.unsubscribe();
313
- }
314
- _unsubscribeAndRecycle() {
315
- const { _parentOrParents } = this;
316
- this._parentOrParents = null;
317
- this.unsubscribe();
318
- this.closed = false;
319
- this.isStopped = false;
320
- this._parentOrParents = _parentOrParents;
321
- return this;
322
- }
323
- }
324
- class SafeSubscriber extends Subscriber {
325
- constructor(_parentSubscriber, observerOrNext, error, complete) {
326
- super();
327
- this._parentSubscriber = _parentSubscriber;
328
- let next;
329
- let context = this;
330
- if (isFunction(observerOrNext)) {
331
- next = observerOrNext;
332
- }
333
- else if (observerOrNext) {
334
- next = observerOrNext.next;
335
- error = observerOrNext.error;
336
- complete = observerOrNext.complete;
337
- if (observerOrNext !== empty) {
338
- context = Object.create(observerOrNext);
339
- if (isFunction(context.unsubscribe)) {
340
- this.add(context.unsubscribe.bind(context));
341
- }
342
- context.unsubscribe = this.unsubscribe.bind(this);
343
- }
344
- }
345
- this._context = context;
346
- this._next = next;
347
- this._error = error;
348
- this._complete = complete;
349
- }
350
- next(value) {
351
- if (!this.isStopped && this._next) {
352
- const { _parentSubscriber } = this;
353
- if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
354
- this.__tryOrUnsub(this._next, value);
355
- }
356
- else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) {
357
- this.unsubscribe();
358
- }
359
- }
360
- }
361
- error(err) {
362
- if (!this.isStopped) {
363
- const { _parentSubscriber } = this;
364
- const { useDeprecatedSynchronousErrorHandling } = config;
365
- if (this._error) {
366
- if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
367
- this.__tryOrUnsub(this._error, err);
368
- this.unsubscribe();
369
- }
370
- else {
371
- this.__tryOrSetError(_parentSubscriber, this._error, err);
372
- this.unsubscribe();
373
- }
374
- }
375
- else if (!_parentSubscriber.syncErrorThrowable) {
376
- this.unsubscribe();
377
- if (useDeprecatedSynchronousErrorHandling) {
378
- throw err;
379
- }
380
- hostReportError(err);
381
- }
382
- else {
383
- if (useDeprecatedSynchronousErrorHandling) {
384
- _parentSubscriber.syncErrorValue = err;
385
- _parentSubscriber.syncErrorThrown = true;
386
- }
387
- else {
388
- hostReportError(err);
389
- }
390
- this.unsubscribe();
391
- }
392
- }
393
- }
394
- complete() {
395
- if (!this.isStopped) {
396
- const { _parentSubscriber } = this;
397
- if (this._complete) {
398
- const wrappedComplete = () => this._complete.call(this._context);
399
- if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
400
- this.__tryOrUnsub(wrappedComplete);
401
- this.unsubscribe();
402
- }
403
- else {
404
- this.__tryOrSetError(_parentSubscriber, wrappedComplete);
405
- this.unsubscribe();
406
- }
407
- }
408
- else {
409
- this.unsubscribe();
410
- }
411
- }
412
- }
413
- __tryOrUnsub(fn, value) {
414
- try {
415
- fn.call(this._context, value);
416
- }
417
- catch (err) {
418
- this.unsubscribe();
419
- if (config.useDeprecatedSynchronousErrorHandling) {
420
- throw err;
421
- }
422
- else {
423
- hostReportError(err);
424
- }
425
- }
426
- }
427
- __tryOrSetError(parent, fn, value) {
428
- if (!config.useDeprecatedSynchronousErrorHandling) {
429
- throw new Error('bad call');
430
- }
431
- try {
432
- fn.call(this._context, value);
433
- }
434
- catch (err) {
435
- if (config.useDeprecatedSynchronousErrorHandling) {
436
- parent.syncErrorValue = err;
437
- parent.syncErrorThrown = true;
438
- return true;
439
- }
440
- else {
441
- hostReportError(err);
442
- return true;
443
- }
444
- }
445
- return false;
446
- }
447
- _unsubscribe() {
448
- const { _parentSubscriber } = this;
449
- this._context = null;
450
- this._parentSubscriber = null;
451
- _parentSubscriber.unsubscribe();
452
- }
453
- }
454
-
455
- function canReportError(observer) {
456
- while (observer) {
457
- const { closed, destination, isStopped } = observer;
458
- if (closed || isStopped) {
459
- return false;
460
- }
461
- else if (destination && destination instanceof Subscriber) {
462
- observer = destination;
463
- }
464
- else {
465
- observer = null;
466
- }
467
- }
468
- return true;
469
- }
470
-
471
- function toSubscriber(nextOrObserver, error, complete) {
472
- if (nextOrObserver) {
473
- if (nextOrObserver instanceof Subscriber) {
474
- return nextOrObserver;
475
- }
476
- if (nextOrObserver[rxSubscriber]) {
477
- return nextOrObserver[rxSubscriber]();
478
- }
479
- }
480
- if (!nextOrObserver && !error && !complete) {
481
- return new Subscriber(empty);
482
- }
483
- return new Subscriber(nextOrObserver, error, complete);
484
- }
485
-
486
- const observable = (() => typeof Symbol === 'function' && Symbol.observable || '@@observable')();
487
-
488
- function identity(x) {
489
- return x;
490
- }
491
-
492
- function pipeFromArray(fns) {
493
- if (fns.length === 0) {
494
- return identity;
495
- }
496
- if (fns.length === 1) {
497
- return fns[0];
498
- }
499
- return function piped(input) {
500
- return fns.reduce((prev, fn) => fn(prev), input);
501
- };
502
- }
503
-
504
- class Observable {
505
- constructor(subscribe) {
506
- this._isScalar = false;
507
- if (subscribe) {
508
- this._subscribe = subscribe;
509
- }
510
- }
511
- lift(operator) {
512
- const observable = new Observable();
513
- observable.source = this;
514
- observable.operator = operator;
515
- return observable;
516
- }
517
- subscribe(observerOrNext, error, complete) {
518
- const { operator } = this;
519
- const sink = toSubscriber(observerOrNext, error, complete);
520
- if (operator) {
521
- sink.add(operator.call(sink, this.source));
522
- }
523
- else {
524
- sink.add(this.source || (config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ?
525
- this._subscribe(sink) :
526
- this._trySubscribe(sink));
527
- }
528
- if (config.useDeprecatedSynchronousErrorHandling) {
529
- if (sink.syncErrorThrowable) {
530
- sink.syncErrorThrowable = false;
531
- if (sink.syncErrorThrown) {
532
- throw sink.syncErrorValue;
533
- }
534
- }
535
- }
536
- return sink;
537
- }
538
- _trySubscribe(sink) {
539
- try {
540
- return this._subscribe(sink);
541
- }
542
- catch (err) {
543
- if (config.useDeprecatedSynchronousErrorHandling) {
544
- sink.syncErrorThrown = true;
545
- sink.syncErrorValue = err;
546
- }
547
- if (canReportError(sink)) {
548
- sink.error(err);
549
- }
550
- else {
551
- console.warn(err);
552
- }
553
- }
554
- }
555
- forEach(next, promiseCtor) {
556
- promiseCtor = getPromiseCtor(promiseCtor);
557
- return new promiseCtor((resolve, reject) => {
558
- let subscription;
559
- subscription = this.subscribe((value) => {
560
- try {
561
- next(value);
562
- }
563
- catch (err) {
564
- reject(err);
565
- if (subscription) {
566
- subscription.unsubscribe();
567
- }
568
- }
569
- }, reject, resolve);
570
- });
571
- }
572
- _subscribe(subscriber) {
573
- const { source } = this;
574
- return source && source.subscribe(subscriber);
575
- }
576
- [observable]() {
577
- return this;
578
- }
579
- pipe(...operations) {
580
- if (operations.length === 0) {
581
- return this;
582
- }
583
- return pipeFromArray(operations)(this);
584
- }
585
- toPromise(promiseCtor) {
586
- promiseCtor = getPromiseCtor(promiseCtor);
587
- return new promiseCtor((resolve, reject) => {
588
- let value;
589
- this.subscribe((x) => value = x, (err) => reject(err), () => resolve(value));
590
- });
591
- }
592
- }
593
- Observable.create = (subscribe) => {
594
- return new Observable(subscribe);
595
- };
596
- function getPromiseCtor(promiseCtor) {
597
- if (!promiseCtor) {
598
- promiseCtor = Promise;
599
- }
600
- if (!promiseCtor) {
601
- throw new Error('no Promise impl found');
602
- }
603
- return promiseCtor;
604
- }
605
-
606
- const ObjectUnsubscribedErrorImpl = (() => {
607
- function ObjectUnsubscribedErrorImpl() {
608
- Error.call(this);
609
- this.message = 'object unsubscribed';
610
- this.name = 'ObjectUnsubscribedError';
611
- return this;
612
- }
613
- ObjectUnsubscribedErrorImpl.prototype = Object.create(Error.prototype);
614
- return ObjectUnsubscribedErrorImpl;
615
- })();
616
- const ObjectUnsubscribedError = ObjectUnsubscribedErrorImpl;
617
-
618
- class SubjectSubscription extends Subscription {
619
- constructor(subject, subscriber) {
620
- super();
621
- this.subject = subject;
622
- this.subscriber = subscriber;
623
- this.closed = false;
624
- }
625
- unsubscribe() {
626
- if (this.closed) {
627
- return;
628
- }
629
- this.closed = true;
630
- const subject = this.subject;
631
- const observers = subject.observers;
632
- this.subject = null;
633
- if (!observers || observers.length === 0 || subject.isStopped || subject.closed) {
634
- return;
635
- }
636
- const subscriberIndex = observers.indexOf(this.subscriber);
637
- if (subscriberIndex !== -1) {
638
- observers.splice(subscriberIndex, 1);
639
- }
640
- }
641
- }
642
-
643
- class SubjectSubscriber extends Subscriber {
644
- constructor(destination) {
645
- super(destination);
646
- this.destination = destination;
647
- }
648
- }
649
- class Subject extends Observable {
650
- constructor() {
651
- super();
652
- this.observers = [];
653
- this.closed = false;
654
- this.isStopped = false;
655
- this.hasError = false;
656
- this.thrownError = null;
657
- }
658
- [rxSubscriber]() {
659
- return new SubjectSubscriber(this);
660
- }
661
- lift(operator) {
662
- const subject = new AnonymousSubject(this, this);
663
- subject.operator = operator;
664
- return subject;
665
- }
666
- next(value) {
667
- if (this.closed) {
668
- throw new ObjectUnsubscribedError();
669
- }
670
- if (!this.isStopped) {
671
- const { observers } = this;
672
- const len = observers.length;
673
- const copy = observers.slice();
674
- for (let i = 0; i < len; i++) {
675
- copy[i].next(value);
676
- }
677
- }
678
- }
679
- error(err) {
680
- if (this.closed) {
681
- throw new ObjectUnsubscribedError();
682
- }
683
- this.hasError = true;
684
- this.thrownError = err;
685
- this.isStopped = true;
686
- const { observers } = this;
687
- const len = observers.length;
688
- const copy = observers.slice();
689
- for (let i = 0; i < len; i++) {
690
- copy[i].error(err);
691
- }
692
- this.observers.length = 0;
693
- }
694
- complete() {
695
- if (this.closed) {
696
- throw new ObjectUnsubscribedError();
697
- }
698
- this.isStopped = true;
699
- const { observers } = this;
700
- const len = observers.length;
701
- const copy = observers.slice();
702
- for (let i = 0; i < len; i++) {
703
- copy[i].complete();
704
- }
705
- this.observers.length = 0;
706
- }
707
- unsubscribe() {
708
- this.isStopped = true;
709
- this.closed = true;
710
- this.observers = null;
711
- }
712
- _trySubscribe(subscriber) {
713
- if (this.closed) {
714
- throw new ObjectUnsubscribedError();
715
- }
716
- else {
717
- return super._trySubscribe(subscriber);
718
- }
719
- }
720
- _subscribe(subscriber) {
721
- if (this.closed) {
722
- throw new ObjectUnsubscribedError();
723
- }
724
- else if (this.hasError) {
725
- subscriber.error(this.thrownError);
726
- return Subscription.EMPTY;
727
- }
728
- else if (this.isStopped) {
729
- subscriber.complete();
730
- return Subscription.EMPTY;
731
- }
732
- else {
733
- this.observers.push(subscriber);
734
- return new SubjectSubscription(this, subscriber);
735
- }
736
- }
737
- asObservable() {
738
- const observable = new Observable();
739
- observable.source = this;
740
- return observable;
741
- }
742
- }
743
- Subject.create = (destination, source) => {
744
- return new AnonymousSubject(destination, source);
745
- };
746
- class AnonymousSubject extends Subject {
747
- constructor(destination, source) {
748
- super();
749
- this.destination = destination;
750
- this.source = source;
751
- }
752
- next(value) {
753
- const { destination } = this;
754
- if (destination && destination.next) {
755
- destination.next(value);
756
- }
757
- }
758
- error(err) {
759
- const { destination } = this;
760
- if (destination && destination.error) {
761
- this.destination.error(err);
762
- }
763
- }
764
- complete() {
765
- const { destination } = this;
766
- if (destination && destination.complete) {
767
- this.destination.complete();
768
- }
769
- }
770
- _subscribe(subscriber) {
771
- const { source } = this;
772
- if (source) {
773
- return this.source.subscribe(subscriber);
774
- }
775
- else {
776
- return Subscription.EMPTY;
777
- }
778
- }
779
- }
780
-
781
- class BehaviorSubject extends Subject {
782
- constructor(_value) {
783
- super();
784
- this._value = _value;
785
- }
786
- get value() {
787
- return this.getValue();
788
- }
789
- _subscribe(subscriber) {
790
- const subscription = super._subscribe(subscriber);
791
- if (subscription && !subscription.closed) {
792
- subscriber.next(this._value);
793
- }
794
- return subscription;
795
- }
796
- getValue() {
797
- if (this.hasError) {
798
- throw this.thrownError;
799
- }
800
- else if (this.closed) {
801
- throw new ObjectUnsubscribedError();
802
- }
803
- else {
804
- return this._value;
805
- }
806
- }
807
- next(value) {
808
- super.next(this._value = value);
809
- }
810
- }
811
-
812
- class Action extends Subscription {
813
- constructor(scheduler, work) {
814
- super();
815
- }
816
- schedule(state, delay = 0) {
817
- return this;
818
- }
819
- }
820
-
821
- class AsyncAction extends Action {
822
- constructor(scheduler, work) {
823
- super(scheduler, work);
824
- this.scheduler = scheduler;
825
- this.work = work;
826
- this.pending = false;
827
- }
828
- schedule(state, delay = 0) {
829
- if (this.closed) {
830
- return this;
831
- }
832
- this.state = state;
833
- const id = this.id;
834
- const scheduler = this.scheduler;
835
- if (id != null) {
836
- this.id = this.recycleAsyncId(scheduler, id, delay);
837
- }
838
- this.pending = true;
839
- this.delay = delay;
840
- this.id = this.id || this.requestAsyncId(scheduler, this.id, delay);
841
- return this;
842
- }
843
- requestAsyncId(scheduler, id, delay = 0) {
844
- return setInterval(scheduler.flush.bind(scheduler, this), delay);
845
- }
846
- recycleAsyncId(scheduler, id, delay = 0) {
847
- if (delay !== null && this.delay === delay && this.pending === false) {
848
- return id;
849
- }
850
- clearInterval(id);
851
- return undefined;
852
- }
853
- execute(state, delay) {
854
- if (this.closed) {
855
- return new Error('executing a cancelled action');
856
- }
857
- this.pending = false;
858
- const error = this._execute(state, delay);
859
- if (error) {
860
- return error;
861
- }
862
- else if (this.pending === false && this.id != null) {
863
- this.id = this.recycleAsyncId(this.scheduler, this.id, null);
864
- }
865
- }
866
- _execute(state, delay) {
867
- let errored = false;
868
- let errorValue = undefined;
869
- try {
870
- this.work(state);
871
- }
872
- catch (e) {
873
- errored = true;
874
- errorValue = !!e && e || new Error(e);
875
- }
876
- if (errored) {
877
- this.unsubscribe();
878
- return errorValue;
879
- }
880
- }
881
- _unsubscribe() {
882
- const id = this.id;
883
- const scheduler = this.scheduler;
884
- const actions = scheduler.actions;
885
- const index = actions.indexOf(this);
886
- this.work = null;
887
- this.state = null;
888
- this.pending = false;
889
- this.scheduler = null;
890
- if (index !== -1) {
891
- actions.splice(index, 1);
892
- }
893
- if (id != null) {
894
- this.id = this.recycleAsyncId(scheduler, id, null);
895
- }
896
- this.delay = null;
897
- }
898
- }
899
-
900
- class QueueAction extends AsyncAction {
901
- constructor(scheduler, work) {
902
- super(scheduler, work);
903
- this.scheduler = scheduler;
904
- this.work = work;
905
- }
906
- schedule(state, delay = 0) {
907
- if (delay > 0) {
908
- return super.schedule(state, delay);
909
- }
910
- this.delay = delay;
911
- this.state = state;
912
- this.scheduler.flush(this);
913
- return this;
914
- }
915
- execute(state, delay) {
916
- return (delay > 0 || this.closed) ?
917
- super.execute(state, delay) :
918
- this._execute(state, delay);
919
- }
920
- requestAsyncId(scheduler, id, delay = 0) {
921
- if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {
922
- return super.requestAsyncId(scheduler, id, delay);
923
- }
924
- return scheduler.flush(this);
925
- }
926
- }
927
-
928
- class Scheduler {
929
- constructor(SchedulerAction, now = Scheduler.now) {
930
- this.SchedulerAction = SchedulerAction;
931
- this.now = now;
932
- }
933
- schedule(work, delay = 0, state) {
934
- return new this.SchedulerAction(this, work).schedule(state, delay);
935
- }
936
- }
937
- Scheduler.now = () => Date.now();
938
-
939
- class AsyncScheduler extends Scheduler {
940
- constructor(SchedulerAction, now = Scheduler.now) {
941
- super(SchedulerAction, () => {
942
- if (AsyncScheduler.delegate && AsyncScheduler.delegate !== this) {
943
- return AsyncScheduler.delegate.now();
944
- }
945
- else {
946
- return now();
947
- }
948
- });
949
- this.actions = [];
950
- this.active = false;
951
- this.scheduled = undefined;
952
- }
953
- schedule(work, delay = 0, state) {
954
- if (AsyncScheduler.delegate && AsyncScheduler.delegate !== this) {
955
- return AsyncScheduler.delegate.schedule(work, delay, state);
956
- }
957
- else {
958
- return super.schedule(work, delay, state);
959
- }
960
- }
961
- flush(action) {
962
- const { actions } = this;
963
- if (this.active) {
964
- actions.push(action);
965
- return;
966
- }
967
- let error;
968
- this.active = true;
969
- do {
970
- if (error = action.execute(action.state, action.delay)) {
971
- break;
972
- }
973
- } while (action = actions.shift());
974
- this.active = false;
975
- if (error) {
976
- while (action = actions.shift()) {
977
- action.unsubscribe();
978
- }
979
- throw error;
980
- }
981
- }
982
- }
983
-
984
- class QueueScheduler extends AsyncScheduler {
985
- }
986
-
987
- const queueScheduler = new QueueScheduler(QueueAction);
988
- const queue = queueScheduler;
989
-
990
- const EMPTY = new Observable(subscriber => subscriber.complete());
991
- function empty$1(scheduler) {
992
- return scheduler ? emptyScheduled(scheduler) : EMPTY;
993
- }
994
- function emptyScheduled(scheduler) {
995
- return new Observable(subscriber => scheduler.schedule(() => subscriber.complete()));
996
- }
997
-
998
- function isScheduler(value) {
999
- return value && typeof value.schedule === 'function';
1000
- }
1001
-
1002
- const subscribeToArray = (array) => (subscriber) => {
1003
- for (let i = 0, len = array.length; i < len && !subscriber.closed; i++) {
1004
- subscriber.next(array[i]);
1005
- }
1006
- subscriber.complete();
1007
- };
1008
-
1009
- function scheduleArray(input, scheduler) {
1010
- return new Observable(subscriber => {
1011
- const sub = new Subscription();
1012
- let i = 0;
1013
- sub.add(scheduler.schedule(function () {
1014
- if (i === input.length) {
1015
- subscriber.complete();
1016
- return;
1017
- }
1018
- subscriber.next(input[i++]);
1019
- if (!subscriber.closed) {
1020
- sub.add(this.schedule());
1021
- }
1022
- }));
1023
- return sub;
1024
- });
1025
- }
1026
-
1027
- function fromArray(input, scheduler) {
1028
- if (!scheduler) {
1029
- return new Observable(subscribeToArray(input));
1030
- }
1031
- else {
1032
- return scheduleArray(input, scheduler);
1033
- }
1034
- }
1035
-
1036
- function of(...args) {
1037
- let scheduler = args[args.length - 1];
1038
- if (isScheduler(scheduler)) {
1039
- args.pop();
1040
- return scheduleArray(args, scheduler);
1041
- }
1042
- else {
1043
- return fromArray(args);
1044
- }
1045
- }
1046
-
1047
- function throwError(error, scheduler) {
1048
- if (!scheduler) {
1049
- return new Observable(subscriber => subscriber.error(error));
1050
- }
1051
- else {
1052
- return new Observable(subscriber => scheduler.schedule(dispatch, 0, { error, subscriber }));
1053
- }
1054
- }
1055
- function dispatch({ error, subscriber }) {
1056
- subscriber.error(error);
1057
- }
1058
-
1059
- var NotificationKind;
1060
- (function (NotificationKind) {
1061
- NotificationKind["NEXT"] = "N";
1062
- NotificationKind["ERROR"] = "E";
1063
- NotificationKind["COMPLETE"] = "C";
1064
- })(NotificationKind || (NotificationKind = {}));
1065
- class Notification {
1066
- constructor(kind, value, error) {
1067
- this.kind = kind;
1068
- this.value = value;
1069
- this.error = error;
1070
- this.hasValue = kind === 'N';
1071
- }
1072
- observe(observer) {
1073
- switch (this.kind) {
1074
- case 'N':
1075
- return observer.next && observer.next(this.value);
1076
- case 'E':
1077
- return observer.error && observer.error(this.error);
1078
- case 'C':
1079
- return observer.complete && observer.complete();
1080
- }
1081
- }
1082
- do(next, error, complete) {
1083
- const kind = this.kind;
1084
- switch (kind) {
1085
- case 'N':
1086
- return next && next(this.value);
1087
- case 'E':
1088
- return error && error(this.error);
1089
- case 'C':
1090
- return complete && complete();
1091
- }
1092
- }
1093
- accept(nextOrObserver, error, complete) {
1094
- if (nextOrObserver && typeof nextOrObserver.next === 'function') {
1095
- return this.observe(nextOrObserver);
1096
- }
1097
- else {
1098
- return this.do(nextOrObserver, error, complete);
1099
- }
1100
- }
1101
- toObservable() {
1102
- const kind = this.kind;
1103
- switch (kind) {
1104
- case 'N':
1105
- return of(this.value);
1106
- case 'E':
1107
- return throwError(this.error);
1108
- case 'C':
1109
- return empty$1();
1110
- }
1111
- throw new Error('unexpected notification kind value');
1112
- }
1113
- static createNext(value) {
1114
- if (typeof value !== 'undefined') {
1115
- return new Notification('N', value);
1116
- }
1117
- return Notification.undefinedValueNotification;
1118
- }
1119
- static createError(err) {
1120
- return new Notification('E', undefined, err);
1121
- }
1122
- static createComplete() {
1123
- return Notification.completeNotification;
1124
- }
1125
- }
1126
- Notification.completeNotification = new Notification('C');
1127
- Notification.undefinedValueNotification = new Notification('N', undefined);
1128
-
1129
- class ObserveOnSubscriber extends Subscriber {
1130
- constructor(destination, scheduler, delay = 0) {
1131
- super(destination);
1132
- this.scheduler = scheduler;
1133
- this.delay = delay;
1134
- }
1135
- static dispatch(arg) {
1136
- const { notification, destination } = arg;
1137
- notification.observe(destination);
1138
- this.unsubscribe();
1139
- }
1140
- scheduleMessage(notification) {
1141
- const destination = this.destination;
1142
- destination.add(this.scheduler.schedule(ObserveOnSubscriber.dispatch, this.delay, new ObserveOnMessage(notification, this.destination)));
1143
- }
1144
- _next(value) {
1145
- this.scheduleMessage(Notification.createNext(value));
1146
- }
1147
- _error(err) {
1148
- this.scheduleMessage(Notification.createError(err));
1149
- this.unsubscribe();
1150
- }
1151
- _complete() {
1152
- this.scheduleMessage(Notification.createComplete());
1153
- this.unsubscribe();
1154
- }
1155
- }
1156
- class ObserveOnMessage {
1157
- constructor(notification, destination) {
1158
- this.notification = notification;
1159
- this.destination = destination;
1160
- }
1161
- }
1162
-
1163
- class ReplaySubject extends Subject {
1164
- constructor(bufferSize = Number.POSITIVE_INFINITY, windowTime = Number.POSITIVE_INFINITY, scheduler) {
1165
- super();
1166
- this.scheduler = scheduler;
1167
- this._events = [];
1168
- this._infiniteTimeWindow = false;
1169
- this._bufferSize = bufferSize < 1 ? 1 : bufferSize;
1170
- this._windowTime = windowTime < 1 ? 1 : windowTime;
1171
- if (windowTime === Number.POSITIVE_INFINITY) {
1172
- this._infiniteTimeWindow = true;
1173
- this.next = this.nextInfiniteTimeWindow;
1174
- }
1175
- else {
1176
- this.next = this.nextTimeWindow;
1177
- }
1178
- }
1179
- nextInfiniteTimeWindow(value) {
1180
- if (!this.isStopped) {
1181
- const _events = this._events;
1182
- _events.push(value);
1183
- if (_events.length > this._bufferSize) {
1184
- _events.shift();
1185
- }
1186
- }
1187
- super.next(value);
1188
- }
1189
- nextTimeWindow(value) {
1190
- if (!this.isStopped) {
1191
- this._events.push(new ReplayEvent(this._getNow(), value));
1192
- this._trimBufferThenGetEvents();
1193
- }
1194
- super.next(value);
1195
- }
1196
- _subscribe(subscriber) {
1197
- const _infiniteTimeWindow = this._infiniteTimeWindow;
1198
- const _events = _infiniteTimeWindow ? this._events : this._trimBufferThenGetEvents();
1199
- const scheduler = this.scheduler;
1200
- const len = _events.length;
1201
- let subscription;
1202
- if (this.closed) {
1203
- throw new ObjectUnsubscribedError();
1204
- }
1205
- else if (this.isStopped || this.hasError) {
1206
- subscription = Subscription.EMPTY;
1207
- }
1208
- else {
1209
- this.observers.push(subscriber);
1210
- subscription = new SubjectSubscription(this, subscriber);
1211
- }
1212
- if (scheduler) {
1213
- subscriber.add(subscriber = new ObserveOnSubscriber(subscriber, scheduler));
1214
- }
1215
- if (_infiniteTimeWindow) {
1216
- for (let i = 0; i < len && !subscriber.closed; i++) {
1217
- subscriber.next(_events[i]);
1218
- }
1219
- }
1220
- else {
1221
- for (let i = 0; i < len && !subscriber.closed; i++) {
1222
- subscriber.next(_events[i].value);
1223
- }
1224
- }
1225
- if (this.hasError) {
1226
- subscriber.error(this.thrownError);
1227
- }
1228
- else if (this.isStopped) {
1229
- subscriber.complete();
1230
- }
1231
- return subscription;
1232
- }
1233
- _getNow() {
1234
- return (this.scheduler || queue).now();
1235
- }
1236
- _trimBufferThenGetEvents() {
1237
- const now = this._getNow();
1238
- const _bufferSize = this._bufferSize;
1239
- const _windowTime = this._windowTime;
1240
- const _events = this._events;
1241
- const eventsCount = _events.length;
1242
- let spliceCount = 0;
1243
- while (spliceCount < eventsCount) {
1244
- if ((now - _events[spliceCount].time) < _windowTime) {
1245
- break;
1246
- }
1247
- spliceCount++;
1248
- }
1249
- if (eventsCount > _bufferSize) {
1250
- spliceCount = Math.max(spliceCount, eventsCount - _bufferSize);
1251
- }
1252
- if (spliceCount > 0) {
1253
- _events.splice(0, spliceCount);
1254
- }
1255
- return _events;
1256
- }
1257
- }
1258
- class ReplayEvent {
1259
- constructor(time, value) {
1260
- this.time = time;
1261
- this.value = value;
1262
- }
1263
- }
1264
-
1265
- const asyncScheduler = new AsyncScheduler(AsyncAction);
1266
- const async = asyncScheduler;
1267
-
1268
- function isObservable(obj) {
1269
- return !!obj && (obj instanceof Observable || (typeof obj.lift === 'function' && typeof obj.subscribe === 'function'));
1270
- }
1271
-
1272
- const ArgumentOutOfRangeErrorImpl = (() => {
1273
- function ArgumentOutOfRangeErrorImpl() {
1274
- Error.call(this);
1275
- this.message = 'argument out of range';
1276
- this.name = 'ArgumentOutOfRangeError';
1277
- return this;
1278
- }
1279
- ArgumentOutOfRangeErrorImpl.prototype = Object.create(Error.prototype);
1280
- return ArgumentOutOfRangeErrorImpl;
1281
- })();
1282
- const ArgumentOutOfRangeError = ArgumentOutOfRangeErrorImpl;
1283
-
1284
- function map(project, thisArg) {
1285
- return function mapOperation(source) {
1286
- if (typeof project !== 'function') {
1287
- throw new TypeError('argument is not a function. Are you looking for `mapTo()`?');
1288
- }
1289
- return source.lift(new MapOperator(project, thisArg));
1290
- };
1291
- }
1292
- class MapOperator {
1293
- constructor(project, thisArg) {
1294
- this.project = project;
1295
- this.thisArg = thisArg;
1296
- }
1297
- call(subscriber, source) {
1298
- return source.subscribe(new MapSubscriber(subscriber, this.project, this.thisArg));
1299
- }
1300
- }
1301
- class MapSubscriber extends Subscriber {
1302
- constructor(destination, project, thisArg) {
1303
- super(destination);
1304
- this.project = project;
1305
- this.count = 0;
1306
- this.thisArg = thisArg || this;
1307
- }
1308
- _next(value) {
1309
- let result;
1310
- try {
1311
- result = this.project.call(this.thisArg, value, this.count++);
1312
- }
1313
- catch (err) {
1314
- this.destination.error(err);
1315
- return;
1316
- }
1317
- this.destination.next(result);
1318
- }
1319
- }
1320
-
1321
- const subscribeToPromise = (promise) => (subscriber) => {
1322
- promise.then((value) => {
1323
- if (!subscriber.closed) {
1324
- subscriber.next(value);
1325
- subscriber.complete();
1326
- }
1327
- }, (err) => subscriber.error(err))
1328
- .then(null, hostReportError);
1329
- return subscriber;
1330
- };
1331
-
1332
- function getSymbolIterator() {
1333
- if (typeof Symbol !== 'function' || !Symbol.iterator) {
1334
- return '@@iterator';
1335
- }
1336
- return Symbol.iterator;
1337
- }
1338
- const iterator = getSymbolIterator();
1339
-
1340
- const subscribeToIterable = (iterable) => (subscriber) => {
1341
- const iterator$1 = iterable[iterator]();
1342
- do {
1343
- let item;
1344
- try {
1345
- item = iterator$1.next();
1346
- }
1347
- catch (err) {
1348
- subscriber.error(err);
1349
- return subscriber;
1350
- }
1351
- if (item.done) {
1352
- subscriber.complete();
1353
- break;
1354
- }
1355
- subscriber.next(item.value);
1356
- if (subscriber.closed) {
1357
- break;
1358
- }
1359
- } while (true);
1360
- if (typeof iterator$1.return === 'function') {
1361
- subscriber.add(() => {
1362
- if (iterator$1.return) {
1363
- iterator$1.return();
1364
- }
1365
- });
1366
- }
1367
- return subscriber;
1368
- };
1369
-
1370
- const subscribeToObservable = (obj) => (subscriber) => {
1371
- const obs = obj[observable]();
1372
- if (typeof obs.subscribe !== 'function') {
1373
- throw new TypeError('Provided object does not correctly implement Symbol.observable');
1374
- }
1375
- else {
1376
- return obs.subscribe(subscriber);
1377
- }
1378
- };
1379
-
1380
- const isArrayLike = ((x) => x && typeof x.length === 'number' && typeof x !== 'function');
1381
-
1382
- function isPromise(value) {
1383
- return !!value && typeof value.subscribe !== 'function' && typeof value.then === 'function';
1384
- }
1385
-
1386
- const subscribeTo = (result) => {
1387
- if (!!result && typeof result[observable] === 'function') {
1388
- return subscribeToObservable(result);
1389
- }
1390
- else if (isArrayLike(result)) {
1391
- return subscribeToArray(result);
1392
- }
1393
- else if (isPromise(result)) {
1394
- return subscribeToPromise(result);
1395
- }
1396
- else if (!!result && typeof result[iterator] === 'function') {
1397
- return subscribeToIterable(result);
1398
- }
1399
- else {
1400
- const value = isObject(result) ? 'an invalid object' : `'${result}'`;
1401
- const msg = `You provided ${value} where a stream was expected.`
1402
- + ' You can provide an Observable, Promise, Array, or Iterable.';
1403
- throw new TypeError(msg);
1404
- }
1405
- };
1406
-
1407
- function scheduleObservable(input, scheduler) {
1408
- return new Observable(subscriber => {
1409
- const sub = new Subscription();
1410
- sub.add(scheduler.schedule(() => {
1411
- const observable$1 = input[observable]();
1412
- sub.add(observable$1.subscribe({
1413
- next(value) { sub.add(scheduler.schedule(() => subscriber.next(value))); },
1414
- error(err) { sub.add(scheduler.schedule(() => subscriber.error(err))); },
1415
- complete() { sub.add(scheduler.schedule(() => subscriber.complete())); },
1416
- }));
1417
- }));
1418
- return sub;
1419
- });
1420
- }
1421
-
1422
- function schedulePromise(input, scheduler) {
1423
- return new Observable(subscriber => {
1424
- const sub = new Subscription();
1425
- sub.add(scheduler.schedule(() => input.then(value => {
1426
- sub.add(scheduler.schedule(() => {
1427
- subscriber.next(value);
1428
- sub.add(scheduler.schedule(() => subscriber.complete()));
1429
- }));
1430
- }, err => {
1431
- sub.add(scheduler.schedule(() => subscriber.error(err)));
1432
- })));
1433
- return sub;
1434
- });
1435
- }
1436
-
1437
- function scheduleIterable(input, scheduler) {
1438
- if (!input) {
1439
- throw new Error('Iterable cannot be null');
1440
- }
1441
- return new Observable(subscriber => {
1442
- const sub = new Subscription();
1443
- let iterator$1;
1444
- sub.add(() => {
1445
- if (iterator$1 && typeof iterator$1.return === 'function') {
1446
- iterator$1.return();
1447
- }
1448
- });
1449
- sub.add(scheduler.schedule(() => {
1450
- iterator$1 = input[iterator]();
1451
- sub.add(scheduler.schedule(function () {
1452
- if (subscriber.closed) {
1453
- return;
1454
- }
1455
- let value;
1456
- let done;
1457
- try {
1458
- const result = iterator$1.next();
1459
- value = result.value;
1460
- done = result.done;
1461
- }
1462
- catch (err) {
1463
- subscriber.error(err);
1464
- return;
1465
- }
1466
- if (done) {
1467
- subscriber.complete();
1468
- }
1469
- else {
1470
- subscriber.next(value);
1471
- this.schedule();
1472
- }
1473
- }));
1474
- }));
1475
- return sub;
1476
- });
1477
- }
1478
-
1479
- function isInteropObservable(input) {
1480
- return input && typeof input[observable] === 'function';
1481
- }
1482
-
1483
- function isIterable(input) {
1484
- return input && typeof input[iterator] === 'function';
1485
- }
1486
-
1487
- function scheduled(input, scheduler) {
1488
- if (input != null) {
1489
- if (isInteropObservable(input)) {
1490
- return scheduleObservable(input, scheduler);
1491
- }
1492
- else if (isPromise(input)) {
1493
- return schedulePromise(input, scheduler);
1494
- }
1495
- else if (isArrayLike(input)) {
1496
- return scheduleArray(input, scheduler);
1497
- }
1498
- else if (isIterable(input) || typeof input === 'string') {
1499
- return scheduleIterable(input, scheduler);
1500
- }
1501
- }
1502
- throw new TypeError((input !== null && typeof input || input) + ' is not observable');
1503
- }
1504
-
1505
- function from(input, scheduler) {
1506
- if (!scheduler) {
1507
- if (input instanceof Observable) {
1508
- return input;
1509
- }
1510
- return new Observable(subscribeTo(input));
1511
- }
1512
- else {
1513
- return scheduled(input, scheduler);
1514
- }
1515
- }
1516
-
1517
- class SimpleInnerSubscriber extends Subscriber {
1518
- constructor(parent) {
1519
- super();
1520
- this.parent = parent;
1521
- }
1522
- _next(value) {
1523
- this.parent.notifyNext(value);
1524
- }
1525
- _error(error) {
1526
- this.parent.notifyError(error);
1527
- this.unsubscribe();
1528
- }
1529
- _complete() {
1530
- this.parent.notifyComplete();
1531
- this.unsubscribe();
1532
- }
1533
- }
1534
- class SimpleOuterSubscriber extends Subscriber {
1535
- notifyNext(innerValue) {
1536
- this.destination.next(innerValue);
1537
- }
1538
- notifyError(err) {
1539
- this.destination.error(err);
1540
- }
1541
- notifyComplete() {
1542
- this.destination.complete();
1543
- }
1544
- }
1545
- function innerSubscribe(result, innerSubscriber) {
1546
- if (innerSubscriber.closed) {
1547
- return undefined;
1548
- }
1549
- if (result instanceof Observable) {
1550
- return result.subscribe(innerSubscriber);
1551
- }
1552
- return subscribeTo(result)(innerSubscriber);
1553
- }
1554
-
1555
- function filter(predicate, thisArg) {
1556
- return function filterOperatorFunction(source) {
1557
- return source.lift(new FilterOperator(predicate, thisArg));
1558
- };
1559
- }
1560
- class FilterOperator {
1561
- constructor(predicate, thisArg) {
1562
- this.predicate = predicate;
1563
- this.thisArg = thisArg;
1564
- }
1565
- call(subscriber, source) {
1566
- return source.subscribe(new FilterSubscriber(subscriber, this.predicate, this.thisArg));
1567
- }
1568
- }
1569
- class FilterSubscriber extends Subscriber {
1570
- constructor(destination, predicate, thisArg) {
1571
- super(destination);
1572
- this.predicate = predicate;
1573
- this.thisArg = thisArg;
1574
- this.count = 0;
1575
- }
1576
- _next(value) {
1577
- let result;
1578
- try {
1579
- result = this.predicate.call(this.thisArg, value, this.count++);
1580
- }
1581
- catch (err) {
1582
- this.destination.error(err);
1583
- return;
1584
- }
1585
- if (result) {
1586
- this.destination.next(value);
1587
- }
1588
- }
1589
- }
1590
-
1591
- function isDate(value) {
1592
- return value instanceof Date && !isNaN(+value);
1593
- }
1594
-
1595
- function delay(delay, scheduler = async) {
1596
- const absoluteDelay = isDate(delay);
1597
- const delayFor = absoluteDelay ? (+delay - scheduler.now()) : Math.abs(delay);
1598
- return (source) => source.lift(new DelayOperator(delayFor, scheduler));
1599
- }
1600
- class DelayOperator {
1601
- constructor(delay, scheduler) {
1602
- this.delay = delay;
1603
- this.scheduler = scheduler;
1604
- }
1605
- call(subscriber, source) {
1606
- return source.subscribe(new DelaySubscriber(subscriber, this.delay, this.scheduler));
1607
- }
1608
- }
1609
- class DelaySubscriber extends Subscriber {
1610
- constructor(destination, delay, scheduler) {
1611
- super(destination);
1612
- this.delay = delay;
1613
- this.scheduler = scheduler;
1614
- this.queue = [];
1615
- this.active = false;
1616
- this.errored = false;
1617
- }
1618
- static dispatch(state) {
1619
- const source = state.source;
1620
- const queue = source.queue;
1621
- const scheduler = state.scheduler;
1622
- const destination = state.destination;
1623
- while (queue.length > 0 && (queue[0].time - scheduler.now()) <= 0) {
1624
- queue.shift().notification.observe(destination);
1625
- }
1626
- if (queue.length > 0) {
1627
- const delay = Math.max(0, queue[0].time - scheduler.now());
1628
- this.schedule(state, delay);
1629
- }
1630
- else {
1631
- this.unsubscribe();
1632
- source.active = false;
1633
- }
1634
- }
1635
- _schedule(scheduler) {
1636
- this.active = true;
1637
- const destination = this.destination;
1638
- destination.add(scheduler.schedule(DelaySubscriber.dispatch, this.delay, {
1639
- source: this, destination: this.destination, scheduler: scheduler
1640
- }));
1641
- }
1642
- scheduleNotification(notification) {
1643
- if (this.errored === true) {
1644
- return;
1645
- }
1646
- const scheduler = this.scheduler;
1647
- const message = new DelayMessage(scheduler.now() + this.delay, notification);
1648
- this.queue.push(message);
1649
- if (this.active === false) {
1650
- this._schedule(scheduler);
1651
- }
1652
- }
1653
- _next(value) {
1654
- this.scheduleNotification(Notification.createNext(value));
1655
- }
1656
- _error(err) {
1657
- this.errored = true;
1658
- this.queue = [];
1659
- this.destination.error(err);
1660
- this.unsubscribe();
1661
- }
1662
- _complete() {
1663
- this.scheduleNotification(Notification.createComplete());
1664
- this.unsubscribe();
1665
- }
1666
- }
1667
- class DelayMessage {
1668
- constructor(time, notification) {
1669
- this.time = time;
1670
- this.notification = notification;
1671
- }
1672
- }
1673
-
1674
- function distinctUntilChanged(compare, keySelector) {
1675
- return (source) => source.lift(new DistinctUntilChangedOperator(compare, keySelector));
1676
- }
1677
- class DistinctUntilChangedOperator {
1678
- constructor(compare, keySelector) {
1679
- this.compare = compare;
1680
- this.keySelector = keySelector;
1681
- }
1682
- call(subscriber, source) {
1683
- return source.subscribe(new DistinctUntilChangedSubscriber(subscriber, this.compare, this.keySelector));
1684
- }
1685
- }
1686
- class DistinctUntilChangedSubscriber extends Subscriber {
1687
- constructor(destination, compare, keySelector) {
1688
- super(destination);
1689
- this.keySelector = keySelector;
1690
- this.hasKey = false;
1691
- if (typeof compare === 'function') {
1692
- this.compare = compare;
1693
- }
1694
- }
1695
- compare(x, y) {
1696
- return x === y;
1697
- }
1698
- _next(value) {
1699
- let key;
1700
- try {
1701
- const { keySelector } = this;
1702
- key = keySelector ? keySelector(value) : value;
1703
- }
1704
- catch (err) {
1705
- return this.destination.error(err);
1706
- }
1707
- let result = false;
1708
- if (this.hasKey) {
1709
- try {
1710
- const { compare } = this;
1711
- result = compare(this.key, key);
1712
- }
1713
- catch (err) {
1714
- return this.destination.error(err);
1715
- }
1716
- }
1717
- else {
1718
- this.hasKey = true;
1719
- }
1720
- if (!result) {
1721
- this.key = key;
1722
- this.destination.next(value);
1723
- }
1724
- }
1725
- }
1726
-
1727
- function take(count) {
1728
- return (source) => {
1729
- if (count === 0) {
1730
- return empty$1();
1731
- }
1732
- else {
1733
- return source.lift(new TakeOperator(count));
1734
- }
1735
- };
1736
- }
1737
- class TakeOperator {
1738
- constructor(total) {
1739
- this.total = total;
1740
- if (this.total < 0) {
1741
- throw new ArgumentOutOfRangeError;
1742
- }
1743
- }
1744
- call(subscriber, source) {
1745
- return source.subscribe(new TakeSubscriber(subscriber, this.total));
1746
- }
1747
- }
1748
- class TakeSubscriber extends Subscriber {
1749
- constructor(destination, total) {
1750
- super(destination);
1751
- this.total = total;
1752
- this.count = 0;
1753
- }
1754
- _next(value) {
1755
- const total = this.total;
1756
- const count = ++this.count;
1757
- if (count <= total) {
1758
- this.destination.next(value);
1759
- if (count === total) {
1760
- this.destination.complete();
1761
- this.unsubscribe();
1762
- }
1763
- }
1764
- }
1765
- }
1766
-
1767
- function switchMap(project, resultSelector) {
1768
- if (typeof resultSelector === 'function') {
1769
- return (source) => source.pipe(switchMap((a, i) => from(project(a, i)).pipe(map((b, ii) => resultSelector(a, b, i, ii)))));
1770
- }
1771
- return (source) => source.lift(new SwitchMapOperator(project));
1772
- }
1773
- class SwitchMapOperator {
1774
- constructor(project) {
1775
- this.project = project;
1776
- }
1777
- call(subscriber, source) {
1778
- return source.subscribe(new SwitchMapSubscriber(subscriber, this.project));
1779
- }
1780
- }
1781
- class SwitchMapSubscriber extends SimpleOuterSubscriber {
1782
- constructor(destination, project) {
1783
- super(destination);
1784
- this.project = project;
1785
- this.index = 0;
1786
- }
1787
- _next(value) {
1788
- let result;
1789
- const index = this.index++;
1790
- try {
1791
- result = this.project(value, index);
1792
- }
1793
- catch (error) {
1794
- this.destination.error(error);
1795
- return;
1796
- }
1797
- this._innerSub(result);
1798
- }
1799
- _innerSub(result) {
1800
- const innerSubscription = this.innerSubscription;
1801
- if (innerSubscription) {
1802
- innerSubscription.unsubscribe();
1803
- }
1804
- const innerSubscriber = new SimpleInnerSubscriber(this);
1805
- const destination = this.destination;
1806
- destination.add(innerSubscriber);
1807
- this.innerSubscription = innerSubscribe(result, innerSubscriber);
1808
- if (this.innerSubscription !== innerSubscriber) {
1809
- destination.add(this.innerSubscription);
1810
- }
1811
- }
1812
- _complete() {
1813
- const { innerSubscription } = this;
1814
- if (!innerSubscription || innerSubscription.closed) {
1815
- super._complete();
1816
- }
1817
- this.unsubscribe();
1818
- }
1819
- _unsubscribe() {
1820
- this.innerSubscription = undefined;
1821
- }
1822
- notifyComplete() {
1823
- this.innerSubscription = undefined;
1824
- if (this.isStopped) {
1825
- super._complete();
1826
- }
1827
- }
1828
- notifyNext(innerValue) {
1829
- this.destination.next(innerValue);
1830
- }
1831
- }
1832
-
1833
- const currentAction = {
1834
- type: null,
1835
- entityIds: null,
1836
- skip: false,
1837
- };
1838
- let customActionActive = false;
1839
- function resetCustomAction() {
1840
- customActionActive = false;
1841
- }
1842
- // public API for custom actions. Custom action always wins
1843
- function logAction(type, entityIds) {
1844
- setAction(type, entityIds);
1845
- customActionActive = true;
1846
- }
1847
- function setAction(type, entityIds) {
1848
- if (customActionActive === false) {
1849
- currentAction.type = type;
1850
- currentAction.entityIds = entityIds;
1851
- }
1852
- }
1853
- function action(action, entityIds) {
1854
- return function (target, propertyKey, descriptor) {
1855
- const originalMethod = descriptor.value;
1856
- descriptor.value = function (...args) {
1857
- logAction(action, entityIds);
1858
- return originalMethod.apply(this, args);
1859
- };
1860
- return descriptor;
1861
- };
1862
- }
1863
-
1864
- // @internal
1865
- function hasEntity(entities, id) {
1866
- return entities.hasOwnProperty(id);
1867
- }
1868
-
1869
- // @internal
1870
- function addEntities({ state, entities, idKey, options = {}, preAddEntity }) {
1871
- let newEntities = {};
1872
- let newIds = [];
1873
- let hasNewEntities = false;
1874
- for (const entity of entities) {
1875
- if (hasEntity(state.entities, entity[idKey]) === false) {
1876
- // evaluate the middleware first to support dynamic ids
1877
- const current = preAddEntity(entity);
1878
- const entityId = current[idKey];
1879
- newEntities[entityId] = current;
1880
- if (options.prepend)
1881
- newIds.unshift(entityId);
1882
- else
1883
- newIds.push(entityId);
1884
- hasNewEntities = true;
1885
- }
1886
- }
1887
- return hasNewEntities
1888
- ? {
1889
- newState: Object.assign({}, state, { entities: Object.assign({}, state.entities, newEntities), ids: options.prepend ? [...newIds, ...state.ids] : [...state.ids, ...newIds] }),
1890
- newIds
1891
- }
1892
- : null;
1893
- }
1894
-
1895
- // @internal
1896
- function isNil(v) {
1897
- return v === null || v === undefined;
1898
- }
1899
-
1900
- // @internal
1901
- function coerceArray(value) {
1902
- if (isNil(value)) {
1903
- return [];
1904
- }
1905
- return Array.isArray(value) ? value : [value];
1906
- }
1907
-
1908
- const DEFAULT_ID_KEY = 'id';
1909
-
1910
- var EntityActions;
1911
- (function (EntityActions) {
1912
- EntityActions["Set"] = "Set";
1913
- EntityActions["Add"] = "Add";
1914
- EntityActions["Update"] = "Update";
1915
- EntityActions["Remove"] = "Remove";
1916
- })(EntityActions || (EntityActions = {}));
1917
-
1918
- const isBrowser = typeof window !== 'undefined';
1919
-
1920
- let __DEV__ = true;
1921
- function enableAkitaProdMode() {
1922
- __DEV__ = false;
1923
- if (isBrowser) {
1924
- delete window.$$stores;
1925
- delete window.$$queries;
1926
- }
1927
- }
1928
- // @internal
1929
- function isDev() {
1930
- return __DEV__;
1931
- }
1932
-
1933
- // @internal
1934
- function isObject$1(value) {
1935
- const type = typeof value;
1936
- return value != null && (type == 'object' || type == 'function');
1937
- }
1938
-
1939
- // @internal
1940
- function isArray$1(value) {
1941
- return Array.isArray(value);
1942
- }
1943
-
1944
- // @internal
1945
- function getActiveEntities(idOrOptions, ids, currentActive) {
1946
- let result;
1947
- if (isArray$1(idOrOptions)) {
1948
- result = idOrOptions;
1949
- }
1950
- else {
1951
- if (isObject$1(idOrOptions)) {
1952
- if (isNil(currentActive))
1953
- return;
1954
- idOrOptions = Object.assign({ wrap: true }, idOrOptions);
1955
- const currentIdIndex = ids.indexOf(currentActive);
1956
- if (idOrOptions.prev) {
1957
- const isFirst = currentIdIndex === 0;
1958
- if (isFirst && !idOrOptions.wrap)
1959
- return;
1960
- result = isFirst ? ids[ids.length - 1] : ids[currentIdIndex - 1];
1961
- }
1962
- else if (idOrOptions.next) {
1963
- const isLast = ids.length === currentIdIndex + 1;
1964
- if (isLast && !idOrOptions.wrap)
1965
- return;
1966
- result = isLast ? ids[0] : ids[currentIdIndex + 1];
1967
- }
1968
- }
1969
- else {
1970
- if (idOrOptions === currentActive)
1971
- return;
1972
- result = idOrOptions;
1973
- }
1974
- }
1975
- return result;
1976
- }
1977
-
1978
- // @internal
1979
- const getInitialEntitiesState = () => ({
1980
- entities: {},
1981
- ids: [],
1982
- loading: true,
1983
- error: null
1984
- });
1985
-
1986
- // @internal
1987
- function isDefined(val) {
1988
- return isNil(val) === false;
1989
- }
1990
-
1991
- // @internal
1992
- function isEmpty(arr) {
1993
- if (isArray$1(arr)) {
1994
- return arr.length === 0;
1995
- }
1996
- return false;
1997
- }
1998
-
1999
- // @internal
2000
- function isFunction$1(value) {
2001
- return typeof value === 'function';
2002
- }
2003
-
2004
- // @internal
2005
- function isUndefined(value) {
2006
- return value === undefined;
2007
- }
2008
-
2009
- // @internal
2010
- function hasActiveState(state) {
2011
- return state.hasOwnProperty('active');
2012
- }
2013
- // @internal
2014
- function isMultiActiveState(active) {
2015
- return isArray$1(active);
2016
- }
2017
- // @internal
2018
- function resolveActiveEntity({ active, ids, entities }) {
2019
- if (isMultiActiveState(active)) {
2020
- return getExitingActives(active, ids);
2021
- }
2022
- if (hasEntity(entities, active) === false) {
2023
- return null;
2024
- }
2025
- return active;
2026
- }
2027
- // @internal
2028
- function getExitingActives(currentActivesIds, newIds) {
2029
- const filtered = currentActivesIds.filter(id => newIds.indexOf(id) > -1);
2030
- /** Return the same reference if nothing has changed */
2031
- if (filtered.length === currentActivesIds.length) {
2032
- return currentActivesIds;
2033
- }
2034
- return filtered;
2035
- }
2036
-
2037
- // @internal
2038
- function removeEntities({ state, ids }) {
2039
- if (isNil(ids))
2040
- return removeAllEntities(state);
2041
- const entities = state.entities;
2042
- let newEntities = {};
2043
- for (const id of state.ids) {
2044
- if (ids.includes(id) === false) {
2045
- newEntities[id] = entities[id];
2046
- }
2047
- }
2048
- const newState = Object.assign({}, state, { entities: newEntities, ids: state.ids.filter(current => ids.includes(current) === false) });
2049
- if (hasActiveState(state)) {
2050
- newState.active = resolveActiveEntity(newState);
2051
- }
2052
- return newState;
2053
- }
2054
- // @internal
2055
- function removeAllEntities(state) {
2056
- return Object.assign({}, state, { entities: {}, ids: [], active: isMultiActiveState(state.active) ? [] : null });
2057
- }
2058
-
2059
- // @internal
2060
- function toEntitiesObject(entities, idKey, preAddEntity) {
2061
- const acc = {
2062
- entities: {},
2063
- ids: []
2064
- };
2065
- for (const entity of entities) {
2066
- // evaluate the middleware first to support dynamic ids
2067
- const current = preAddEntity(entity);
2068
- acc.entities[current[idKey]] = current;
2069
- acc.ids.push(current[idKey]);
2070
- }
2071
- return acc;
2072
- }
2073
-
2074
- // @internal
2075
- function isEntityState(state) {
2076
- return state.entities && state.ids;
2077
- }
2078
- // @internal
2079
- function applyMiddleware(entities, preAddEntity) {
2080
- let mapped = {};
2081
- for (const id of Object.keys(entities)) {
2082
- mapped[id] = preAddEntity(entities[id]);
2083
- }
2084
- return mapped;
2085
- }
2086
- // @internal
2087
- function setEntities({ state, entities, idKey, preAddEntity, isNativePreAdd }) {
2088
- let newEntities;
2089
- let newIds;
2090
- if (isArray$1(entities)) {
2091
- const resolve = toEntitiesObject(entities, idKey, preAddEntity);
2092
- newEntities = resolve.entities;
2093
- newIds = resolve.ids;
2094
- }
2095
- else if (isEntityState(entities)) {
2096
- newEntities = isNativePreAdd ? entities.entities : applyMiddleware(entities.entities, preAddEntity);
2097
- newIds = entities.ids;
2098
- }
2099
- else {
2100
- // it's an object
2101
- newEntities = isNativePreAdd ? entities : applyMiddleware(entities, preAddEntity);
2102
- newIds = Object.keys(newEntities).map(id => (isNaN(id) ? id : Number(id)));
2103
- }
2104
- const newState = Object.assign({}, state, { entities: newEntities, ids: newIds, loading: false });
2105
- if (hasActiveState(state)) {
2106
- newState.active = resolveActiveEntity(newState);
2107
- }
2108
- return newState;
2109
- }
2110
-
2111
- let CONFIG = {
2112
- resettable: false,
2113
- ttl: null,
2114
- producerFn: undefined
2115
- };
2116
- // @internal
2117
- function getAkitaConfig() {
2118
- return CONFIG;
2119
- }
2120
- function getGlobalProducerFn() {
2121
- return CONFIG.producerFn;
2122
- }
2123
-
2124
- // @internal
2125
- function deepFreeze(o) {
2126
- Object.freeze(o);
2127
- const oIsFunction = typeof o === 'function';
2128
- const hasOwnProp = Object.prototype.hasOwnProperty;
2129
- Object.getOwnPropertyNames(o).forEach(function (prop) {
2130
- if (hasOwnProp.call(o, prop) &&
2131
- (oIsFunction ? prop !== 'caller' && prop !== 'callee' && prop !== 'arguments' : true) &&
2132
- o[prop] !== null &&
2133
- (typeof o[prop] === 'object' || typeof o[prop] === 'function') &&
2134
- !Object.isFrozen(o[prop])) {
2135
- deepFreeze(o[prop]);
2136
- }
2137
- });
2138
- return o;
2139
- }
2140
-
2141
- // @internal
2142
- const $$deleteStore = new Subject();
2143
- // @internal
2144
- const $$addStore = new ReplaySubject(50, 5000);
2145
- // @internal
2146
- const $$updateStore = new Subject();
2147
- // @internal
2148
- function dispatchDeleted(storeName) {
2149
- $$deleteStore.next(storeName);
2150
- }
2151
- // @internal
2152
- function dispatchAdded(storeName) {
2153
- $$addStore.next(storeName);
2154
- }
2155
- // @internal
2156
- function dispatchUpdate(storeName, action) {
2157
- $$updateStore.next({ storeName, action });
2158
- }
2159
- // @internal
2160
- function assertStoreHasName(name, className) {
2161
- if (!name) {
2162
- console.error(`@StoreConfig({ name }) is missing in ${className}`);
2163
- }
2164
- }
2165
-
2166
- // @internal
2167
- function toBoolean(value) {
2168
- return value != null && `${value}` !== 'false';
2169
- }
2170
-
2171
- // @internal
2172
- function isPlainObject(value) {
2173
- return toBoolean(value) && value.constructor.name === 'Object';
2174
- }
2175
-
2176
- const configKey = 'akitaConfig';
2177
- function StoreConfig(metadata) {
2178
- return function (constructor) {
2179
- constructor[configKey] = { idKey: 'id' };
2180
- for (let i = 0, keys = Object.keys(metadata); i < keys.length; i++) {
2181
- const key = keys[i];
2182
- /* name is preserved read only key */
2183
- if (key === 'name') {
2184
- constructor[configKey]['storeName'] = metadata[key];
2185
- }
2186
- else {
2187
- constructor[configKey][key] = metadata[key];
2188
- }
2189
- }
2190
- };
2191
- }
2192
-
2193
- // @internal
2194
- const __stores__ = {};
2195
- // @internal
2196
- const __queries__ = {};
2197
- if (isBrowser) {
2198
- window.$$stores = __stores__;
2199
- window.$$queries = __queries__;
2200
- }
2201
-
2202
- // @internal
2203
- const transactionFinished = new Subject();
2204
- // @internal
2205
- const transactionInProcess = new BehaviorSubject(false);
2206
- // @internal
2207
- const transactionManager = {
2208
- activeTransactions: 0,
2209
- batchTransaction: null
2210
- };
2211
- // @internal
2212
- function startBatch() {
2213
- if (!isTransactionInProcess()) {
2214
- transactionManager.batchTransaction = new Subject();
2215
- }
2216
- transactionManager.activeTransactions++;
2217
- transactionInProcess.next(true);
2218
- }
2219
- // @internal
2220
- function endBatch() {
2221
- if (--transactionManager.activeTransactions === 0) {
2222
- transactionManager.batchTransaction.next(true);
2223
- transactionManager.batchTransaction.complete();
2224
- transactionInProcess.next(false);
2225
- transactionFinished.next(true);
2226
- }
2227
- }
2228
- // @internal
2229
- function isTransactionInProcess() {
2230
- return transactionManager.activeTransactions > 0;
2231
- }
2232
- // @internal
2233
- function commit() {
2234
- return transactionManager.batchTransaction ? transactionManager.batchTransaction.asObservable() : of(true);
2235
- }
2236
- /**
2237
- * A logical transaction.
2238
- * Use this transaction to optimize the dispatch of all the stores.
2239
- * The following code will update the store, BUT emits only once
2240
- *
2241
- * @example
2242
- * applyTransaction(() => {
2243
- * this.todosStore.add(new Todo(1, title));
2244
- * this.todosStore.add(new Todo(2, title));
2245
- * });
2246
- *
2247
- */
2248
- function applyTransaction(action, thisArg = undefined) {
2249
- startBatch();
2250
- try {
2251
- return action.apply(thisArg);
2252
- }
2253
- finally {
2254
- logAction('@Transaction');
2255
- endBatch();
2256
- }
2257
- }
2258
- /**
2259
- * A logical transaction.
2260
- * Use this transaction to optimize the dispatch of all the stores.
2261
- *
2262
- * The following code will update the store, BUT emits only once.
2263
- *
2264
- * @example
2265
- * @transaction
2266
- * addTodos() {
2267
- * this.todosStore.add(new Todo(1, title));
2268
- * this.todosStore.add(new Todo(2, title));
2269
- * }
2270
- *
2271
- *
2272
- */
2273
- function transaction() {
2274
- return function (target, propertyKey, descriptor) {
2275
- const originalMethod = descriptor.value;
2276
- descriptor.value = function (...args) {
2277
- return applyTransaction(() => {
2278
- return originalMethod.apply(this, args);
2279
- }, this);
2280
- };
2281
- return descriptor;
2282
- };
2283
- }
2284
-
2285
- /**
2286
- *
2287
- * Store for managing any type of data
2288
- *
2289
- * @example
2290
- *
2291
- * export interface SessionState {
2292
- * token: string;
2293
- * userDetails: UserDetails
2294
- * }
2295
- *
2296
- * export function createInitialState(): SessionState {
2297
- * return {
2298
- * token: '',
2299
- * userDetails: null
2300
- * };
2301
- * }
2302
- *
2303
- * @StoreConfig({ name: 'session' })
2304
- * export class SessionStore extends Store<SessionState> {
2305
- * constructor() {
2306
- * super(createInitialState());
2307
- * }
2308
- * }
2309
- */
2310
- class Store {
2311
- constructor(initialState, options = {}) {
2312
- this.options = options;
2313
- this.inTransaction = false;
2314
- this.cache = {
2315
- active: new BehaviorSubject(false),
2316
- ttl: null,
2317
- };
2318
- this.onInit(initialState);
2319
- }
2320
- /**
2321
- * Set the loading state
2322
- *
2323
- * @example
2324
- *
2325
- * store.setLoading(true)
2326
- *
2327
- */
2328
- setLoading(loading = false) {
2329
- if (loading !== this._value().loading) {
2330
- isDev() && setAction('Set Loading');
2331
- this._setState((state) => (Object.assign({}, state, { loading })));
2332
- }
2333
- }
2334
- /**
2335
- *
2336
- * Set whether the data is cached
2337
- *
2338
- * @example
2339
- *
2340
- * store.setHasCache(true)
2341
- * store.setHasCache(false)
2342
- * store.setHasCache(true, { restartTTL: true })
2343
- *
2344
- */
2345
- setHasCache(hasCache, options = { restartTTL: false }) {
2346
- if (hasCache !== this.cache.active.value) {
2347
- this.cache.active.next(hasCache);
2348
- }
2349
- if (options.restartTTL) {
2350
- const ttlConfig = this.getCacheTTL();
2351
- if (ttlConfig) {
2352
- if (this.cache.ttl !== null) {
2353
- clearTimeout(this.cache.ttl);
2354
- }
2355
- this.cache.ttl = setTimeout(() => this.setHasCache(false), ttlConfig);
2356
- }
2357
- }
2358
- }
2359
- /**
2360
- *
2361
- * Sometimes we need to access the store value from a store
2362
- *
2363
- * @example middleware
2364
- *
2365
- */
2366
- getValue() {
2367
- return this.storeValue;
2368
- }
2369
- /**
2370
- * Set the error state
2371
- *
2372
- * @example
2373
- *
2374
- * store.setError({text: 'unable to load data' })
2375
- *
2376
- */
2377
- setError(error) {
2378
- if (error !== this._value().error) {
2379
- isDev() && setAction('Set Error');
2380
- this._setState((state) => (Object.assign({}, state, { error })));
2381
- }
2382
- }
2383
- // @internal
2384
- _select(project) {
2385
- return this.store.asObservable().pipe(map((snapshot) => project(snapshot.state)), distinctUntilChanged());
2386
- }
2387
- // @internal
2388
- _value() {
2389
- return this.storeValue;
2390
- }
2391
- // @internal
2392
- _cache() {
2393
- return this.cache.active;
2394
- }
2395
- // @internal
2396
- get config() {
2397
- return this.constructor[configKey] || {};
2398
- }
2399
- // @internal
2400
- get storeName() {
2401
- return this.config.storeName || this.options.storeName || this.options.name;
2402
- }
2403
- // @internal
2404
- get deepFreeze() {
2405
- return this.config.deepFreezeFn || this.options.deepFreezeFn || deepFreeze;
2406
- }
2407
- // @internal
2408
- get cacheConfig() {
2409
- return this.config.cache || this.options.cache;
2410
- }
2411
- get _producerFn() {
2412
- return this.config.producerFn || this.options.producerFn || getGlobalProducerFn();
2413
- }
2414
- // @internal
2415
- get resettable() {
2416
- return isDefined(this.config.resettable) ? this.config.resettable : this.options.resettable;
2417
- }
2418
- // @internal
2419
- _setState(newState, _dispatchAction = true) {
2420
- if (isFunction$1(newState)) {
2421
- const _newState = newState(this._value());
2422
- this.storeValue = __DEV__ ? this.deepFreeze(_newState) : _newState;
2423
- }
2424
- else {
2425
- this.storeValue = newState;
2426
- }
2427
- if (!this.store) {
2428
- this.store = new BehaviorSubject({ state: this.storeValue });
2429
- if (isDev()) {
2430
- this.store.subscribe(({ action }) => {
2431
- if (action) {
2432
- dispatchUpdate(this.storeName, action);
2433
- }
2434
- });
2435
- }
2436
- return;
2437
- }
2438
- if (isTransactionInProcess()) {
2439
- this.handleTransaction();
2440
- return;
2441
- }
2442
- this.dispatch(this.storeValue, _dispatchAction);
2443
- }
2444
- /**
2445
- *
2446
- * Reset the current store back to the initial value
2447
- *
2448
- * @example
2449
- *
2450
- * store.reset()
2451
- *
2452
- */
2453
- reset() {
2454
- if (this.isResettable()) {
2455
- isDev() && setAction('Reset');
2456
- this._setState(() => Object.assign({}, this._initialState));
2457
- this.setHasCache(false);
2458
- }
2459
- else {
2460
- isDev() && console.warn(`You need to enable the reset functionality`);
2461
- }
2462
- }
2463
- update(stateOrCallback) {
2464
- isDev() && setAction('Update');
2465
- let newState;
2466
- const currentState = this._value();
2467
- if (isFunction$1(stateOrCallback)) {
2468
- newState = isFunction$1(this._producerFn) ? this._producerFn(currentState, stateOrCallback) : stateOrCallback(currentState);
2469
- }
2470
- else {
2471
- newState = stateOrCallback;
2472
- }
2473
- const withHook = this.akitaPreUpdate(currentState, Object.assign({}, currentState, newState));
2474
- const resolved = isPlainObject(currentState) ? withHook : new currentState.constructor(withHook);
2475
- this._setState(resolved);
2476
- }
2477
- updateStoreConfig(newOptions) {
2478
- this.options = Object.assign({}, this.options, newOptions);
2479
- }
2480
- // @internal
2481
- akitaPreUpdate(_, nextState) {
2482
- return nextState;
2483
- }
2484
- ngOnDestroy() {
2485
- this.destroy();
2486
- }
2487
- /**
2488
- *
2489
- * Destroy the store
2490
- *
2491
- * @example
2492
- *
2493
- * store.destroy()
2494
- *
2495
- */
2496
- destroy() {
2497
- const hmrEnabled = isBrowser ? window.hmrEnabled : false;
2498
- if (!hmrEnabled && this === __stores__[this.storeName]) {
2499
- delete __stores__[this.storeName];
2500
- dispatchDeleted(this.storeName);
2501
- this.setHasCache(false);
2502
- this.cache.active.complete();
2503
- this.store.complete();
2504
- }
2505
- }
2506
- onInit(initialState) {
2507
- __stores__[this.storeName] = this;
2508
- this._setState(() => initialState);
2509
- dispatchAdded(this.storeName);
2510
- if (this.isResettable()) {
2511
- this._initialState = initialState;
2512
- }
2513
- isDev() && assertStoreHasName(this.storeName, this.constructor.name);
2514
- }
2515
- dispatch(state, _dispatchAction = true) {
2516
- let action = undefined;
2517
- if (_dispatchAction) {
2518
- action = currentAction;
2519
- resetCustomAction();
2520
- }
2521
- this.store.next({ state, action });
2522
- }
2523
- watchTransaction() {
2524
- commit().subscribe(() => {
2525
- this.inTransaction = false;
2526
- this.dispatch(this._value());
2527
- });
2528
- }
2529
- isResettable() {
2530
- if (this.resettable === false) {
2531
- return false;
2532
- }
2533
- return this.resettable || getAkitaConfig().resettable;
2534
- }
2535
- handleTransaction() {
2536
- if (!this.inTransaction) {
2537
- this.watchTransaction();
2538
- this.inTransaction = true;
2539
- }
2540
- }
2541
- getCacheTTL() {
2542
- return (this.cacheConfig && this.cacheConfig.ttl) || getAkitaConfig().ttl;
2543
- }
2544
- }
2545
-
2546
- // @internal
2547
- function updateEntities({ state, ids, idKey, newStateOrFn, preUpdateEntity, producerFn, onEntityIdChanges }) {
2548
- const updatedEntities = {};
2549
- let isUpdatingIdKey = false;
2550
- let idToUpdate;
2551
- for (const id of ids) {
2552
- // if the entity doesn't exist don't do anything
2553
- if (hasEntity(state.entities, id) === false) {
2554
- continue;
2555
- }
2556
- const oldEntity = state.entities[id];
2557
- let newState;
2558
- if (isFunction$1(newStateOrFn)) {
2559
- newState = isFunction$1(producerFn) ? producerFn(oldEntity, newStateOrFn) : newStateOrFn(oldEntity);
2560
- }
2561
- else {
2562
- newState = newStateOrFn;
2563
- }
2564
- const isIdChanged = newState.hasOwnProperty(idKey) && newState[idKey] !== oldEntity[idKey];
2565
- let newEntity;
2566
- idToUpdate = id;
2567
- if (isIdChanged) {
2568
- isUpdatingIdKey = true;
2569
- idToUpdate = newState[idKey];
2570
- }
2571
- const merged = Object.assign({}, oldEntity, newState);
2572
- if (isPlainObject(oldEntity)) {
2573
- newEntity = merged;
2574
- }
2575
- else {
2576
- /**
2577
- * In case that new state is class of it's own, there's
2578
- * a possibility that it will be different than the old
2579
- * class.
2580
- * For example, Old state is an instance of animal class
2581
- * and new state is instance of person class.
2582
- * To avoid run over new person class with the old animal
2583
- * class we check if the new state is a class of it's own.
2584
- * If so, use it. Otherwise, use the old state class
2585
- */
2586
- if (isPlainObject(newState)) {
2587
- newEntity = new oldEntity.constructor(merged);
2588
- }
2589
- else {
2590
- newEntity = new newState.constructor(merged);
2591
- }
2592
- }
2593
- updatedEntities[idToUpdate] = preUpdateEntity(oldEntity, newEntity);
2594
- }
2595
- let updatedIds = state.ids;
2596
- let stateEntities = state.entities;
2597
- if (isUpdatingIdKey) {
2598
- const [id] = ids;
2599
- const _a = state.entities, _b = id, rest = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
2600
- stateEntities = rest;
2601
- updatedIds = state.ids.map((current) => (current === id ? idToUpdate : current));
2602
- onEntityIdChanges(id, idToUpdate);
2603
- }
2604
- return Object.assign({}, state, { entities: Object.assign({}, stateEntities, updatedEntities), ids: updatedIds });
2605
- }
2606
-
2607
- var _b;
2608
- /**
2609
- *
2610
- * Store for managing a collection of entities
2611
- *
2612
- * @example
2613
- *
2614
- * export interface WidgetsState extends EntityState<Widget> { }
2615
- *
2616
- * @StoreConfig({ name: 'widgets' })
2617
- * export class WidgetsStore extends EntityStore<WidgetsState> {
2618
- * constructor() {
2619
- * super();
2620
- * }
2621
- * }
2622
- *
2623
- *
2624
- */
2625
- class EntityStore extends Store {
2626
- constructor(initialState = {}, options = {}) {
2627
- super(Object.assign({}, getInitialEntitiesState(), initialState), options);
2628
- this.options = options;
2629
- this.entityActions = new Subject();
2630
- this.entityIdChanges = new Subject();
2631
- }
2632
- // @internal
2633
- get selectEntityAction$() {
2634
- return this.entityActions.asObservable();
2635
- }
2636
- // @internal
2637
- get selectEntityIdChanges$() {
2638
- return this.entityIdChanges.asObservable();
2639
- }
2640
- // @internal
2641
- get idKey() {
2642
- return this.config.idKey || this.options.idKey || DEFAULT_ID_KEY;
2643
- }
2644
- /**
2645
- *
2646
- * Replace current collection with provided collection
2647
- *
2648
- * @example
2649
- *
2650
- * this.store.set([Entity, Entity])
2651
- * this.store.set({ids: [], entities: {}})
2652
- * this.store.set({ 1: {}, 2: {}})
2653
- *
2654
- */
2655
- set(entities, options = {}) {
2656
- if (isNil(entities))
2657
- return;
2658
- isDev() && setAction('Set Entity');
2659
- const isNativePreAdd = this.akitaPreAddEntity === EntityStore.prototype.akitaPreAddEntity;
2660
- this.setHasCache(true, { restartTTL: true });
2661
- this._setState((state) => {
2662
- const newState = setEntities({
2663
- state,
2664
- entities,
2665
- idKey: this.idKey,
2666
- preAddEntity: this.akitaPreAddEntity,
2667
- isNativePreAdd,
2668
- });
2669
- if (isUndefined(options.activeId) === false) {
2670
- newState.active = options.activeId;
2671
- }
2672
- return newState;
2673
- });
2674
- if (this.hasInitialUIState()) {
2675
- this.handleUICreation();
2676
- }
2677
- this.entityActions.next({ type: EntityActions.Set, ids: this.ids });
2678
- }
2679
- /**
2680
- * Add entities
2681
- *
2682
- * @example
2683
- *
2684
- * this.store.add([Entity, Entity])
2685
- * this.store.add(Entity)
2686
- * this.store.add(Entity, { prepend: true })
2687
- *
2688
- * this.store.add(Entity, { loading: false })
2689
- */
2690
- add(entities, options = { loading: false }) {
2691
- const collection = coerceArray(entities);
2692
- if (isEmpty(collection))
2693
- return;
2694
- const data = addEntities({
2695
- state: this._value(),
2696
- preAddEntity: this.akitaPreAddEntity,
2697
- entities: collection,
2698
- idKey: this.idKey,
2699
- options,
2700
- });
2701
- if (data) {
2702
- isDev() && setAction('Add Entity');
2703
- data.newState.loading = options.loading;
2704
- this._setState(() => data.newState);
2705
- if (this.hasInitialUIState()) {
2706
- this.handleUICreation(true);
2707
- }
2708
- this.entityActions.next({ type: EntityActions.Add, ids: data.newIds });
2709
- }
2710
- }
2711
- update(idsOrFnOrState, newStateOrFn) {
2712
- if (isUndefined(newStateOrFn)) {
2713
- super.update(idsOrFnOrState);
2714
- return;
2715
- }
2716
- let ids = [];
2717
- if (isFunction$1(idsOrFnOrState)) {
2718
- // We need to filter according the predicate function
2719
- ids = this.ids.filter((id) => idsOrFnOrState(this.entities[id]));
2720
- }
2721
- else {
2722
- // If it's nil we want all of them
2723
- ids = isNil(idsOrFnOrState) ? this.ids : coerceArray(idsOrFnOrState);
2724
- }
2725
- if (isEmpty(ids))
2726
- return;
2727
- isDev() && setAction('Update Entity', ids);
2728
- let entityIdChanged;
2729
- this._setState((state) => updateEntities({
2730
- idKey: this.idKey,
2731
- ids,
2732
- preUpdateEntity: this.akitaPreUpdateEntity,
2733
- state,
2734
- newStateOrFn,
2735
- producerFn: this._producerFn,
2736
- onEntityIdChanges: (oldId, newId) => {
2737
- entityIdChanged = { oldId, newId };
2738
- this.entityIdChanges.next(Object.assign({}, entityIdChanged, { pending: true }));
2739
- },
2740
- }));
2741
- if (entityIdChanged) {
2742
- this.entityIdChanges.next(Object.assign({}, entityIdChanged, { pending: false }));
2743
- }
2744
- this.entityActions.next({ type: EntityActions.Update, ids });
2745
- }
2746
- upsert(ids, newState, onCreate, options = {}) {
2747
- const toArray = coerceArray(ids);
2748
- const predicate = (isUpdate) => (id) => hasEntity(this.entities, id) === isUpdate;
2749
- const baseClass = isFunction$1(onCreate) ? options.baseClass : onCreate ? onCreate.baseClass : undefined;
2750
- const isClassBased = isFunction$1(baseClass);
2751
- const updateIds = toArray.filter(predicate(true));
2752
- const newEntities = toArray.filter(predicate(false)).map((id) => {
2753
- const newStateObj = typeof newState === 'function' ? newState({}) : newState;
2754
- const entity = isFunction$1(onCreate) ? onCreate(id, newStateObj) : newStateObj;
2755
- const withId = Object.assign({}, entity, { [this.idKey]: id });
2756
- if (isClassBased) {
2757
- return new baseClass(withId);
2758
- }
2759
- return withId;
2760
- });
2761
- // it can be any of the three types
2762
- this.update(updateIds, newState);
2763
- this.add(newEntities);
2764
- isDev() && logAction('Upsert Entity');
2765
- }
2766
- /**
2767
- *
2768
- * Upsert entity collection (idKey must be present)
2769
- *
2770
- * @example
2771
- *
2772
- * store.upsertMany([ { id: 1 }, { id: 2 }]);
2773
- *
2774
- * store.upsertMany([ { id: 1 }, { id: 2 }], { loading: true });
2775
- * store.upsertMany([ { id: 1 }, { id: 2 }], { baseClass: Todo });
2776
- *
2777
- */
2778
- upsertMany(entities, options = {}) {
2779
- const addedIds = [];
2780
- const updatedIds = [];
2781
- const updatedEntities = {};
2782
- // Update the state directly to optimize performance
2783
- for (const entity of entities) {
2784
- const withPreCheckHook = this.akitaPreCheckEntity(entity);
2785
- const id = withPreCheckHook[this.idKey];
2786
- if (hasEntity(this.entities, id)) {
2787
- const prev = this._value().entities[id];
2788
- const merged = Object.assign({}, this._value().entities[id], withPreCheckHook);
2789
- const next = options.baseClass ? new options.baseClass(merged) : merged;
2790
- const withHook = this.akitaPreUpdateEntity(prev, next);
2791
- const nextId = withHook[this.idKey];
2792
- updatedEntities[nextId] = withHook;
2793
- updatedIds.push(nextId);
2794
- }
2795
- else {
2796
- const newEntity = options.baseClass ? new options.baseClass(withPreCheckHook) : withPreCheckHook;
2797
- const withHook = this.akitaPreAddEntity(newEntity);
2798
- const nextId = withHook[this.idKey];
2799
- addedIds.push(nextId);
2800
- updatedEntities[nextId] = withHook;
2801
- }
2802
- }
2803
- isDev() && logAction('Upsert Many');
2804
- this._setState((state) => (Object.assign({}, state, { ids: addedIds.length ? [...state.ids, ...addedIds] : state.ids, entities: Object.assign({}, state.entities, updatedEntities), loading: !!options.loading })));
2805
- updatedIds.length && this.entityActions.next({ type: EntityActions.Update, ids: updatedIds });
2806
- addedIds.length && this.entityActions.next({ type: EntityActions.Add, ids: addedIds });
2807
- if (addedIds.length && this.hasUIStore()) {
2808
- this.handleUICreation(true);
2809
- }
2810
- }
2811
- /**
2812
- *
2813
- * Replace one or more entities (except the id property)
2814
- *
2815
- *
2816
- * @example
2817
- *
2818
- * this.store.replace(5, newEntity)
2819
- * this.store.replace([1,2,3], newEntity)
2820
- */
2821
- replace(ids, newState) {
2822
- const toArray = coerceArray(ids);
2823
- if (isEmpty(toArray))
2824
- return;
2825
- let replaced = {};
2826
- for (const id of toArray) {
2827
- newState[this.idKey] = id;
2828
- replaced[id] = newState;
2829
- }
2830
- isDev() && setAction('Replace Entity', ids);
2831
- this._setState((state) => (Object.assign({}, state, { entities: Object.assign({}, state.entities, replaced) })));
2832
- }
2833
- /**
2834
- *
2835
- * Move entity inside the collection
2836
- *
2837
- *
2838
- * @example
2839
- *
2840
- * this.store.move(fromIndex, toIndex)
2841
- */
2842
- move(from, to) {
2843
- const ids = this.ids.slice();
2844
- ids.splice(to < 0 ? ids.length + to : to, 0, ids.splice(from, 1)[0]);
2845
- isDev() && setAction('Move Entity');
2846
- this._setState((state) => (Object.assign({}, state, {
2847
- // Change the entities reference so that selectAll emit
2848
- entities: Object.assign({}, state.entities), ids })));
2849
- }
2850
- remove(idsOrFn) {
2851
- if (isEmpty(this.ids))
2852
- return;
2853
- const idPassed = isDefined(idsOrFn);
2854
- // null means remove all
2855
- let ids = [];
2856
- if (isFunction$1(idsOrFn)) {
2857
- ids = this.ids.filter((entityId) => idsOrFn(this.entities[entityId]));
2858
- }
2859
- else {
2860
- ids = idPassed ? coerceArray(idsOrFn) : this.ids;
2861
- }
2862
- if (isEmpty(ids))
2863
- return;
2864
- isDev() && setAction('Remove Entity', ids);
2865
- this._setState((state) => removeEntities({ state, ids }));
2866
- if (!idPassed) {
2867
- this.setHasCache(false);
2868
- }
2869
- this.handleUIRemove(ids);
2870
- this.entityActions.next({ type: EntityActions.Remove, ids });
2871
- }
2872
- /**
2873
- *
2874
- * Update the active entity
2875
- *
2876
- * @example
2877
- *
2878
- * this.store.updateActive({ completed: true })
2879
- * this.store.updateActive(active => {
2880
- * return {
2881
- * config: {
2882
- * ..active.config,
2883
- * date
2884
- * }
2885
- * }
2886
- * })
2887
- */
2888
- updateActive(newStateOrCallback) {
2889
- const ids = coerceArray(this.active);
2890
- isDev() && setAction('Update Active', ids);
2891
- this.update(ids, newStateOrCallback);
2892
- }
2893
- setActive(idOrOptions) {
2894
- const active = getActiveEntities(idOrOptions, this.ids, this.active);
2895
- if (active === undefined) {
2896
- return;
2897
- }
2898
- isDev() && setAction('Set Active', active);
2899
- this._setActive(active);
2900
- }
2901
- /**
2902
- * Add active entities
2903
- *
2904
- * @example
2905
- *
2906
- * store.addActive(2);
2907
- * store.addActive([3, 4, 5]);
2908
- */
2909
- addActive(ids) {
2910
- const toArray = coerceArray(ids);
2911
- if (isEmpty(toArray))
2912
- return;
2913
- const everyExist = toArray.every((id) => this.active.indexOf(id) > -1);
2914
- if (everyExist)
2915
- return;
2916
- isDev() && setAction('Add Active', ids);
2917
- this._setState((state) => {
2918
- /** Protect against case that one of the items in the array exist */
2919
- const uniques = Array.from(new Set([...state.active, ...toArray]));
2920
- return Object.assign({}, state, { active: uniques });
2921
- });
2922
- }
2923
- /**
2924
- * Remove active entities
2925
- *
2926
- * @example
2927
- *
2928
- * store.removeActive(2)
2929
- * store.removeActive([3, 4, 5])
2930
- */
2931
- removeActive(ids) {
2932
- const toArray = coerceArray(ids);
2933
- if (isEmpty(toArray))
2934
- return;
2935
- const someExist = toArray.some((id) => this.active.indexOf(id) > -1);
2936
- if (!someExist)
2937
- return;
2938
- isDev() && setAction('Remove Active', ids);
2939
- this._setState((state) => {
2940
- return Object.assign({}, state, { active: Array.isArray(state.active) ? state.active.filter((currentId) => toArray.indexOf(currentId) === -1) : null });
2941
- });
2942
- }
2943
- /**
2944
- * Toggle active entities
2945
- *
2946
- * @example
2947
- *
2948
- * store.toggle(2)
2949
- * store.toggle([3, 4, 5])
2950
- */
2951
- toggleActive(ids) {
2952
- const toArray = coerceArray(ids);
2953
- const filterExists = (remove) => (id) => this.active.includes(id) === remove;
2954
- const remove = toArray.filter(filterExists(true));
2955
- const add = toArray.filter(filterExists(false));
2956
- this.removeActive(remove);
2957
- this.addActive(add);
2958
- isDev() && logAction('Toggle Active');
2959
- }
2960
- /**
2961
- *
2962
- * Create sub UI store for managing Entity's UI state
2963
- *
2964
- * @example
2965
- *
2966
- * export type ProductUI = {
2967
- * isLoading: boolean;
2968
- * isOpen: boolean
2969
- * }
2970
- *
2971
- * interface ProductsUIState extends EntityState<ProductUI> {}
2972
- *
2973
- * export class ProductsStore EntityStore<ProductsState, Product> {
2974
- * ui: EntityUIStore<ProductsUIState, ProductUI>;
2975
- *
2976
- * constructor() {
2977
- * super();
2978
- * this.createUIStore();
2979
- * }
2980
- *
2981
- * }
2982
- */
2983
- createUIStore(initialState = {}, storeConfig = {}) {
2984
- const defaults = { name: `UI/${this.storeName}`, idKey: this.idKey };
2985
- this.ui = new EntityUIStore(initialState, Object.assign({}, defaults, storeConfig));
2986
- return this.ui;
2987
- }
2988
- // @internal
2989
- destroy() {
2990
- super.destroy();
2991
- if (this.ui instanceof EntityStore) {
2992
- this.ui.destroy();
2993
- }
2994
- this.entityActions.complete();
2995
- }
2996
- // @internal
2997
- akitaPreUpdateEntity(_, nextEntity) {
2998
- return nextEntity;
2999
- }
3000
- // @internal
3001
- akitaPreAddEntity(newEntity) {
3002
- return newEntity;
3003
- }
3004
- // @internal
3005
- akitaPreCheckEntity(newEntity) {
3006
- return newEntity;
3007
- }
3008
- get ids() {
3009
- return this._value().ids;
3010
- }
3011
- get entities() {
3012
- return this._value().entities;
3013
- }
3014
- get active() {
3015
- return this._value().active;
3016
- }
3017
- _setActive(ids) {
3018
- this._setState((state) => {
3019
- return Object.assign({}, state, { active: ids });
3020
- });
3021
- }
3022
- handleUICreation(add = false) {
3023
- const ids = this.ids;
3024
- const isFunc = isFunction$1(this.ui._akitaCreateEntityFn);
3025
- let uiEntities;
3026
- const createFn = (id) => {
3027
- const current = this.entities[id];
3028
- const ui = isFunc ? this.ui._akitaCreateEntityFn(current) : this.ui._akitaCreateEntityFn;
3029
- return Object.assign({ [this.idKey]: current[this.idKey] }, ui);
3030
- };
3031
- if (add) {
3032
- uiEntities = this.ids.filter((id) => isUndefined(this.ui.entities[id])).map(createFn);
3033
- }
3034
- else {
3035
- uiEntities = ids.map(createFn);
3036
- }
3037
- add ? this.ui.add(uiEntities) : this.ui.set(uiEntities);
3038
- }
3039
- hasInitialUIState() {
3040
- return this.hasUIStore() && isUndefined(this.ui._akitaCreateEntityFn) === false;
3041
- }
3042
- handleUIRemove(ids) {
3043
- if (this.hasUIStore()) {
3044
- this.ui.remove(ids);
3045
- }
3046
- }
3047
- hasUIStore() {
3048
- return this.ui instanceof EntityUIStore;
3049
- }
3050
- }
3051
- __decorate([
3052
- transaction(),
3053
- __metadata("design:type", Function),
3054
- __metadata("design:paramtypes", [Object, Object, Object, Object]),
3055
- __metadata("design:returntype", void 0)
3056
- ], EntityStore.prototype, "upsert", null);
3057
- __decorate([
3058
- transaction(),
3059
- __metadata("design:type", Function),
3060
- __metadata("design:paramtypes", [typeof (_b = typeof T !== "undefined" && T) === "function" ? _b : Object]),
3061
- __metadata("design:returntype", void 0)
3062
- ], EntityStore.prototype, "toggleActive", null);
3063
- // @internal
3064
- class EntityUIStore extends EntityStore {
3065
- constructor(initialState = {}, storeConfig = {}) {
3066
- super(initialState, storeConfig);
3067
- }
3068
- /**
3069
- *
3070
- * Set the initial UI entity state. This function will determine the entity's
3071
- * initial state when we call `set()` or `add()`.
3072
- *
3073
- * @example
3074
- *
3075
- * constructor() {
3076
- * super();
3077
- * this.createUIStore().setInitialEntityState(entity => ({ isLoading: false, isOpen: true }));
3078
- * this.createUIStore().setInitialEntityState({ isLoading: false, isOpen: true });
3079
- * }
3080
- *
3081
- */
3082
- setInitialEntityState(createFn) {
3083
- this._akitaCreateEntityFn = createFn;
3084
- }
3085
- }
3086
-
3087
- var Order;
3088
- (function (Order) {
3089
- Order["ASC"] = "asc";
3090
- Order["DESC"] = "desc";
3091
- })(Order || (Order = {}));
3092
-
3093
- // @internal
3094
- function isString(value) {
3095
- return typeof value === 'string';
3096
- }
3097
-
3098
- const queryConfigKey = 'akitaQueryConfig';
3099
-
3100
- function compareKeys(keysOrFuncs) {
3101
- return function (prevState, currState) {
3102
- const isFns = isFunction$1(keysOrFuncs[0]);
3103
- // Return when they are NOT changed
3104
- return keysOrFuncs.some(keyOrFunc => {
3105
- if (isFns) {
3106
- return keyOrFunc(prevState) !== keyOrFunc(currState);
3107
- }
3108
- return prevState[keyOrFunc] !== currState[keyOrFunc];
3109
- }) === false;
3110
- };
3111
- }
3112
-
3113
- class Query {
3114
- constructor(store) {
3115
- this.store = store;
3116
- this.__store__ = store;
3117
- if (isDev()) {
3118
- // @internal
3119
- __queries__[store.storeName] = this;
3120
- }
3121
- }
3122
- select(project) {
3123
- let mapFn;
3124
- if (isFunction$1(project)) {
3125
- mapFn = project;
3126
- }
3127
- else if (isString(project)) {
3128
- mapFn = state => state[project];
3129
- }
3130
- else if (Array.isArray(project)) {
3131
- return this.store
3132
- ._select(state => state)
3133
- .pipe(distinctUntilChanged(compareKeys(project)), map(state => {
3134
- if (isFunction$1(project[0])) {
3135
- return project.map(func => func(state));
3136
- }
3137
- return project.reduce((acc, k) => {
3138
- acc[k] = state[k];
3139
- return acc;
3140
- }, {});
3141
- }));
3142
- }
3143
- else {
3144
- mapFn = state => state;
3145
- }
3146
- return this.store._select(mapFn);
3147
- }
3148
- /**
3149
- * Select the loading state
3150
- *
3151
- * @example
3152
- *
3153
- * this.query.selectLoading().subscribe(isLoading => {})
3154
- */
3155
- selectLoading() {
3156
- return this.select(state => state.loading);
3157
- }
3158
- /**
3159
- * Select the error state
3160
- *
3161
- * @example
3162
- *
3163
- * this.query.selectError().subscribe(error => {})
3164
- */
3165
- selectError() {
3166
- return this.select(state => state.error);
3167
- }
3168
- /**
3169
- * Get the store's value
3170
- *
3171
- * @example
3172
- *
3173
- * this.query.getValue()
3174
- *
3175
- */
3176
- getValue() {
3177
- return this.store._value();
3178
- }
3179
- /**
3180
- * Select the cache state
3181
- *
3182
- * @example
3183
- *
3184
- * this.query.selectHasCache().pipe(
3185
- * switchMap(hasCache => {
3186
- * return hasCache ? of() : http().pipe(res => store.set(res))
3187
- * })
3188
- * )
3189
- */
3190
- selectHasCache() {
3191
- return this.store._cache().asObservable();
3192
- }
3193
- /**
3194
- * Whether we've cached data
3195
- *
3196
- * @example
3197
- *
3198
- * this.query.getHasCache()
3199
- *
3200
- */
3201
- getHasCache() {
3202
- return this.store._cache().value;
3203
- }
3204
- // @internal
3205
- get config() {
3206
- return this.constructor[queryConfigKey];
3207
- }
3208
- }
3209
-
3210
- /**
3211
- * @example
3212
- *
3213
- * query.selectEntity(2).pipe(filterNil)
3214
- */
3215
- const filterNil = (source) => source.pipe(filter((value) => value !== null && typeof value !== 'undefined'));
3216
-
3217
- /**
3218
- * @internal
3219
- *
3220
- * @example
3221
- *
3222
- * getValue(state, 'todos.ui')
3223
- *
3224
- */
3225
- function getValue(obj, prop) {
3226
- /** return the whole state */
3227
- if (prop.split('.').length === 1) {
3228
- return obj;
3229
- }
3230
- const removeStoreName = prop
3231
- .split('.')
3232
- .slice(1)
3233
- .join('.');
3234
- return removeStoreName.split('.').reduce((acc, part) => acc && acc[part], obj);
3235
- }
3236
-
3237
- /**
3238
- * @internal
3239
- *
3240
- * @example
3241
- * setValue(state, 'todos.ui', { filter: {} })
3242
- */
3243
- function setValue(obj, prop, val) {
3244
- const split = prop.split('.');
3245
- if (split.length === 1) {
3246
- return Object.assign({}, obj, val);
3247
- }
3248
- obj = Object.assign({}, obj);
3249
- const lastIndex = split.length - 2;
3250
- const removeStoreName = prop.split('.').slice(1);
3251
- removeStoreName.reduce((acc, part, index) => {
3252
- if (index !== lastIndex) {
3253
- acc[part] = Object.assign({}, acc[part]);
3254
- return acc && acc[part];
3255
- }
3256
- acc[part] = Array.isArray(acc[part]) || !isObject$1(acc[part]) ? val : Object.assign({}, acc[part], val);
3257
- return acc && acc[part];
3258
- }, obj);
3259
- return obj;
3260
- }
3261
- const _persistStateInit = new ReplaySubject(1);
3262
-
3263
- class AkitaPlugin {
3264
- constructor(query, config) {
3265
- this.query = query;
3266
- if (config && config.resetFn) {
3267
- if (getAkitaConfig().resettable) {
3268
- this.onReset(config.resetFn);
3269
- }
3270
- }
3271
- }
3272
- /** This method is responsible for getting access to the query. */
3273
- getQuery() {
3274
- return this.query;
3275
- }
3276
- /** This method is responsible for getting access to the store. */
3277
- getStore() {
3278
- return this.getQuery().__store__;
3279
- }
3280
- /** This method is responsible tells whether the plugin is entityBased or not. */
3281
- isEntityBased(entityId) {
3282
- return toBoolean(entityId);
3283
- }
3284
- /** This method is responsible for selecting the source; it can be the whole store or one entity. */
3285
- selectSource(entityId, property) {
3286
- if (this.isEntityBased(entityId)) {
3287
- return this.getQuery().selectEntity(entityId).pipe(filterNil);
3288
- }
3289
- if (property) {
3290
- return this.getQuery().select(state => getValue(state, this.withStoreName(property)));
3291
- }
3292
- return this.getQuery().select();
3293
- }
3294
- getSource(entityId, property) {
3295
- if (this.isEntityBased(entityId)) {
3296
- return this.getQuery().getEntity(entityId);
3297
- }
3298
- const state = this.getQuery().getValue();
3299
- if (property) {
3300
- return getValue(state, this.withStoreName(property));
3301
- }
3302
- return state;
3303
- }
3304
- withStoreName(prop) {
3305
- return `${this.storeName}.${prop}`;
3306
- }
3307
- get storeName() {
3308
- return this.getStore().storeName;
3309
- }
3310
- /** This method is responsible for updating the store or one entity; it can be the whole store or one entity. */
3311
- updateStore(newState, entityId, property) {
3312
- if (this.isEntityBased(entityId)) {
3313
- this.getStore().update(entityId, newState);
3314
- }
3315
- else {
3316
- if (property) {
3317
- this.getStore()._setState(state => {
3318
- return setValue(state, this.withStoreName(property), newState);
3319
- });
3320
- return;
3321
- }
3322
- this.getStore()._setState(state => (Object.assign({}, state, newState)));
3323
- }
3324
- }
3325
- /**
3326
- * Function to invoke upon reset
3327
- */
3328
- onReset(fn) {
3329
- const original = this.getStore().reset;
3330
- this.getStore().reset = (...params) => {
3331
- /** It should run after the plugin destroy method */
3332
- setTimeout(() => {
3333
- original.apply(this.getStore(), params);
3334
- fn();
3335
- });
3336
- };
3337
- }
3338
- }
3339
-
3340
- const paginatorDefaults = {
3341
- pagesControls: false,
3342
- range: false,
3343
- startWith: 1,
3344
- cacheTimeout: undefined,
3345
- clearStoreWithCache: true
3346
- };
3347
- class PaginatorPlugin extends AkitaPlugin {
3348
- constructor(query, config = {}) {
3349
- super(query, {
3350
- resetFn: () => {
3351
- this.initial = false;
3352
- this.destroy({ clearCache: true, currentPage: 1 });
3353
- }
3354
- });
3355
- this.query = query;
3356
- this.config = config;
3357
- /** Save current filters, sorting, etc. in cache */
3358
- this.metadata = new Map();
3359
- this.pages = new Map();
3360
- this.pagination = {
3361
- currentPage: 1,
3362
- perPage: 0,
3363
- total: 0,
3364
- lastPage: 0,
3365
- data: []
3366
- };
3367
- /**
3368
- * When the user navigates to a different page and return
3369
- * we don't want to call `clearCache` on first time.
3370
- */
3371
- this.initial = true;
3372
- /**
3373
- * Proxy to the query loading
3374
- */
3375
- this.isLoading$ = this.query.selectLoading().pipe(delay(0));
3376
- this.config = Object.assign(paginatorDefaults, config);
3377
- const { startWith, cacheTimeout } = this.config;
3378
- this.page = new BehaviorSubject(startWith);
3379
- if (isObservable(cacheTimeout)) {
3380
- this.clearCacheSubscription = cacheTimeout.subscribe(() => this.clearCache());
3381
- }
3382
- }
3383
- /**
3384
- * Listen to page changes
3385
- */
3386
- get pageChanges() {
3387
- return this.page.asObservable();
3388
- }
3389
- /**
3390
- * Get the current page number
3391
- */
3392
- get currentPage() {
3393
- return this.pagination.currentPage;
3394
- }
3395
- /**
3396
- * Check if current page is the first one
3397
- */
3398
- get isFirst() {
3399
- return this.currentPage === 1;
3400
- }
3401
- /**
3402
- * Check if current page is the last one
3403
- */
3404
- get isLast() {
3405
- return this.currentPage === this.pagination.lastPage;
3406
- }
3407
- /**
3408
- * Whether to generate an array of pages for *ngFor
3409
- * [1, 2, 3, 4]
3410
- */
3411
- withControls() {
3412
- this.config.pagesControls = true;
3413
- return this;
3414
- }
3415
- /**
3416
- * Whether to generate the `from` and `to` keys
3417
- * [1, 2, 3, 4]
3418
- */
3419
- withRange() {
3420
- this.config.range = true;
3421
- return this;
3422
- }
3423
- /**
3424
- * Set the loading state
3425
- */
3426
- setLoading(value = true) {
3427
- this.getStore().setLoading(value);
3428
- }
3429
- /**
3430
- * Update the pagination object and add the page
3431
- */
3432
- update(response) {
3433
- this.pagination = response;
3434
- this.addPage(response.data);
3435
- }
3436
- /**
3437
- *
3438
- * Set the ids and add the page to store
3439
- */
3440
- addPage(data) {
3441
- this.pages.set(this.currentPage, { ids: data.map(entity => entity[this.getStore().idKey]) });
3442
- this.getStore().upsertMany(data);
3443
- }
3444
- /**
3445
- * Clear the cache.
3446
- */
3447
- clearCache(options = {}) {
3448
- if (!this.initial) {
3449
- logAction('@Pagination - Clear Cache');
3450
- if (options.clearStore !== false && (this.config.clearStoreWithCache || options.clearStore)) {
3451
- this.getStore().remove();
3452
- }
3453
- this.pages = new Map();
3454
- this.metadata = new Map();
3455
- }
3456
- this.initial = false;
3457
- }
3458
- clearPage(page) {
3459
- this.pages.delete(page);
3460
- }
3461
- /**
3462
- * Clear the cache timeout and optionally the pages
3463
- */
3464
- destroy({ clearCache, currentPage } = {}) {
3465
- if (this.clearCacheSubscription) {
3466
- this.clearCacheSubscription.unsubscribe();
3467
- }
3468
- if (clearCache) {
3469
- this.clearCache();
3470
- }
3471
- if (!isUndefined(currentPage)) {
3472
- this.setPage(currentPage);
3473
- }
3474
- this.initial = true;
3475
- }
3476
- /**
3477
- * Whether the provided page is active
3478
- */
3479
- isPageActive(page) {
3480
- return this.currentPage === page;
3481
- }
3482
- /**
3483
- * Set the current page
3484
- */
3485
- setPage(page) {
3486
- if (page !== this.currentPage || !this.hasPage(page)) {
3487
- this.page.next((this.pagination.currentPage = page));
3488
- }
3489
- }
3490
- /**
3491
- * Increment current page
3492
- */
3493
- nextPage() {
3494
- if (this.currentPage !== this.pagination.lastPage) {
3495
- this.setPage(this.pagination.currentPage + 1);
3496
- }
3497
- }
3498
- /**
3499
- * Decrement current page
3500
- */
3501
- prevPage() {
3502
- if (this.pagination.currentPage > 1) {
3503
- this.setPage(this.pagination.currentPage - 1);
3504
- }
3505
- }
3506
- /**
3507
- * Set current page to last
3508
- */
3509
- setLastPage() {
3510
- this.setPage(this.pagination.lastPage);
3511
- }
3512
- /**
3513
- * Set current page to first
3514
- */
3515
- setFirstPage() {
3516
- this.setPage(1);
3517
- }
3518
- /**
3519
- * Check if page exists in cache
3520
- */
3521
- hasPage(page) {
3522
- return this.pages.has(page);
3523
- }
3524
- /**
3525
- * Get the current page if it's in cache, otherwise invoke the request
3526
- */
3527
- getPage(req) {
3528
- let page = this.pagination.currentPage;
3529
- if (this.hasPage(page)) {
3530
- return this.selectPage(page);
3531
- }
3532
- else {
3533
- this.setLoading(true);
3534
- return from(req()).pipe(switchMap((config) => {
3535
- page = config.currentPage;
3536
- applyTransaction(() => {
3537
- this.setLoading(false);
3538
- this.update(config);
3539
- });
3540
- return this.selectPage(page);
3541
- }));
3542
- }
3543
- }
3544
- getQuery() {
3545
- return this.query;
3546
- }
3547
- refreshCurrentPage() {
3548
- if (isNil(this.currentPage) === false) {
3549
- this.clearPage(this.currentPage);
3550
- this.setPage(this.currentPage);
3551
- }
3552
- }
3553
- getFrom() {
3554
- if (this.isFirst) {
3555
- return 1;
3556
- }
3557
- return (this.currentPage - 1) * this.pagination.perPage + 1;
3558
- }
3559
- getTo() {
3560
- if (this.isLast) {
3561
- return this.pagination.total;
3562
- }
3563
- return this.currentPage * this.pagination.perPage;
3564
- }
3565
- /**
3566
- * Select the page
3567
- */
3568
- selectPage(page) {
3569
- return this.query.selectAll({ asObject: true }).pipe(take(1), map(entities => {
3570
- let response = Object.assign({}, this.pagination, { data: this.pages.get(page).ids.map(id => entities[id]) });
3571
- const { range, pagesControls } = this.config;
3572
- /** If no total - calc it */
3573
- if (isNaN(this.pagination.total)) {
3574
- if (response.lastPage === 1) {
3575
- response.total = response.data ? response.data.length : 0;
3576
- }
3577
- else {
3578
- response.total = response.perPage * response.lastPage;
3579
- }
3580
- this.pagination.total = response.total;
3581
- }
3582
- if (range) {
3583
- response.from = this.getFrom();
3584
- response.to = this.getTo();
3585
- }
3586
- if (pagesControls) {
3587
- response.pageControls = generatePages(this.pagination.total, this.pagination.perPage);
3588
- }
3589
- return response;
3590
- }));
3591
- }
3592
- }
3593
- __decorate([
3594
- action('@Pagination - New Page'),
3595
- __metadata("design:type", Function),
3596
- __metadata("design:paramtypes", [Object]),
3597
- __metadata("design:returntype", void 0)
3598
- ], PaginatorPlugin.prototype, "update", null);
3599
- /**
3600
- * Generate an array so we can ngFor them to navigate between pages
3601
- */
3602
- function generatePages(total, perPage) {
3603
- const len = Math.ceil(total / perPage);
3604
- let arr = [];
3605
- for (let i = 0; i < len; i++) {
3606
- arr.push(i + 1);
3607
- }
3608
- return arr;
3609
- }
3610
-
3611
- var StoreAction;
3612
- (function (StoreAction) {
3613
- StoreAction["Update"] = "UPDATE";
3614
- })(StoreAction || (StoreAction = {}));
3615
- var EntityStoreAction;
3616
- (function (EntityStoreAction) {
3617
- EntityStoreAction["Update"] = "UPDATE";
3618
- EntityStoreAction["AddEntities"] = "ADD_ENTITIES";
3619
- EntityStoreAction["SetEntities"] = "SET_ENTITIES";
3620
- EntityStoreAction["UpdateEntities"] = "UPDATE_ENTITIES";
3621
- EntityStoreAction["RemoveEntities"] = "REMOVE_ENTITIES";
3622
- EntityStoreAction["UpsertEntities"] = "UPSERT_ENTITIES";
3623
- EntityStoreAction["UpsertManyEntities"] = "UPSERT_MANY_ENTITIES";
3624
- })(EntityStoreAction || (EntityStoreAction = {}));
3625
-
3626
- exports.Observable = Observable;
3627
- exports.Query = Query;
3628
- exports.SimpleInnerSubscriber = SimpleInnerSubscriber;
3629
- exports.SimpleOuterSubscriber = SimpleOuterSubscriber;
3630
- exports.Store = Store;
3631
- exports.StoreConfig = StoreConfig;
3632
- exports.Subscriber = Subscriber;
3633
- exports.async = async;
3634
- exports.distinctUntilChanged = distinctUntilChanged;
3635
- exports.enableAkitaProdMode = enableAkitaProdMode;
3636
- exports.filter = filter;
3637
- exports.from = from;
3638
- exports.innerSubscribe = innerSubscribe;
3639
- exports.isArray = isArray;
3640
- exports.isFunction = isFunction;
3641
- exports.map = map;