@flarehr/apollo-benefits 1.2.97 → 1.3.54109
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.
- package/README.md +19 -0
- package/dist/assets/@splitsoftware-7d799540.js +18 -0
- package/dist/assets/all_tab_color-548783b9.svg +21 -0
- package/dist/assets/all_tab_gray-a5051313.svg +6 -0
- package/dist/assets/check-57fe1dcb.svg +15 -0
- package/dist/assets/datadog-9aa4bf28.js +5 -0
- package/dist/assets/date-fns-c5d8fbc0.js +1 -0
- package/dist/assets/default_backdrop-fdd955b8.png +0 -0
- package/dist/assets/external_link-599a0aec.svg +3 -0
- package/dist/assets/external_link_white-55111b2e.svg +3 -0
- package/dist/assets/framer-motion-bb8d6b82.js +1 -0
- package/dist/assets/index-18cd5088.js +35 -0
- package/dist/assets/index-cfa25e28.css +1 -0
- package/dist/assets/index-e4f1c441.js +5 -0
- package/dist/assets/lodash-5d893f8c.js +1 -0
- package/dist/assets/logo-a34e9b4b.png +0 -0
- package/dist/assets/oidc-client-6f6e47c2.js +101 -0
- package/dist/assets/padlock-8c081120.svg +26 -0
- package/dist/assets/suitcase-6471ad05.svg +17 -0
- package/dist/assets/vendor-2d0139ca.js +788 -0
- package/dist/assets/warning-a7f1af23.svg +14 -0
- package/dist/assets/welcome_image_mobile-dbde6c80.png +0 -0
- package/dist/assets/welcome_image_v2-869c59e4.png +0 -0
- package/dist/assets/wellbeing_banner-6903d615.png +0 -0
- package/dist/assets/workplace_link_banner_mobile-6ebaa24b.png +0 -0
- package/dist/assets/workplace_link_banner_v2-c81ed849.png +0 -0
- package/dist/config.json +14 -0
- package/dist/favicon.ico +0 -0
- package/dist/icons/android-chrome-192x192.png +0 -0
- package/dist/icons/android-chrome-512x512.png +0 -0
- package/dist/icons/apple-touch-icon.png +0 -0
- package/dist/icons/favicon-16x16.png +0 -0
- package/dist/icons/favicon-32x32.png +0 -0
- package/dist/index.html +114 -0
- package/dist/manifest.json +21 -0
- package/dist/sw-esm.js +16 -0
- package/package.json +127 -69
- package/LICENSE +0 -21
- package/dist/lib/apollo-benefits/apollo-benefits.esm.js +0 -1
- package/dist/lib/apollo-benefits/assets/Hero_Background.png +0 -0
- package/dist/lib/apollo-benefits/assets/car-placeholder.svg +0 -5
- package/dist/lib/apollo-benefits/assets/check.svg +0 -13
- package/dist/lib/apollo-benefits/common-assets/icon-info.svg +0 -4
- package/dist/lib/apollo-benefits/index.esm.js +0 -0
- package/dist/lib/apollo-benefits/p-054d1471.js +0 -1
- package/dist/lib/apollo-benefits/p-066d8e7b.js +0 -15
- package/dist/lib/apollo-benefits/p-08376428.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-1d7ab1b9.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-25a89275.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-26d363c9.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-337ce3df.js +0 -1
- package/dist/lib/apollo-benefits/p-3dc9a379.js +0 -1
- package/dist/lib/apollo-benefits/p-4376366b.js +0 -46
- package/dist/lib/apollo-benefits/p-4e2d34f4.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-50bbf713.js +0 -1
- package/dist/lib/apollo-benefits/p-53c5e861.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-556fdb43.js +0 -1
- package/dist/lib/apollo-benefits/p-57d4702d.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-58ee670f.js +0 -1
- package/dist/lib/apollo-benefits/p-6a54654f.entry.js +0 -11
- package/dist/lib/apollo-benefits/p-6bd33850.js +0 -1
- package/dist/lib/apollo-benefits/p-79c3b633.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-7f3a2f3b.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-82d42c2b.js +0 -1
- package/dist/lib/apollo-benefits/p-9b3e978e.js +0 -1
- package/dist/lib/apollo-benefits/p-a1dd0cba.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-aa379cfe.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-aaf0e527.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-b0b9425b.js +0 -1
- package/dist/lib/apollo-benefits/p-d0ef83f8.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-db4a65f0.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-dc67f942.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-e1fd79bb.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-ea120e31.js +0 -1
- package/dist/lib/apollo-benefits/p-ef5f33ca.js +0 -1
- package/dist/lib/apollo-benefits/p-f5254031.js +0 -1
- package/dist/lib/apollo-benefits/p-f63d9d89.js +0 -1
- package/dist/lib/apollo-benefits/p-fcfa5255.entry.js +0 -1
- package/dist/lib/cjs/Option-98dab0b8.js +0 -1988
- package/dist/lib/cjs/active-router-90429847.js +0 -75
- package/dist/lib/cjs/ap-ben-asset_5.cjs.entry.js +0 -1856
- package/dist/lib/cjs/ap-ben-benefit-card.cjs.entry.js +0 -45
- package/dist/lib/cjs/ap-ben-benefit-list-item.cjs.entry.js +0 -56
- package/dist/lib/cjs/ap-ben-benefit-url_27.cjs.entry.js +0 -48767
- package/dist/lib/cjs/ap-ben-benefits-list_3.cjs.entry.js +0 -55
- package/dist/lib/cjs/ap-ben-benefits-page.cjs.entry.js +0 -55
- package/dist/lib/cjs/ap-ben-choose-vehicle-section_4.cjs.entry.js +0 -2779
- package/dist/lib/cjs/ap-ben-notifications-section.cjs.entry.js +0 -243
- package/dist/lib/cjs/ap-ben-oidc-callback-page.cjs.entry.js +0 -40
- package/dist/lib/cjs/apollo-benefits.cjs.js +0 -25
- package/dist/lib/cjs/app-globals-e04ab04b.js +0 -12
- package/dist/lib/cjs/authentication.service-11c30071.js +0 -237
- package/dist/lib/cjs/benefits.api-b46ee2ea.js +0 -35
- package/dist/lib/cjs/cars-calculator-app.cjs.entry.js +0 -60
- package/dist/lib/cjs/cars-calculator.service-a8beab79.js +0 -166
- package/dist/lib/cjs/context-consumer.cjs.entry.js +0 -29
- package/dist/lib/cjs/datorama-akita-792b4d1d.js +0 -2553
- package/dist/lib/cjs/delay-e91dba76.js +0 -206
- package/dist/lib/cjs/event-tracking.service-6f723d9c.js +0 -155
- package/dist/lib/cjs/event-tracking.service-d6f9a51c.js +0 -259
- package/dist/lib/cjs/filter-c38164e6.js +0 -378
- package/dist/lib/cjs/fl-dropdown-async.cjs.entry.js +0 -422
- package/dist/lib/cjs/fl-dropdown.cjs.entry.js +0 -232
- package/dist/lib/cjs/fl-style-guide.cjs.entry.js +0 -91
- package/dist/lib/cjs/index-4f00f593.js +0 -994
- package/dist/lib/cjs/index-6e643fec.js +0 -1734
- package/dist/lib/cjs/index-889ce6c6.js +0 -27
- package/dist/lib/cjs/index.cjs.js +0 -2
- package/dist/lib/cjs/loader.cjs.js +0 -27
- package/dist/lib/cjs/scheduleArray-0ba3d6f8.js +0 -753
- package/dist/lib/cjs/stencil-async-content.cjs.entry.js +0 -32
- package/dist/lib/cjs/stencil-route-title.cjs.entry.js +0 -32
- package/dist/lib/cjs/stencil-router-prompt.cjs.entry.js +0 -59
- package/dist/lib/cjs/stencil-router-redirect.cjs.entry.js +0 -32
- package/dist/lib/cjs/view.service-ec43dea6.js +0 -21
- package/dist/lib/collection/assets/image/complete.svg +0 -122
- package/dist/lib/collection/collection-manifest.json +0 -81
- package/dist/lib/collection/components/benefits-app/apis/api-client.js +0 -16
- package/dist/lib/collection/components/benefits-app/apis/benefits-api/benefits-api.dto.js +0 -16
- package/dist/lib/collection/components/benefits-app/apis/benefits-api/benefits.api.js +0 -30
- package/dist/lib/collection/components/benefits-app/apis/event-tracking-api/event-tracking-api.dto.js +0 -1
- package/dist/lib/collection/components/benefits-app/apis/event-tracking-api/event-tracking-api.js +0 -7
- package/dist/lib/collection/components/benefits-app/apis/user-api/user-api.dto.js +0 -8
- package/dist/lib/collection/components/benefits-app/apis/user-api/user.api.js +0 -16
- package/dist/lib/collection/components/benefits-app/benefits-app.css +0 -399
- package/dist/lib/collection/components/benefits-app/benefits-app.js +0 -216
- package/dist/lib/collection/components/benefits-app/pages/benefits-page/benefits-list/benefit-list-item.css +0 -23
- package/dist/lib/collection/components/benefits-app/pages/benefits-page/benefits-list/benefits-list-item.js +0 -80
- package/dist/lib/collection/components/benefits-app/pages/benefits-page/benefits-list/benefits-list.js +0 -32
- package/dist/lib/collection/components/benefits-app/pages/benefits-page/benefits-page.js +0 -47
- package/dist/lib/collection/components/benefits-app/pages/benefits-page/hero-banner/assets/Hero_Background.png +0 -0
- package/dist/lib/collection/components/benefits-app/pages/benefits-page/hero-banner/hero-banner.css +0 -8
- package/dist/lib/collection/components/benefits-app/pages/benefits-page/hero-banner/hero-banner.js +0 -53
- package/dist/lib/collection/components/benefits-app/pages/benefits-page/promoted-benefits/benefit-card.css +0 -3
- package/dist/lib/collection/components/benefits-app/pages/benefits-page/promoted-benefits/benefit-card.js +0 -62
- package/dist/lib/collection/components/benefits-app/pages/benefits-page/promoted-benefits/promoted-benefits.js +0 -33
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/api/manage-benefits-api.dto.js +0 -36
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/api/manage-benefits.api.js +0 -23
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/edit-benefit-page/confirm-dialog.js +0 -158
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/edit-benefit-page/edit-benefit-form/benefit-url.css +0 -8
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/edit-benefit-page/edit-benefit-form/benefit-url.js +0 -126
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/edit-benefit-page/edit-benefit-form/edit-benefit-form.js +0 -138
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/edit-benefit-page/edit-benefit-form/upload-benefit-icon.css +0 -24
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/edit-benefit-page/edit-benefit-form/upload-benefit-icon.js +0 -102
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/edit-benefit-page/edit-benefit-form/upload-file.css +0 -18
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/edit-benefit-page/edit-benefit-form/upload-file.js +0 -120
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/edit-benefit-page/edit-benefit-page.js +0 -154
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/edit-benefit-page/edit-benefit.query.js +0 -18
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/edit-benefit-page/edit-benefit.service.js +0 -155
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/empty-benefits.js +0 -36
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/manage-benefits-header-row.js +0 -13
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/manage-benefits-page.css +0 -3
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/manage-benefits-page.js +0 -88
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/manage-benefits-page.routes.js +0 -24
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/manage-benefits.service.js +0 -37
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/managed-benefit-item/managed-benefit-item.css +0 -10
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/managed-benefit-item/managed-benefit-item.js +0 -89
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/store/manage-benefits.query.js +0 -11
- package/dist/lib/collection/components/benefits-app/pages/manage-benefits-page/store/manage-benefits.store.js +0 -51
- package/dist/lib/collection/components/benefits-app/pages/role-management-page/api/role-management.api.js +0 -21
- package/dist/lib/collection/components/benefits-app/pages/role-management-page/role-editors-section/role-editors-section.js +0 -104
- package/dist/lib/collection/components/benefits-app/pages/role-management-page/role-management-page.js +0 -50
- package/dist/lib/collection/components/benefits-app/pages/role-management-page/role-management.service.js +0 -44
- package/dist/lib/collection/components/benefits-app/pages/role-management-page/role-owner-section/role-owner-section.js +0 -40
- package/dist/lib/collection/components/benefits-app/pages/role-management-page/store/role-management.query.js +0 -13
- package/dist/lib/collection/components/benefits-app/pages/role-management-page/store/role-management.store.js +0 -42
- package/dist/lib/collection/components/benefits-app/services/benefits-app.service.js +0 -36
- package/dist/lib/collection/components/benefits-app/services/benefits.service.js +0 -11
- package/dist/lib/collection/components/benefits-app/services/event-tracking.service.js +0 -40
- package/dist/lib/collection/components/benefits-app/services/navigation.service.js +0 -34
- package/dist/lib/collection/components/benefits-app/store/benefits-app.query.js +0 -13
- package/dist/lib/collection/components/benefits-app/store/benefits-app.store.js +0 -24
- package/dist/lib/collection/components/benefits-app-host/benefits-app-host.js +0 -48
- package/dist/lib/collection/components/benefits-app-host/loading-page.js +0 -9
- package/dist/lib/collection/components/benefits-app-host/oidc-callback-page/oidc-callback-page.js +0 -65
- package/dist/lib/collection/components/benefits-app-host/oidc-callback-page/oidc-callback-page.routes.js +0 -11
- package/dist/lib/collection/components/benefits-app-host/services/app-configuration.query.js +0 -18
- package/dist/lib/collection/components/benefits-app-host/services/app-configuration.service.js +0 -23
- package/dist/lib/collection/components/benefits-app-host/services/authentication.query.js +0 -21
- package/dist/lib/collection/components/benefits-app-host/services/authentication.service.js +0 -96
- package/dist/lib/collection/components/benefits-app-host/services/session.store.js +0 -33
- package/dist/lib/collection/components/cars-calculator-app/api/api-client.js +0 -5
- package/dist/lib/collection/components/cars-calculator-app/api/cars-calculator-events.model.js +0 -1
- package/dist/lib/collection/components/cars-calculator-app/api/cars-calculator.api.js +0 -45
- package/dist/lib/collection/components/cars-calculator-app/api/event-tracking.api.js +0 -7
- package/dist/lib/collection/components/cars-calculator-app/cars-calculator-app.css +0 -22
- package/dist/lib/collection/components/cars-calculator-app/cars-calculator-app.js +0 -97
- package/dist/lib/collection/components/cars-calculator-app/notifications-section/notifications-section.js +0 -25
- package/dist/lib/collection/components/cars-calculator-app/pages/asset.component.js +0 -27
- package/dist/lib/collection/components/cars-calculator-app/pages/assets/car-placeholder.svg +0 -5
- package/dist/lib/collection/components/cars-calculator-app/pages/assets/check.svg +0 -13
- package/dist/lib/collection/components/cars-calculator-app/pages/choose-vehicle-section.component.js +0 -234
- package/dist/lib/collection/components/cars-calculator-app/pages/common-assets/icon-info.svg +0 -4
- package/dist/lib/collection/components/cars-calculator-app/pages/complete-section.component.js +0 -38
- package/dist/lib/collection/components/cars-calculator-app/pages/cost-breakdown-section.component.js +0 -45
- package/dist/lib/collection/components/cars-calculator-app/pages/model-variants-section.component.css +0 -34
- package/dist/lib/collection/components/cars-calculator-app/pages/model-variants-section.component.js +0 -93
- package/dist/lib/collection/components/cars-calculator-app/pages/personal-info-section.component.js +0 -71
- package/dist/lib/collection/components/cars-calculator-app/pages/quote-result-section.component.js +0 -117
- package/dist/lib/collection/components/cars-calculator-app/pages/submit-quote-section.component.js +0 -87
- package/dist/lib/collection/components/cars-calculator-app/services/app-configuration.service.js +0 -13
- package/dist/lib/collection/components/cars-calculator-app/services/cars-calculator.service.js +0 -117
- package/dist/lib/collection/components/cars-calculator-app/services/event-tracking.service.js +0 -37
- package/dist/lib/collection/components/cars-calculator-app/services/notifications.service.js +0 -37
- package/dist/lib/collection/components/cars-calculator-app/services/notifications.store.js +0 -3
- package/dist/lib/collection/components/cars-calculator-app/services/session.query.js +0 -38
- package/dist/lib/collection/components/cars-calculator-app/services/session.store.js +0 -80
- package/dist/lib/collection/components/cars-calculator-app/services/view.service.js +0 -16
- package/dist/lib/collection/components/shared/file-icon/file-icon.css +0 -15
- package/dist/lib/collection/components/shared/file-icon/file-icon.js +0 -84
- package/dist/lib/collection/components/shared/icon.js +0 -77
- package/dist/lib/collection/components/shared/icons-library.js +0 -11
- package/dist/lib/collection/components/shared/modal-section.js +0 -138
- package/dist/lib/collection/components/shared/tooltip.css +0 -3
- package/dist/lib/collection/components/shared/tooltip.js +0 -115
- package/dist/lib/collection/components/shared/ui-container/ui-container.css +0 -39
- package/dist/lib/collection/components/shared/ui-container/ui-container.js +0 -27
- package/dist/lib/collection/global/config.js +0 -2
- package/dist/lib/collection/global/main.dev.js +0 -31
- package/dist/lib/collection/global/main.js +0 -5
- package/dist/lib/collection/index.js +0 -2
- package/dist/lib/collection/utils/config.js +0 -2
- package/dist/lib/collection/utils/index.js +0 -28
- package/dist/lib/collection/utils/lazy.js +0 -29
- package/dist/lib/collection/utils/promise.js +0 -7
- package/dist/lib/esm/Option-53ef163a.js +0 -1982
- package/dist/lib/esm/active-router-134fe07f.js +0 -73
- package/dist/lib/esm/ap-ben-asset_5.entry.js +0 -1848
- package/dist/lib/esm/ap-ben-benefit-card.entry.js +0 -41
- package/dist/lib/esm/ap-ben-benefit-list-item.entry.js +0 -52
- package/dist/lib/esm/ap-ben-benefit-url_27.entry.js +0 -48737
- package/dist/lib/esm/ap-ben-benefits-list_3.entry.js +0 -49
- package/dist/lib/esm/ap-ben-benefits-page.entry.js +0 -51
- package/dist/lib/esm/ap-ben-choose-vehicle-section_4.entry.js +0 -2772
- package/dist/lib/esm/ap-ben-notifications-section.entry.js +0 -239
- package/dist/lib/esm/ap-ben-oidc-callback-page.entry.js +0 -36
- package/dist/lib/esm/apollo-benefits.js +0 -23
- package/dist/lib/esm/app-globals-ff43b669.js +0 -10
- package/dist/lib/esm/authentication.service-4dbff8a5.js +0 -232
- package/dist/lib/esm/benefits.api-5a0c5fa7.js +0 -33
- package/dist/lib/esm/cars-calculator-app.entry.js +0 -56
- package/dist/lib/esm/cars-calculator.service-1278f563.js +0 -163
- package/dist/lib/esm/context-consumer.entry.js +0 -25
- package/dist/lib/esm/datorama-akita-e42d9911.js +0 -2547
- package/dist/lib/esm/delay-d08c267f.js +0 -200
- package/dist/lib/esm/event-tracking.service-27d79066.js +0 -253
- package/dist/lib/esm/event-tracking.service-429d997c.js +0 -146
- package/dist/lib/esm/filter-aeb65cac.js +0 -370
- package/dist/lib/esm/fl-dropdown-async.entry.js +0 -418
- package/dist/lib/esm/fl-dropdown.entry.js +0 -228
- package/dist/lib/esm/fl-style-guide.entry.js +0 -87
- package/dist/lib/esm/index-1351f893.js +0 -979
- package/dist/lib/esm/index-8676bf1e.js +0 -22
- package/dist/lib/esm/index-d4b319a7.js +0 -1702
- package/dist/lib/esm/index.js +0 -1
- package/dist/lib/esm/loader.js +0 -23
- package/dist/lib/esm/polyfills/core-js.js +0 -11
- package/dist/lib/esm/polyfills/css-shim.js +0 -1
- package/dist/lib/esm/polyfills/dom.js +0 -79
- package/dist/lib/esm/polyfills/es5-html-element.js +0 -1
- package/dist/lib/esm/polyfills/index.js +0 -34
- package/dist/lib/esm/polyfills/system.js +0 -6
- package/dist/lib/esm/scheduleArray-b9669898.js +0 -738
- package/dist/lib/esm/stencil-async-content.entry.js +0 -28
- package/dist/lib/esm/stencil-route-title.entry.js +0 -28
- package/dist/lib/esm/stencil-router-prompt.entry.js +0 -55
- package/dist/lib/esm/stencil-router-redirect.entry.js +0 -28
- package/dist/lib/esm/view.service-6adbec31.js +0 -19
- package/dist/lib/index.cjs.js +0 -1
- package/dist/lib/index.js +0 -1
- package/dist/lib/loader/cdn.js +0 -3
- package/dist/lib/loader/index.cjs.js +0 -3
- package/dist/lib/loader/index.d.ts +0 -13
- package/dist/lib/loader/index.es2017.js +0 -3
- package/dist/lib/loader/index.js +0 -4
- package/dist/lib/loader/package.json +0 -10
- package/dist/lib/node_modules/@flarehr/beacon/dist/collection/components/button/button.css +0 -118
- package/dist/lib/node_modules/@flarehr/beacon/dist/collection/components/dropdown/dropdown.css +0 -9
- package/dist/lib/node_modules/@flarehr/beacon/dist/collection/components/dropdown-async/dropdown-async.css +0 -9
- package/dist/lib/node_modules/@flarehr/beacon/dist/collection/components/loading-indicator/loading-indicator.css +0 -141
- package/dist/lib/node_modules/@flarehr/beacon/dist/collection/components/promise-button/promise-button.css +0 -5
- package/dist/lib/node_modules/@flarehr/beacon/dist/collection/components/style-guide/style-guide.css +0 -0
- package/dist/lib/node_modules/@stencil/router/dist/collection/components/route/route.css +0 -3
- package/dist/lib/types/components/benefits-app/apis/api-client.d.ts +0 -7
- package/dist/lib/types/components/benefits-app/apis/benefits-api/benefits-api.dto.d.ts +0 -44
- package/dist/lib/types/components/benefits-app/apis/benefits-api/benefits.api.d.ts +0 -9
- package/dist/lib/types/components/benefits-app/apis/event-tracking-api/event-tracking-api.d.ts +0 -6
- package/dist/lib/types/components/benefits-app/apis/event-tracking-api/event-tracking-api.dto.d.ts +0 -18
- package/dist/lib/types/components/benefits-app/apis/user-api/user-api.dto.d.ts +0 -30
- package/dist/lib/types/components/benefits-app/apis/user-api/user.api.d.ts +0 -8
- package/dist/lib/types/components/benefits-app/benefits-app.d.ts +0 -22
- package/dist/lib/types/components/benefits-app/pages/benefits-page/benefits-list/benefits-list-item.d.ts +0 -10
- package/dist/lib/types/components/benefits-app/pages/benefits-page/benefits-list/benefits-list.d.ts +0 -5
- package/dist/lib/types/components/benefits-app/pages/benefits-page/benefits-page.d.ts +0 -10
- package/dist/lib/types/components/benefits-app/pages/benefits-page/hero-banner/hero-banner.d.ts +0 -5
- package/dist/lib/types/components/benefits-app/pages/benefits-page/promoted-benefits/benefit-card.d.ts +0 -8
- package/dist/lib/types/components/benefits-app/pages/benefits-page/promoted-benefits/promoted-benefits.d.ts +0 -5
- package/dist/lib/types/components/benefits-app/pages/manage-benefits-page/api/manage-benefits-api.dto.d.ts +0 -39
- package/dist/lib/types/components/benefits-app/pages/manage-benefits-page/api/manage-benefits.api.d.ts +0 -9
- package/dist/lib/types/components/benefits-app/pages/manage-benefits-page/edit-benefit-page/confirm-dialog.d.ts +0 -16
- package/dist/lib/types/components/benefits-app/pages/manage-benefits-page/edit-benefit-page/edit-benefit-form/benefit-url.d.ts +0 -21
- package/dist/lib/types/components/benefits-app/pages/manage-benefits-page/edit-benefit-page/edit-benefit-form/edit-benefit-form.d.ts +0 -12
- package/dist/lib/types/components/benefits-app/pages/manage-benefits-page/edit-benefit-page/edit-benefit-form/upload-benefit-icon.d.ts +0 -16
- package/dist/lib/types/components/benefits-app/pages/manage-benefits-page/edit-benefit-page/edit-benefit-form/upload-file.d.ts +0 -17
- package/dist/lib/types/components/benefits-app/pages/manage-benefits-page/edit-benefit-page/edit-benefit-page.d.ts +0 -24
- package/dist/lib/types/components/benefits-app/pages/manage-benefits-page/edit-benefit-page/edit-benefit.query.d.ts +0 -16
- package/dist/lib/types/components/benefits-app/pages/manage-benefits-page/edit-benefit-page/edit-benefit.service.d.ts +0 -20
- package/dist/lib/types/components/benefits-app/pages/manage-benefits-page/empty-benefits.d.ts +0 -5
- package/dist/lib/types/components/benefits-app/pages/manage-benefits-page/manage-benefits-header-row.d.ts +0 -3
- package/dist/lib/types/components/benefits-app/pages/manage-benefits-page/manage-benefits-page.d.ts +0 -16
- package/dist/lib/types/components/benefits-app/pages/manage-benefits-page/manage-benefits-page.routes.d.ts +0 -6
- package/dist/lib/types/components/benefits-app/pages/manage-benefits-page/manage-benefits.service.d.ts +0 -8
- package/dist/lib/types/components/benefits-app/pages/manage-benefits-page/managed-benefit-item/managed-benefit-item.d.ts +0 -11
- package/dist/lib/types/components/benefits-app/pages/manage-benefits-page/store/manage-benefits.query.d.ts +0 -10
- package/dist/lib/types/components/benefits-app/pages/manage-benefits-page/store/manage-benefits.store.d.ts +0 -51
- package/dist/lib/types/components/benefits-app/pages/role-management-page/api/role-management.api.d.ts +0 -7
- package/dist/lib/types/components/benefits-app/pages/role-management-page/role-editors-section/role-editors-section.d.ts +0 -15
- package/dist/lib/types/components/benefits-app/pages/role-management-page/role-management-page.d.ts +0 -9
- package/dist/lib/types/components/benefits-app/pages/role-management-page/role-management.service.d.ts +0 -11
- package/dist/lib/types/components/benefits-app/pages/role-management-page/role-owner-section/role-owner-section.d.ts +0 -5
- package/dist/lib/types/components/benefits-app/pages/role-management-page/store/role-management.query.d.ts +0 -12
- package/dist/lib/types/components/benefits-app/pages/role-management-page/store/role-management.store.d.ts +0 -17
- package/dist/lib/types/components/benefits-app/services/benefits-app.service.d.ts +0 -13
- package/dist/lib/types/components/benefits-app/services/benefits.service.d.ts +0 -8
- package/dist/lib/types/components/benefits-app/services/event-tracking.service.d.ts +0 -11
- package/dist/lib/types/components/benefits-app/services/navigation.service.d.ts +0 -14
- package/dist/lib/types/components/benefits-app/store/benefits-app.query.d.ts +0 -12
- package/dist/lib/types/components/benefits-app/store/benefits-app.store.d.ts +0 -31
- package/dist/lib/types/components/benefits-app-host/benefits-app-host.d.ts +0 -9
- package/dist/lib/types/components/benefits-app-host/loading-page.d.ts +0 -3
- package/dist/lib/types/components/benefits-app-host/oidc-callback-page/oidc-callback-page.d.ts +0 -8
- package/dist/lib/types/components/benefits-app-host/oidc-callback-page/oidc-callback-page.routes.d.ts +0 -1
- package/dist/lib/types/components/benefits-app-host/services/app-configuration.query.d.ts +0 -11
- package/dist/lib/types/components/benefits-app-host/services/app-configuration.service.d.ts +0 -9
- package/dist/lib/types/components/benefits-app-host/services/authentication.query.d.ts +0 -13
- package/dist/lib/types/components/benefits-app-host/services/authentication.service.d.ts +0 -25
- package/dist/lib/types/components/benefits-app-host/services/session.store.d.ts +0 -25
- package/dist/lib/types/components/cars-calculator-app/api/api-client.d.ts +0 -2
- package/dist/lib/types/components/cars-calculator-app/api/cars-calculator-events.model.d.ts +0 -39
- package/dist/lib/types/components/cars-calculator-app/api/cars-calculator.api.d.ts +0 -100
- package/dist/lib/types/components/cars-calculator-app/api/event-tracking.api.d.ts +0 -6
- package/dist/lib/types/components/cars-calculator-app/cars-calculator-app.d.ts +0 -18
- package/dist/lib/types/components/cars-calculator-app/notifications-section/notifications-section.d.ts +0 -5
- package/dist/lib/types/components/cars-calculator-app/pages/asset.component.d.ts +0 -4
- package/dist/lib/types/components/cars-calculator-app/pages/choose-vehicle-section.component.d.ts +0 -23
- package/dist/lib/types/components/cars-calculator-app/pages/complete-section.component.d.ts +0 -5
- package/dist/lib/types/components/cars-calculator-app/pages/cost-breakdown-section.component.d.ts +0 -6
- package/dist/lib/types/components/cars-calculator-app/pages/model-variants-section.component.d.ts +0 -12
- package/dist/lib/types/components/cars-calculator-app/pages/personal-info-section.component.d.ts +0 -10
- package/dist/lib/types/components/cars-calculator-app/pages/quote-result-section.component.d.ts +0 -16
- package/dist/lib/types/components/cars-calculator-app/pages/submit-quote-section.component.d.ts +0 -12
- package/dist/lib/types/components/cars-calculator-app/services/app-configuration.service.d.ts +0 -7
- package/dist/lib/types/components/cars-calculator-app/services/cars-calculator.service.d.ts +0 -11
- package/dist/lib/types/components/cars-calculator-app/services/event-tracking.service.d.ts +0 -13
- package/dist/lib/types/components/cars-calculator-app/services/notifications.service.d.ts +0 -15
- package/dist/lib/types/components/cars-calculator-app/services/notifications.store.d.ts +0 -14
- package/dist/lib/types/components/cars-calculator-app/services/session.query.d.ts +0 -26
- package/dist/lib/types/components/cars-calculator-app/services/session.store.d.ts +0 -78
- package/dist/lib/types/components/cars-calculator-app/services/view.service.d.ts +0 -8
- package/dist/lib/types/components/shared/file-icon/file-icon.d.ts +0 -11
- package/dist/lib/types/components/shared/icon.d.ts +0 -7
- package/dist/lib/types/components/shared/icons-library.d.ts +0 -1
- package/dist/lib/types/components/shared/modal-section.d.ts +0 -16
- package/dist/lib/types/components/shared/tooltip.d.ts +0 -13
- package/dist/lib/types/components/shared/ui-container/ui-container.d.ts +0 -5
- package/dist/lib/types/components.d.ts +0 -606
- package/dist/lib/types/global/config.d.ts +0 -2
- package/dist/lib/types/global/main.d.ts +0 -1
- package/dist/lib/types/global/main.dev.d.ts +0 -1
- package/dist/lib/types/index.d.ts +0 -2
- package/dist/lib/types/stencil-public-runtime.d.ts +0 -1555
- package/dist/lib/types/utils/config.d.ts +0 -2
- package/dist/lib/types/utils/index.d.ts +0 -10
- package/dist/lib/types/utils/lazy.d.ts +0 -12
- package/dist/lib/types/utils/promise.d.ts +0 -1
- package/readme.md +0 -1
|
@@ -1,2547 +0,0 @@
|
|
|
1
|
-
import { S as Subscriber, a as Subscription, O as Observable, r as rxSubscriber, A as AsyncAction, b as AsyncScheduler } from './scheduleArray-b9669898.js';
|
|
2
|
-
import { e as empty, N as Notification, o as of, d as delay } from './delay-d08c267f.js';
|
|
3
|
-
import { S as SimpleOuterSubscriber, a as SimpleInnerSubscriber, i as innerSubscribe, f as from, m as map, d as distinctUntilChanged, b as filter } from './filter-aeb65cac.js';
|
|
4
|
-
|
|
5
|
-
const ArgumentOutOfRangeErrorImpl = (() => {
|
|
6
|
-
function ArgumentOutOfRangeErrorImpl() {
|
|
7
|
-
Error.call(this);
|
|
8
|
-
this.message = 'argument out of range';
|
|
9
|
-
this.name = 'ArgumentOutOfRangeError';
|
|
10
|
-
return this;
|
|
11
|
-
}
|
|
12
|
-
ArgumentOutOfRangeErrorImpl.prototype = Object.create(Error.prototype);
|
|
13
|
-
return ArgumentOutOfRangeErrorImpl;
|
|
14
|
-
})();
|
|
15
|
-
const ArgumentOutOfRangeError = ArgumentOutOfRangeErrorImpl;
|
|
16
|
-
|
|
17
|
-
function take(count) {
|
|
18
|
-
return (source) => {
|
|
19
|
-
if (count === 0) {
|
|
20
|
-
return empty();
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
return source.lift(new TakeOperator(count));
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
class TakeOperator {
|
|
28
|
-
constructor(total) {
|
|
29
|
-
this.total = total;
|
|
30
|
-
if (this.total < 0) {
|
|
31
|
-
throw new ArgumentOutOfRangeError;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
call(subscriber, source) {
|
|
35
|
-
return source.subscribe(new TakeSubscriber(subscriber, this.total));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
class TakeSubscriber extends Subscriber {
|
|
39
|
-
constructor(destination, total) {
|
|
40
|
-
super(destination);
|
|
41
|
-
this.total = total;
|
|
42
|
-
this.count = 0;
|
|
43
|
-
}
|
|
44
|
-
_next(value) {
|
|
45
|
-
const total = this.total;
|
|
46
|
-
const count = ++this.count;
|
|
47
|
-
if (count <= total) {
|
|
48
|
-
this.destination.next(value);
|
|
49
|
-
if (count === total) {
|
|
50
|
-
this.destination.complete();
|
|
51
|
-
this.unsubscribe();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const ObjectUnsubscribedErrorImpl = (() => {
|
|
58
|
-
function ObjectUnsubscribedErrorImpl() {
|
|
59
|
-
Error.call(this);
|
|
60
|
-
this.message = 'object unsubscribed';
|
|
61
|
-
this.name = 'ObjectUnsubscribedError';
|
|
62
|
-
return this;
|
|
63
|
-
}
|
|
64
|
-
ObjectUnsubscribedErrorImpl.prototype = Object.create(Error.prototype);
|
|
65
|
-
return ObjectUnsubscribedErrorImpl;
|
|
66
|
-
})();
|
|
67
|
-
const ObjectUnsubscribedError = ObjectUnsubscribedErrorImpl;
|
|
68
|
-
|
|
69
|
-
class SubjectSubscription extends Subscription {
|
|
70
|
-
constructor(subject, subscriber) {
|
|
71
|
-
super();
|
|
72
|
-
this.subject = subject;
|
|
73
|
-
this.subscriber = subscriber;
|
|
74
|
-
this.closed = false;
|
|
75
|
-
}
|
|
76
|
-
unsubscribe() {
|
|
77
|
-
if (this.closed) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
this.closed = true;
|
|
81
|
-
const subject = this.subject;
|
|
82
|
-
const observers = subject.observers;
|
|
83
|
-
this.subject = null;
|
|
84
|
-
if (!observers || observers.length === 0 || subject.isStopped || subject.closed) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const subscriberIndex = observers.indexOf(this.subscriber);
|
|
88
|
-
if (subscriberIndex !== -1) {
|
|
89
|
-
observers.splice(subscriberIndex, 1);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
class SubjectSubscriber extends Subscriber {
|
|
95
|
-
constructor(destination) {
|
|
96
|
-
super(destination);
|
|
97
|
-
this.destination = destination;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
class Subject extends Observable {
|
|
101
|
-
constructor() {
|
|
102
|
-
super();
|
|
103
|
-
this.observers = [];
|
|
104
|
-
this.closed = false;
|
|
105
|
-
this.isStopped = false;
|
|
106
|
-
this.hasError = false;
|
|
107
|
-
this.thrownError = null;
|
|
108
|
-
}
|
|
109
|
-
[rxSubscriber]() {
|
|
110
|
-
return new SubjectSubscriber(this);
|
|
111
|
-
}
|
|
112
|
-
lift(operator) {
|
|
113
|
-
const subject = new AnonymousSubject(this, this);
|
|
114
|
-
subject.operator = operator;
|
|
115
|
-
return subject;
|
|
116
|
-
}
|
|
117
|
-
next(value) {
|
|
118
|
-
if (this.closed) {
|
|
119
|
-
throw new ObjectUnsubscribedError();
|
|
120
|
-
}
|
|
121
|
-
if (!this.isStopped) {
|
|
122
|
-
const { observers } = this;
|
|
123
|
-
const len = observers.length;
|
|
124
|
-
const copy = observers.slice();
|
|
125
|
-
for (let i = 0; i < len; i++) {
|
|
126
|
-
copy[i].next(value);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
error(err) {
|
|
131
|
-
if (this.closed) {
|
|
132
|
-
throw new ObjectUnsubscribedError();
|
|
133
|
-
}
|
|
134
|
-
this.hasError = true;
|
|
135
|
-
this.thrownError = err;
|
|
136
|
-
this.isStopped = true;
|
|
137
|
-
const { observers } = this;
|
|
138
|
-
const len = observers.length;
|
|
139
|
-
const copy = observers.slice();
|
|
140
|
-
for (let i = 0; i < len; i++) {
|
|
141
|
-
copy[i].error(err);
|
|
142
|
-
}
|
|
143
|
-
this.observers.length = 0;
|
|
144
|
-
}
|
|
145
|
-
complete() {
|
|
146
|
-
if (this.closed) {
|
|
147
|
-
throw new ObjectUnsubscribedError();
|
|
148
|
-
}
|
|
149
|
-
this.isStopped = true;
|
|
150
|
-
const { observers } = this;
|
|
151
|
-
const len = observers.length;
|
|
152
|
-
const copy = observers.slice();
|
|
153
|
-
for (let i = 0; i < len; i++) {
|
|
154
|
-
copy[i].complete();
|
|
155
|
-
}
|
|
156
|
-
this.observers.length = 0;
|
|
157
|
-
}
|
|
158
|
-
unsubscribe() {
|
|
159
|
-
this.isStopped = true;
|
|
160
|
-
this.closed = true;
|
|
161
|
-
this.observers = null;
|
|
162
|
-
}
|
|
163
|
-
_trySubscribe(subscriber) {
|
|
164
|
-
if (this.closed) {
|
|
165
|
-
throw new ObjectUnsubscribedError();
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
return super._trySubscribe(subscriber);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
_subscribe(subscriber) {
|
|
172
|
-
if (this.closed) {
|
|
173
|
-
throw new ObjectUnsubscribedError();
|
|
174
|
-
}
|
|
175
|
-
else if (this.hasError) {
|
|
176
|
-
subscriber.error(this.thrownError);
|
|
177
|
-
return Subscription.EMPTY;
|
|
178
|
-
}
|
|
179
|
-
else if (this.isStopped) {
|
|
180
|
-
subscriber.complete();
|
|
181
|
-
return Subscription.EMPTY;
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
this.observers.push(subscriber);
|
|
185
|
-
return new SubjectSubscription(this, subscriber);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
asObservable() {
|
|
189
|
-
const observable = new Observable();
|
|
190
|
-
observable.source = this;
|
|
191
|
-
return observable;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
Subject.create = (destination, source) => {
|
|
195
|
-
return new AnonymousSubject(destination, source);
|
|
196
|
-
};
|
|
197
|
-
class AnonymousSubject extends Subject {
|
|
198
|
-
constructor(destination, source) {
|
|
199
|
-
super();
|
|
200
|
-
this.destination = destination;
|
|
201
|
-
this.source = source;
|
|
202
|
-
}
|
|
203
|
-
next(value) {
|
|
204
|
-
const { destination } = this;
|
|
205
|
-
if (destination && destination.next) {
|
|
206
|
-
destination.next(value);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
error(err) {
|
|
210
|
-
const { destination } = this;
|
|
211
|
-
if (destination && destination.error) {
|
|
212
|
-
this.destination.error(err);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
complete() {
|
|
216
|
-
const { destination } = this;
|
|
217
|
-
if (destination && destination.complete) {
|
|
218
|
-
this.destination.complete();
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
_subscribe(subscriber) {
|
|
222
|
-
const { source } = this;
|
|
223
|
-
if (source) {
|
|
224
|
-
return this.source.subscribe(subscriber);
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
return Subscription.EMPTY;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
class ObserveOnSubscriber extends Subscriber {
|
|
233
|
-
constructor(destination, scheduler, delay = 0) {
|
|
234
|
-
super(destination);
|
|
235
|
-
this.scheduler = scheduler;
|
|
236
|
-
this.delay = delay;
|
|
237
|
-
}
|
|
238
|
-
static dispatch(arg) {
|
|
239
|
-
const { notification, destination } = arg;
|
|
240
|
-
notification.observe(destination);
|
|
241
|
-
this.unsubscribe();
|
|
242
|
-
}
|
|
243
|
-
scheduleMessage(notification) {
|
|
244
|
-
const destination = this.destination;
|
|
245
|
-
destination.add(this.scheduler.schedule(ObserveOnSubscriber.dispatch, this.delay, new ObserveOnMessage(notification, this.destination)));
|
|
246
|
-
}
|
|
247
|
-
_next(value) {
|
|
248
|
-
this.scheduleMessage(Notification.createNext(value));
|
|
249
|
-
}
|
|
250
|
-
_error(err) {
|
|
251
|
-
this.scheduleMessage(Notification.createError(err));
|
|
252
|
-
this.unsubscribe();
|
|
253
|
-
}
|
|
254
|
-
_complete() {
|
|
255
|
-
this.scheduleMessage(Notification.createComplete());
|
|
256
|
-
this.unsubscribe();
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
class ObserveOnMessage {
|
|
260
|
-
constructor(notification, destination) {
|
|
261
|
-
this.notification = notification;
|
|
262
|
-
this.destination = destination;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
class BehaviorSubject extends Subject {
|
|
267
|
-
constructor(_value) {
|
|
268
|
-
super();
|
|
269
|
-
this._value = _value;
|
|
270
|
-
}
|
|
271
|
-
get value() {
|
|
272
|
-
return this.getValue();
|
|
273
|
-
}
|
|
274
|
-
_subscribe(subscriber) {
|
|
275
|
-
const subscription = super._subscribe(subscriber);
|
|
276
|
-
if (subscription && !subscription.closed) {
|
|
277
|
-
subscriber.next(this._value);
|
|
278
|
-
}
|
|
279
|
-
return subscription;
|
|
280
|
-
}
|
|
281
|
-
getValue() {
|
|
282
|
-
if (this.hasError) {
|
|
283
|
-
throw this.thrownError;
|
|
284
|
-
}
|
|
285
|
-
else if (this.closed) {
|
|
286
|
-
throw new ObjectUnsubscribedError();
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
return this._value;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
next(value) {
|
|
293
|
-
super.next(this._value = value);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
class QueueAction extends AsyncAction {
|
|
298
|
-
constructor(scheduler, work) {
|
|
299
|
-
super(scheduler, work);
|
|
300
|
-
this.scheduler = scheduler;
|
|
301
|
-
this.work = work;
|
|
302
|
-
}
|
|
303
|
-
schedule(state, delay = 0) {
|
|
304
|
-
if (delay > 0) {
|
|
305
|
-
return super.schedule(state, delay);
|
|
306
|
-
}
|
|
307
|
-
this.delay = delay;
|
|
308
|
-
this.state = state;
|
|
309
|
-
this.scheduler.flush(this);
|
|
310
|
-
return this;
|
|
311
|
-
}
|
|
312
|
-
execute(state, delay) {
|
|
313
|
-
return (delay > 0 || this.closed) ?
|
|
314
|
-
super.execute(state, delay) :
|
|
315
|
-
this._execute(state, delay);
|
|
316
|
-
}
|
|
317
|
-
requestAsyncId(scheduler, id, delay = 0) {
|
|
318
|
-
if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {
|
|
319
|
-
return super.requestAsyncId(scheduler, id, delay);
|
|
320
|
-
}
|
|
321
|
-
return scheduler.flush(this);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
class QueueScheduler extends AsyncScheduler {
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
const queueScheduler = new QueueScheduler(QueueAction);
|
|
329
|
-
const queue = queueScheduler;
|
|
330
|
-
|
|
331
|
-
class ReplaySubject extends Subject {
|
|
332
|
-
constructor(bufferSize = Number.POSITIVE_INFINITY, windowTime = Number.POSITIVE_INFINITY, scheduler) {
|
|
333
|
-
super();
|
|
334
|
-
this.scheduler = scheduler;
|
|
335
|
-
this._events = [];
|
|
336
|
-
this._infiniteTimeWindow = false;
|
|
337
|
-
this._bufferSize = bufferSize < 1 ? 1 : bufferSize;
|
|
338
|
-
this._windowTime = windowTime < 1 ? 1 : windowTime;
|
|
339
|
-
if (windowTime === Number.POSITIVE_INFINITY) {
|
|
340
|
-
this._infiniteTimeWindow = true;
|
|
341
|
-
this.next = this.nextInfiniteTimeWindow;
|
|
342
|
-
}
|
|
343
|
-
else {
|
|
344
|
-
this.next = this.nextTimeWindow;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
nextInfiniteTimeWindow(value) {
|
|
348
|
-
if (!this.isStopped) {
|
|
349
|
-
const _events = this._events;
|
|
350
|
-
_events.push(value);
|
|
351
|
-
if (_events.length > this._bufferSize) {
|
|
352
|
-
_events.shift();
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
super.next(value);
|
|
356
|
-
}
|
|
357
|
-
nextTimeWindow(value) {
|
|
358
|
-
if (!this.isStopped) {
|
|
359
|
-
this._events.push(new ReplayEvent(this._getNow(), value));
|
|
360
|
-
this._trimBufferThenGetEvents();
|
|
361
|
-
}
|
|
362
|
-
super.next(value);
|
|
363
|
-
}
|
|
364
|
-
_subscribe(subscriber) {
|
|
365
|
-
const _infiniteTimeWindow = this._infiniteTimeWindow;
|
|
366
|
-
const _events = _infiniteTimeWindow ? this._events : this._trimBufferThenGetEvents();
|
|
367
|
-
const scheduler = this.scheduler;
|
|
368
|
-
const len = _events.length;
|
|
369
|
-
let subscription;
|
|
370
|
-
if (this.closed) {
|
|
371
|
-
throw new ObjectUnsubscribedError();
|
|
372
|
-
}
|
|
373
|
-
else if (this.isStopped || this.hasError) {
|
|
374
|
-
subscription = Subscription.EMPTY;
|
|
375
|
-
}
|
|
376
|
-
else {
|
|
377
|
-
this.observers.push(subscriber);
|
|
378
|
-
subscription = new SubjectSubscription(this, subscriber);
|
|
379
|
-
}
|
|
380
|
-
if (scheduler) {
|
|
381
|
-
subscriber.add(subscriber = new ObserveOnSubscriber(subscriber, scheduler));
|
|
382
|
-
}
|
|
383
|
-
if (_infiniteTimeWindow) {
|
|
384
|
-
for (let i = 0; i < len && !subscriber.closed; i++) {
|
|
385
|
-
subscriber.next(_events[i]);
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
389
|
-
for (let i = 0; i < len && !subscriber.closed; i++) {
|
|
390
|
-
subscriber.next(_events[i].value);
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
if (this.hasError) {
|
|
394
|
-
subscriber.error(this.thrownError);
|
|
395
|
-
}
|
|
396
|
-
else if (this.isStopped) {
|
|
397
|
-
subscriber.complete();
|
|
398
|
-
}
|
|
399
|
-
return subscription;
|
|
400
|
-
}
|
|
401
|
-
_getNow() {
|
|
402
|
-
return (this.scheduler || queue).now();
|
|
403
|
-
}
|
|
404
|
-
_trimBufferThenGetEvents() {
|
|
405
|
-
const now = this._getNow();
|
|
406
|
-
const _bufferSize = this._bufferSize;
|
|
407
|
-
const _windowTime = this._windowTime;
|
|
408
|
-
const _events = this._events;
|
|
409
|
-
const eventsCount = _events.length;
|
|
410
|
-
let spliceCount = 0;
|
|
411
|
-
while (spliceCount < eventsCount) {
|
|
412
|
-
if ((now - _events[spliceCount].time) < _windowTime) {
|
|
413
|
-
break;
|
|
414
|
-
}
|
|
415
|
-
spliceCount++;
|
|
416
|
-
}
|
|
417
|
-
if (eventsCount > _bufferSize) {
|
|
418
|
-
spliceCount = Math.max(spliceCount, eventsCount - _bufferSize);
|
|
419
|
-
}
|
|
420
|
-
if (spliceCount > 0) {
|
|
421
|
-
_events.splice(0, spliceCount);
|
|
422
|
-
}
|
|
423
|
-
return _events;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
class ReplayEvent {
|
|
427
|
-
constructor(time, value) {
|
|
428
|
-
this.time = time;
|
|
429
|
-
this.value = value;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
function skip(count) {
|
|
434
|
-
return (source) => source.lift(new SkipOperator(count));
|
|
435
|
-
}
|
|
436
|
-
class SkipOperator {
|
|
437
|
-
constructor(total) {
|
|
438
|
-
this.total = total;
|
|
439
|
-
}
|
|
440
|
-
call(subscriber, source) {
|
|
441
|
-
return source.subscribe(new SkipSubscriber(subscriber, this.total));
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
class SkipSubscriber extends Subscriber {
|
|
445
|
-
constructor(destination, total) {
|
|
446
|
-
super(destination);
|
|
447
|
-
this.total = total;
|
|
448
|
-
this.count = 0;
|
|
449
|
-
}
|
|
450
|
-
_next(x) {
|
|
451
|
-
if (++this.count > this.total) {
|
|
452
|
-
this.destination.next(x);
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
function switchMap(project, resultSelector) {
|
|
458
|
-
if (typeof resultSelector === 'function') {
|
|
459
|
-
return (source) => source.pipe(switchMap((a, i) => from(project(a, i)).pipe(map((b, ii) => resultSelector(a, b, i, ii)))));
|
|
460
|
-
}
|
|
461
|
-
return (source) => source.lift(new SwitchMapOperator(project));
|
|
462
|
-
}
|
|
463
|
-
class SwitchMapOperator {
|
|
464
|
-
constructor(project) {
|
|
465
|
-
this.project = project;
|
|
466
|
-
}
|
|
467
|
-
call(subscriber, source) {
|
|
468
|
-
return source.subscribe(new SwitchMapSubscriber(subscriber, this.project));
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
class SwitchMapSubscriber extends SimpleOuterSubscriber {
|
|
472
|
-
constructor(destination, project) {
|
|
473
|
-
super(destination);
|
|
474
|
-
this.project = project;
|
|
475
|
-
this.index = 0;
|
|
476
|
-
}
|
|
477
|
-
_next(value) {
|
|
478
|
-
let result;
|
|
479
|
-
const index = this.index++;
|
|
480
|
-
try {
|
|
481
|
-
result = this.project(value, index);
|
|
482
|
-
}
|
|
483
|
-
catch (error) {
|
|
484
|
-
this.destination.error(error);
|
|
485
|
-
return;
|
|
486
|
-
}
|
|
487
|
-
this._innerSub(result);
|
|
488
|
-
}
|
|
489
|
-
_innerSub(result) {
|
|
490
|
-
const innerSubscription = this.innerSubscription;
|
|
491
|
-
if (innerSubscription) {
|
|
492
|
-
innerSubscription.unsubscribe();
|
|
493
|
-
}
|
|
494
|
-
const innerSubscriber = new SimpleInnerSubscriber(this);
|
|
495
|
-
const destination = this.destination;
|
|
496
|
-
destination.add(innerSubscriber);
|
|
497
|
-
this.innerSubscription = innerSubscribe(result, innerSubscriber);
|
|
498
|
-
if (this.innerSubscription !== innerSubscriber) {
|
|
499
|
-
destination.add(this.innerSubscription);
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
_complete() {
|
|
503
|
-
const { innerSubscription } = this;
|
|
504
|
-
if (!innerSubscription || innerSubscription.closed) {
|
|
505
|
-
super._complete();
|
|
506
|
-
}
|
|
507
|
-
this.unsubscribe();
|
|
508
|
-
}
|
|
509
|
-
_unsubscribe() {
|
|
510
|
-
this.innerSubscription = undefined;
|
|
511
|
-
}
|
|
512
|
-
notifyComplete() {
|
|
513
|
-
this.innerSubscription = undefined;
|
|
514
|
-
if (this.isStopped) {
|
|
515
|
-
super._complete();
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
notifyNext(innerValue) {
|
|
519
|
-
this.destination.next(innerValue);
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
function isObservable(obj) {
|
|
524
|
-
return !!obj && (obj instanceof Observable || (typeof obj.lift === 'function' && typeof obj.subscribe === 'function'));
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
/*! *****************************************************************************
|
|
528
|
-
Copyright (c) Microsoft Corporation.
|
|
529
|
-
|
|
530
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
531
|
-
purpose with or without fee is hereby granted.
|
|
532
|
-
|
|
533
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
534
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
535
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
536
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
537
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
538
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
539
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
540
|
-
***************************************************************************** */
|
|
541
|
-
|
|
542
|
-
function __rest(s, e) {
|
|
543
|
-
var t = {};
|
|
544
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
545
|
-
t[p] = s[p];
|
|
546
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
547
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
548
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
549
|
-
t[p[i]] = s[p[i]];
|
|
550
|
-
}
|
|
551
|
-
return t;
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
function __decorate(decorators, target, key, desc) {
|
|
555
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
556
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
557
|
-
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;
|
|
558
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
function __metadata(metadataKey, metadataValue) {
|
|
562
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
const currentAction = {
|
|
566
|
-
type: null,
|
|
567
|
-
entityIds: null,
|
|
568
|
-
skip: false,
|
|
569
|
-
payload: null
|
|
570
|
-
};
|
|
571
|
-
let customActionActive = false;
|
|
572
|
-
function resetCustomAction() {
|
|
573
|
-
customActionActive = false;
|
|
574
|
-
}
|
|
575
|
-
// public API for custom actions. Custom action always wins
|
|
576
|
-
function logAction(type, entityIds, payload) {
|
|
577
|
-
setAction(type, entityIds, payload);
|
|
578
|
-
customActionActive = true;
|
|
579
|
-
}
|
|
580
|
-
function setAction(type, entityIds, payload) {
|
|
581
|
-
if (customActionActive === false) {
|
|
582
|
-
currentAction.type = type;
|
|
583
|
-
currentAction.entityIds = entityIds;
|
|
584
|
-
currentAction.payload = payload;
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
function action(action, entityIds) {
|
|
588
|
-
return function (target, propertyKey, descriptor) {
|
|
589
|
-
const originalMethod = descriptor.value;
|
|
590
|
-
descriptor.value = function (...args) {
|
|
591
|
-
logAction(action, entityIds);
|
|
592
|
-
return originalMethod.apply(this, args);
|
|
593
|
-
};
|
|
594
|
-
return descriptor;
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
// @internal
|
|
599
|
-
function hasEntity(entities, id) {
|
|
600
|
-
return entities.hasOwnProperty(id);
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
// @internal
|
|
604
|
-
function isArray(value) {
|
|
605
|
-
return Array.isArray(value);
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
// @internal
|
|
609
|
-
function hasActiveState(state) {
|
|
610
|
-
return state.hasOwnProperty('active');
|
|
611
|
-
}
|
|
612
|
-
// @internal
|
|
613
|
-
function isMultiActiveState(active) {
|
|
614
|
-
return isArray(active);
|
|
615
|
-
}
|
|
616
|
-
// @internal
|
|
617
|
-
function resolveActiveEntity({ active, ids, entities }) {
|
|
618
|
-
if (isMultiActiveState(active)) {
|
|
619
|
-
return getExitingActives(active, ids);
|
|
620
|
-
}
|
|
621
|
-
if (hasEntity(entities, active) === false) {
|
|
622
|
-
return null;
|
|
623
|
-
}
|
|
624
|
-
return active;
|
|
625
|
-
}
|
|
626
|
-
// @internal
|
|
627
|
-
function getExitingActives(currentActivesIds, newIds) {
|
|
628
|
-
const filtered = currentActivesIds.filter(id => newIds.indexOf(id) > -1);
|
|
629
|
-
/** Return the same reference if nothing has changed */
|
|
630
|
-
if (filtered.length === currentActivesIds.length) {
|
|
631
|
-
return currentActivesIds;
|
|
632
|
-
}
|
|
633
|
-
return filtered;
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
// @internal
|
|
637
|
-
function addEntities({ state, entities, idKey, options = {}, preAddEntity }) {
|
|
638
|
-
let newEntities = {};
|
|
639
|
-
let newIds = [];
|
|
640
|
-
let hasNewEntities = false;
|
|
641
|
-
for (const entity of entities) {
|
|
642
|
-
if (hasEntity(state.entities, entity[idKey]) === false) {
|
|
643
|
-
// evaluate the middleware first to support dynamic ids
|
|
644
|
-
const current = preAddEntity(entity);
|
|
645
|
-
const entityId = current[idKey];
|
|
646
|
-
newEntities[entityId] = current;
|
|
647
|
-
if (options.prepend)
|
|
648
|
-
newIds.unshift(entityId);
|
|
649
|
-
else
|
|
650
|
-
newIds.push(entityId);
|
|
651
|
-
hasNewEntities = true;
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
return hasNewEntities
|
|
655
|
-
? {
|
|
656
|
-
newState: Object.assign(Object.assign({}, state), { entities: Object.assign(Object.assign({}, state.entities), newEntities), ids: options.prepend ? [...newIds, ...state.ids] : [...state.ids, ...newIds] }),
|
|
657
|
-
newIds
|
|
658
|
-
}
|
|
659
|
-
: null;
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
// @internal
|
|
663
|
-
function isNil(v) {
|
|
664
|
-
return v === null || v === undefined;
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
// @internal
|
|
668
|
-
function coerceArray(value) {
|
|
669
|
-
if (isNil(value)) {
|
|
670
|
-
return [];
|
|
671
|
-
}
|
|
672
|
-
return Array.isArray(value) ? value : [value];
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
const DEFAULT_ID_KEY = 'id';
|
|
676
|
-
|
|
677
|
-
// @internal
|
|
678
|
-
function isFunction(value) {
|
|
679
|
-
return typeof value === 'function';
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
// @internal
|
|
683
|
-
function isEmpty(arr) {
|
|
684
|
-
if (isArray(arr)) {
|
|
685
|
-
return arr.length === 0;
|
|
686
|
-
}
|
|
687
|
-
return false;
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
// @internal
|
|
691
|
-
function isObject(value) {
|
|
692
|
-
const type = typeof value;
|
|
693
|
-
return value != null && (type == 'object' || type == 'function');
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
let CONFIG = {
|
|
697
|
-
resettable: false,
|
|
698
|
-
ttl: null,
|
|
699
|
-
producerFn: undefined
|
|
700
|
-
};
|
|
701
|
-
// @internal
|
|
702
|
-
function getAkitaConfig() {
|
|
703
|
-
return CONFIG;
|
|
704
|
-
}
|
|
705
|
-
function getGlobalProducerFn() {
|
|
706
|
-
return CONFIG.producerFn;
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
// @internal
|
|
710
|
-
function isDefined(val) {
|
|
711
|
-
return isNil(val) === false;
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
// @internal
|
|
715
|
-
const $$deleteStore = new Subject();
|
|
716
|
-
// @internal
|
|
717
|
-
const $$addStore = new ReplaySubject(50, 5000);
|
|
718
|
-
// @internal
|
|
719
|
-
const $$updateStore = new Subject();
|
|
720
|
-
// @internal
|
|
721
|
-
function dispatchDeleted(storeName) {
|
|
722
|
-
$$deleteStore.next(storeName);
|
|
723
|
-
}
|
|
724
|
-
// @internal
|
|
725
|
-
function dispatchAdded(storeName) {
|
|
726
|
-
$$addStore.next(storeName);
|
|
727
|
-
}
|
|
728
|
-
// @internal
|
|
729
|
-
function dispatchUpdate(storeName, action) {
|
|
730
|
-
$$updateStore.next({ storeName, action });
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
const isBrowser = typeof window !== 'undefined';
|
|
734
|
-
const isNotBrowser = !isBrowser;
|
|
735
|
-
// export const isNativeScript = typeof global !== 'undefined' && (<any>global).__runtimeVersion !== 'undefined'; TODO is this used?
|
|
736
|
-
const hasLocalStorage = () => {
|
|
737
|
-
try {
|
|
738
|
-
return typeof localStorage !== 'undefined';
|
|
739
|
-
}
|
|
740
|
-
catch (_a) {
|
|
741
|
-
return false;
|
|
742
|
-
}
|
|
743
|
-
};
|
|
744
|
-
const hasSessionStorage = () => {
|
|
745
|
-
try {
|
|
746
|
-
return typeof sessionStorage !== 'undefined';
|
|
747
|
-
}
|
|
748
|
-
catch (_a) {
|
|
749
|
-
return false;
|
|
750
|
-
}
|
|
751
|
-
};
|
|
752
|
-
|
|
753
|
-
// @internal
|
|
754
|
-
const __stores__ = {};
|
|
755
|
-
// @internal
|
|
756
|
-
const __queries__ = {};
|
|
757
|
-
if (isBrowser) {
|
|
758
|
-
window.$$stores = __stores__;
|
|
759
|
-
window.$$queries = __queries__;
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
var Order;
|
|
763
|
-
(function (Order) {
|
|
764
|
-
Order["ASC"] = "asc";
|
|
765
|
-
Order["DESC"] = "desc";
|
|
766
|
-
})(Order || (Order = {}));
|
|
767
|
-
|
|
768
|
-
var EntityActions;
|
|
769
|
-
(function (EntityActions) {
|
|
770
|
-
EntityActions["Set"] = "Set";
|
|
771
|
-
EntityActions["Add"] = "Add";
|
|
772
|
-
EntityActions["Update"] = "Update";
|
|
773
|
-
EntityActions["Remove"] = "Remove";
|
|
774
|
-
})(EntityActions || (EntityActions = {}));
|
|
775
|
-
|
|
776
|
-
let __DEV__ = true;
|
|
777
|
-
function enableAkitaProdMode() {
|
|
778
|
-
__DEV__ = false;
|
|
779
|
-
if (isBrowser) {
|
|
780
|
-
delete window.$$stores;
|
|
781
|
-
delete window.$$queries;
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
// @internal
|
|
785
|
-
function isDev() {
|
|
786
|
-
return __DEV__;
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
// @internal
|
|
790
|
-
function getActiveEntities(idOrOptions, ids, currentActive) {
|
|
791
|
-
let result;
|
|
792
|
-
if (isArray(idOrOptions)) {
|
|
793
|
-
result = idOrOptions;
|
|
794
|
-
}
|
|
795
|
-
else {
|
|
796
|
-
if (isObject(idOrOptions)) {
|
|
797
|
-
if (isNil(currentActive))
|
|
798
|
-
return;
|
|
799
|
-
idOrOptions = Object.assign({ wrap: true }, idOrOptions);
|
|
800
|
-
const currentIdIndex = ids.indexOf(currentActive);
|
|
801
|
-
if (idOrOptions.prev) {
|
|
802
|
-
const isFirst = currentIdIndex === 0;
|
|
803
|
-
if (isFirst && !idOrOptions.wrap)
|
|
804
|
-
return;
|
|
805
|
-
result = isFirst ? ids[ids.length - 1] : ids[currentIdIndex - 1];
|
|
806
|
-
}
|
|
807
|
-
else if (idOrOptions.next) {
|
|
808
|
-
const isLast = ids.length === currentIdIndex + 1;
|
|
809
|
-
if (isLast && !idOrOptions.wrap)
|
|
810
|
-
return;
|
|
811
|
-
result = isLast ? ids[0] : ids[currentIdIndex + 1];
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
else {
|
|
815
|
-
if (idOrOptions === currentActive)
|
|
816
|
-
return;
|
|
817
|
-
result = idOrOptions;
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
return result;
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
// @internal
|
|
824
|
-
const getInitialEntitiesState = () => ({
|
|
825
|
-
entities: {},
|
|
826
|
-
ids: [],
|
|
827
|
-
loading: true,
|
|
828
|
-
error: null
|
|
829
|
-
});
|
|
830
|
-
|
|
831
|
-
// @internal
|
|
832
|
-
function isUndefined(value) {
|
|
833
|
-
return value === undefined;
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
// @internal
|
|
837
|
-
function removeEntities({ state, ids }) {
|
|
838
|
-
if (isNil(ids))
|
|
839
|
-
return removeAllEntities(state);
|
|
840
|
-
const entities = state.entities;
|
|
841
|
-
let newEntities = {};
|
|
842
|
-
for (const id of state.ids) {
|
|
843
|
-
if (ids.includes(id) === false) {
|
|
844
|
-
newEntities[id] = entities[id];
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
const newState = Object.assign(Object.assign({}, state), { entities: newEntities, ids: state.ids.filter(current => ids.includes(current) === false) });
|
|
848
|
-
if (hasActiveState(state)) {
|
|
849
|
-
newState.active = resolveActiveEntity(newState);
|
|
850
|
-
}
|
|
851
|
-
return newState;
|
|
852
|
-
}
|
|
853
|
-
// @internal
|
|
854
|
-
function removeAllEntities(state) {
|
|
855
|
-
return Object.assign(Object.assign({}, state), { entities: {}, ids: [], active: isMultiActiveState(state.active) ? [] : null });
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
// @internal
|
|
859
|
-
function toEntitiesObject(entities, idKey, preAddEntity) {
|
|
860
|
-
const acc = {
|
|
861
|
-
entities: {},
|
|
862
|
-
ids: []
|
|
863
|
-
};
|
|
864
|
-
for (const entity of entities) {
|
|
865
|
-
// evaluate the middleware first to support dynamic ids
|
|
866
|
-
const current = preAddEntity(entity);
|
|
867
|
-
acc.entities[current[idKey]] = current;
|
|
868
|
-
acc.ids.push(current[idKey]);
|
|
869
|
-
}
|
|
870
|
-
return acc;
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
// @internal
|
|
874
|
-
function isEntityState(state) {
|
|
875
|
-
return state.entities && state.ids;
|
|
876
|
-
}
|
|
877
|
-
// @internal
|
|
878
|
-
function applyMiddleware(entities, preAddEntity) {
|
|
879
|
-
let mapped = {};
|
|
880
|
-
for (const id of Object.keys(entities)) {
|
|
881
|
-
mapped[id] = preAddEntity(entities[id]);
|
|
882
|
-
}
|
|
883
|
-
return mapped;
|
|
884
|
-
}
|
|
885
|
-
// @internal
|
|
886
|
-
function setEntities({ state, entities, idKey, preAddEntity, isNativePreAdd }) {
|
|
887
|
-
let newEntities;
|
|
888
|
-
let newIds;
|
|
889
|
-
if (isArray(entities)) {
|
|
890
|
-
const resolve = toEntitiesObject(entities, idKey, preAddEntity);
|
|
891
|
-
newEntities = resolve.entities;
|
|
892
|
-
newIds = resolve.ids;
|
|
893
|
-
}
|
|
894
|
-
else if (isEntityState(entities)) {
|
|
895
|
-
newEntities = isNativePreAdd ? entities.entities : applyMiddleware(entities.entities, preAddEntity);
|
|
896
|
-
newIds = entities.ids;
|
|
897
|
-
}
|
|
898
|
-
else {
|
|
899
|
-
// it's an object
|
|
900
|
-
newEntities = isNativePreAdd ? entities : applyMiddleware(entities, preAddEntity);
|
|
901
|
-
newIds = Object.keys(newEntities).map(id => (isNaN(id) ? id : Number(id)));
|
|
902
|
-
}
|
|
903
|
-
const newState = Object.assign(Object.assign({}, state), { entities: newEntities, ids: newIds, loading: false });
|
|
904
|
-
if (hasActiveState(state)) {
|
|
905
|
-
newState.active = resolveActiveEntity(newState);
|
|
906
|
-
}
|
|
907
|
-
return newState;
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
// @internal
|
|
911
|
-
function deepFreeze(o) {
|
|
912
|
-
Object.freeze(o);
|
|
913
|
-
const oIsFunction = typeof o === 'function';
|
|
914
|
-
const hasOwnProp = Object.prototype.hasOwnProperty;
|
|
915
|
-
Object.getOwnPropertyNames(o).forEach(function (prop) {
|
|
916
|
-
if (hasOwnProp.call(o, prop) &&
|
|
917
|
-
(oIsFunction ? prop !== 'caller' && prop !== 'callee' && prop !== 'arguments' : true) &&
|
|
918
|
-
o[prop] !== null &&
|
|
919
|
-
(typeof o[prop] === 'object' || typeof o[prop] === 'function') &&
|
|
920
|
-
!Object.isFrozen(o[prop])) {
|
|
921
|
-
deepFreeze(o[prop]);
|
|
922
|
-
}
|
|
923
|
-
});
|
|
924
|
-
return o;
|
|
925
|
-
}
|
|
926
|
-
// @internal
|
|
927
|
-
function assertStoreHasName(name, className) {
|
|
928
|
-
if (!name) {
|
|
929
|
-
console.error(`@StoreConfig({ name }) is missing in ${className}`);
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
// @internal
|
|
934
|
-
function toBoolean(value) {
|
|
935
|
-
return value != null && `${value}` !== 'false';
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
// @internal
|
|
939
|
-
function isPlainObject(value) {
|
|
940
|
-
return toBoolean(value) && value.constructor.name === 'Object';
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
const configKey = 'akitaConfig';
|
|
944
|
-
function StoreConfig(metadata) {
|
|
945
|
-
return function (constructor) {
|
|
946
|
-
constructor[configKey] = { idKey: 'id' };
|
|
947
|
-
for (let i = 0, keys = Object.keys(metadata); i < keys.length; i++) {
|
|
948
|
-
const key = keys[i];
|
|
949
|
-
/* name is preserved read only key */
|
|
950
|
-
if (key === 'name') {
|
|
951
|
-
constructor[configKey]['storeName'] = metadata[key];
|
|
952
|
-
}
|
|
953
|
-
else {
|
|
954
|
-
constructor[configKey][key] = metadata[key];
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
};
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
// @internal
|
|
961
|
-
const transactionFinished = new Subject();
|
|
962
|
-
// @internal
|
|
963
|
-
const transactionInProcess = new BehaviorSubject(false);
|
|
964
|
-
// @internal
|
|
965
|
-
const transactionManager = {
|
|
966
|
-
activeTransactions: 0,
|
|
967
|
-
batchTransaction: null
|
|
968
|
-
};
|
|
969
|
-
// @internal
|
|
970
|
-
function startBatch() {
|
|
971
|
-
if (!isTransactionInProcess()) {
|
|
972
|
-
transactionManager.batchTransaction = new Subject();
|
|
973
|
-
}
|
|
974
|
-
transactionManager.activeTransactions++;
|
|
975
|
-
transactionInProcess.next(true);
|
|
976
|
-
}
|
|
977
|
-
// @internal
|
|
978
|
-
function endBatch() {
|
|
979
|
-
if (--transactionManager.activeTransactions === 0) {
|
|
980
|
-
transactionManager.batchTransaction.next(true);
|
|
981
|
-
transactionManager.batchTransaction.complete();
|
|
982
|
-
transactionInProcess.next(false);
|
|
983
|
-
transactionFinished.next(true);
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
// @internal
|
|
987
|
-
function isTransactionInProcess() {
|
|
988
|
-
return transactionManager.activeTransactions > 0;
|
|
989
|
-
}
|
|
990
|
-
// @internal
|
|
991
|
-
function commit() {
|
|
992
|
-
return transactionManager.batchTransaction ? transactionManager.batchTransaction.asObservable() : of(true);
|
|
993
|
-
}
|
|
994
|
-
/**
|
|
995
|
-
* A logical transaction.
|
|
996
|
-
* Use this transaction to optimize the dispatch of all the stores.
|
|
997
|
-
* The following code will update the store, BUT emits only once
|
|
998
|
-
*
|
|
999
|
-
* @example
|
|
1000
|
-
* applyTransaction(() => {
|
|
1001
|
-
* this.todosStore.add(new Todo(1, title));
|
|
1002
|
-
* this.todosStore.add(new Todo(2, title));
|
|
1003
|
-
* });
|
|
1004
|
-
*
|
|
1005
|
-
*/
|
|
1006
|
-
function applyTransaction(action, thisArg = undefined) {
|
|
1007
|
-
startBatch();
|
|
1008
|
-
try {
|
|
1009
|
-
return action.apply(thisArg);
|
|
1010
|
-
}
|
|
1011
|
-
finally {
|
|
1012
|
-
logAction('@Transaction');
|
|
1013
|
-
endBatch();
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
/**
|
|
1017
|
-
* A logical transaction.
|
|
1018
|
-
* Use this transaction to optimize the dispatch of all the stores.
|
|
1019
|
-
*
|
|
1020
|
-
* The following code will update the store, BUT emits only once.
|
|
1021
|
-
*
|
|
1022
|
-
* @example
|
|
1023
|
-
* @transaction
|
|
1024
|
-
* addTodos() {
|
|
1025
|
-
* this.todosStore.add(new Todo(1, title));
|
|
1026
|
-
* this.todosStore.add(new Todo(2, title));
|
|
1027
|
-
* }
|
|
1028
|
-
*
|
|
1029
|
-
*
|
|
1030
|
-
*/
|
|
1031
|
-
function transaction() {
|
|
1032
|
-
return function (target, propertyKey, descriptor) {
|
|
1033
|
-
const originalMethod = descriptor.value;
|
|
1034
|
-
descriptor.value = function (...args) {
|
|
1035
|
-
return applyTransaction(() => {
|
|
1036
|
-
return originalMethod.apply(this, args);
|
|
1037
|
-
}, this);
|
|
1038
|
-
};
|
|
1039
|
-
return descriptor;
|
|
1040
|
-
};
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
/**
|
|
1044
|
-
*
|
|
1045
|
-
* Store for managing any type of data
|
|
1046
|
-
*
|
|
1047
|
-
* @example
|
|
1048
|
-
*
|
|
1049
|
-
* export interface SessionState {
|
|
1050
|
-
* token: string;
|
|
1051
|
-
* userDetails: UserDetails
|
|
1052
|
-
* }
|
|
1053
|
-
*
|
|
1054
|
-
* export function createInitialState(): SessionState {
|
|
1055
|
-
* return {
|
|
1056
|
-
* token: '',
|
|
1057
|
-
* userDetails: null
|
|
1058
|
-
* };
|
|
1059
|
-
* }
|
|
1060
|
-
*
|
|
1061
|
-
* @StoreConfig({ name: 'session' })
|
|
1062
|
-
* export class SessionStore extends Store<SessionState> {
|
|
1063
|
-
* constructor() {
|
|
1064
|
-
* super(createInitialState());
|
|
1065
|
-
* }
|
|
1066
|
-
* }
|
|
1067
|
-
*/
|
|
1068
|
-
class Store {
|
|
1069
|
-
constructor(initialState, options = {}) {
|
|
1070
|
-
this.options = options;
|
|
1071
|
-
this.inTransaction = false;
|
|
1072
|
-
this.cache = {
|
|
1073
|
-
active: new BehaviorSubject(false),
|
|
1074
|
-
ttl: null,
|
|
1075
|
-
};
|
|
1076
|
-
this.onInit(initialState);
|
|
1077
|
-
}
|
|
1078
|
-
/**
|
|
1079
|
-
* Set the loading state
|
|
1080
|
-
*
|
|
1081
|
-
* @example
|
|
1082
|
-
*
|
|
1083
|
-
* store.setLoading(true)
|
|
1084
|
-
*
|
|
1085
|
-
*/
|
|
1086
|
-
setLoading(loading = false) {
|
|
1087
|
-
if (loading !== this._value().loading) {
|
|
1088
|
-
isDev() && setAction('Set Loading');
|
|
1089
|
-
this._setState((state) => (Object.assign(Object.assign({}, state), { loading })));
|
|
1090
|
-
}
|
|
1091
|
-
}
|
|
1092
|
-
/**
|
|
1093
|
-
*
|
|
1094
|
-
* Set whether the data is cached
|
|
1095
|
-
*
|
|
1096
|
-
* @example
|
|
1097
|
-
*
|
|
1098
|
-
* store.setHasCache(true)
|
|
1099
|
-
* store.setHasCache(false)
|
|
1100
|
-
* store.setHasCache(true, { restartTTL: true })
|
|
1101
|
-
*
|
|
1102
|
-
*/
|
|
1103
|
-
setHasCache(hasCache, options = { restartTTL: false }) {
|
|
1104
|
-
if (hasCache !== this.cache.active.value) {
|
|
1105
|
-
this.cache.active.next(hasCache);
|
|
1106
|
-
}
|
|
1107
|
-
if (options.restartTTL) {
|
|
1108
|
-
const ttlConfig = this.getCacheTTL();
|
|
1109
|
-
if (ttlConfig) {
|
|
1110
|
-
if (this.cache.ttl !== null) {
|
|
1111
|
-
clearTimeout(this.cache.ttl);
|
|
1112
|
-
}
|
|
1113
|
-
this.cache.ttl = setTimeout(() => this.setHasCache(false), ttlConfig);
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1117
|
-
/**
|
|
1118
|
-
*
|
|
1119
|
-
* Sometimes we need to access the store value from a store
|
|
1120
|
-
*
|
|
1121
|
-
* @example middleware
|
|
1122
|
-
*
|
|
1123
|
-
*/
|
|
1124
|
-
getValue() {
|
|
1125
|
-
return this.storeValue;
|
|
1126
|
-
}
|
|
1127
|
-
/**
|
|
1128
|
-
* Set the error state
|
|
1129
|
-
*
|
|
1130
|
-
* @example
|
|
1131
|
-
*
|
|
1132
|
-
* store.setError({text: 'unable to load data' })
|
|
1133
|
-
*
|
|
1134
|
-
*/
|
|
1135
|
-
setError(error) {
|
|
1136
|
-
if (error !== this._value().error) {
|
|
1137
|
-
isDev() && setAction('Set Error');
|
|
1138
|
-
this._setState((state) => (Object.assign(Object.assign({}, state), { error })));
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
// @internal
|
|
1142
|
-
_select(project) {
|
|
1143
|
-
return this.store.asObservable().pipe(map((snapshot) => project(snapshot.state)), distinctUntilChanged());
|
|
1144
|
-
}
|
|
1145
|
-
// @internal
|
|
1146
|
-
_value() {
|
|
1147
|
-
return this.storeValue;
|
|
1148
|
-
}
|
|
1149
|
-
// @internal
|
|
1150
|
-
_cache() {
|
|
1151
|
-
return this.cache.active;
|
|
1152
|
-
}
|
|
1153
|
-
// @internal
|
|
1154
|
-
get config() {
|
|
1155
|
-
return this.constructor[configKey] || {};
|
|
1156
|
-
}
|
|
1157
|
-
// @internal
|
|
1158
|
-
get storeName() {
|
|
1159
|
-
return this.config.storeName || this.options.storeName || this.options.name;
|
|
1160
|
-
}
|
|
1161
|
-
// @internal
|
|
1162
|
-
get deepFreeze() {
|
|
1163
|
-
return this.config.deepFreezeFn || this.options.deepFreezeFn || deepFreeze;
|
|
1164
|
-
}
|
|
1165
|
-
// @internal
|
|
1166
|
-
get cacheConfig() {
|
|
1167
|
-
return this.config.cache || this.options.cache;
|
|
1168
|
-
}
|
|
1169
|
-
get _producerFn() {
|
|
1170
|
-
return this.config.producerFn || this.options.producerFn || getGlobalProducerFn();
|
|
1171
|
-
}
|
|
1172
|
-
// @internal
|
|
1173
|
-
get resettable() {
|
|
1174
|
-
return isDefined(this.config.resettable) ? this.config.resettable : this.options.resettable;
|
|
1175
|
-
}
|
|
1176
|
-
// @internal
|
|
1177
|
-
_setState(newState, _dispatchAction = true) {
|
|
1178
|
-
if (isFunction(newState)) {
|
|
1179
|
-
const _newState = newState(this._value());
|
|
1180
|
-
this.storeValue = __DEV__ ? this.deepFreeze(_newState) : _newState;
|
|
1181
|
-
}
|
|
1182
|
-
else {
|
|
1183
|
-
this.storeValue = newState;
|
|
1184
|
-
}
|
|
1185
|
-
if (!this.store) {
|
|
1186
|
-
this.store = new BehaviorSubject({ state: this.storeValue });
|
|
1187
|
-
if (isDev()) {
|
|
1188
|
-
this.store.subscribe(({ action }) => {
|
|
1189
|
-
if (action) {
|
|
1190
|
-
dispatchUpdate(this.storeName, action);
|
|
1191
|
-
}
|
|
1192
|
-
});
|
|
1193
|
-
}
|
|
1194
|
-
return;
|
|
1195
|
-
}
|
|
1196
|
-
if (isTransactionInProcess()) {
|
|
1197
|
-
this.handleTransaction();
|
|
1198
|
-
return;
|
|
1199
|
-
}
|
|
1200
|
-
this.dispatch(this.storeValue, _dispatchAction);
|
|
1201
|
-
}
|
|
1202
|
-
/**
|
|
1203
|
-
*
|
|
1204
|
-
* Reset the current store back to the initial value
|
|
1205
|
-
*
|
|
1206
|
-
* @example
|
|
1207
|
-
*
|
|
1208
|
-
* store.reset()
|
|
1209
|
-
*
|
|
1210
|
-
*/
|
|
1211
|
-
reset() {
|
|
1212
|
-
if (this.isResettable()) {
|
|
1213
|
-
isDev() && setAction('Reset');
|
|
1214
|
-
this._setState(() => Object.assign({}, this._initialState));
|
|
1215
|
-
this.setHasCache(false);
|
|
1216
|
-
}
|
|
1217
|
-
else {
|
|
1218
|
-
isDev() && console.warn(`You need to enable the reset functionality`);
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
update(stateOrCallback) {
|
|
1222
|
-
isDev() && setAction('Update');
|
|
1223
|
-
let newState;
|
|
1224
|
-
const currentState = this._value();
|
|
1225
|
-
if (isFunction(stateOrCallback)) {
|
|
1226
|
-
newState = isFunction(this._producerFn) ? this._producerFn(currentState, stateOrCallback) : stateOrCallback(currentState);
|
|
1227
|
-
}
|
|
1228
|
-
else {
|
|
1229
|
-
newState = stateOrCallback;
|
|
1230
|
-
}
|
|
1231
|
-
const withHook = this.akitaPreUpdate(currentState, Object.assign(Object.assign({}, currentState), newState));
|
|
1232
|
-
const resolved = isPlainObject(currentState) ? withHook : new currentState.constructor(withHook);
|
|
1233
|
-
this._setState(resolved);
|
|
1234
|
-
}
|
|
1235
|
-
updateStoreConfig(newOptions) {
|
|
1236
|
-
this.options = Object.assign(Object.assign({}, this.options), newOptions);
|
|
1237
|
-
}
|
|
1238
|
-
// @internal
|
|
1239
|
-
akitaPreUpdate(_, nextState) {
|
|
1240
|
-
return nextState;
|
|
1241
|
-
}
|
|
1242
|
-
ngOnDestroy() {
|
|
1243
|
-
this.destroy();
|
|
1244
|
-
}
|
|
1245
|
-
/**
|
|
1246
|
-
*
|
|
1247
|
-
* Destroy the store
|
|
1248
|
-
*
|
|
1249
|
-
* @example
|
|
1250
|
-
*
|
|
1251
|
-
* store.destroy()
|
|
1252
|
-
*
|
|
1253
|
-
*/
|
|
1254
|
-
destroy() {
|
|
1255
|
-
const hmrEnabled = isBrowser ? window.hmrEnabled : false;
|
|
1256
|
-
if (!hmrEnabled && this === __stores__[this.storeName]) {
|
|
1257
|
-
delete __stores__[this.storeName];
|
|
1258
|
-
dispatchDeleted(this.storeName);
|
|
1259
|
-
this.setHasCache(false);
|
|
1260
|
-
this.cache.active.complete();
|
|
1261
|
-
this.store.complete();
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
onInit(initialState) {
|
|
1265
|
-
__stores__[this.storeName] = this;
|
|
1266
|
-
this._setState(() => initialState);
|
|
1267
|
-
dispatchAdded(this.storeName);
|
|
1268
|
-
if (this.isResettable()) {
|
|
1269
|
-
this._initialState = initialState;
|
|
1270
|
-
}
|
|
1271
|
-
isDev() && assertStoreHasName(this.storeName, this.constructor.name);
|
|
1272
|
-
}
|
|
1273
|
-
dispatch(state, _dispatchAction = true) {
|
|
1274
|
-
let action = undefined;
|
|
1275
|
-
if (_dispatchAction) {
|
|
1276
|
-
action = currentAction;
|
|
1277
|
-
resetCustomAction();
|
|
1278
|
-
}
|
|
1279
|
-
this.store.next({ state, action });
|
|
1280
|
-
}
|
|
1281
|
-
watchTransaction() {
|
|
1282
|
-
commit().subscribe(() => {
|
|
1283
|
-
this.inTransaction = false;
|
|
1284
|
-
this.dispatch(this._value());
|
|
1285
|
-
});
|
|
1286
|
-
}
|
|
1287
|
-
isResettable() {
|
|
1288
|
-
if (this.resettable === false) {
|
|
1289
|
-
return false;
|
|
1290
|
-
}
|
|
1291
|
-
return this.resettable || getAkitaConfig().resettable;
|
|
1292
|
-
}
|
|
1293
|
-
handleTransaction() {
|
|
1294
|
-
if (!this.inTransaction) {
|
|
1295
|
-
this.watchTransaction();
|
|
1296
|
-
this.inTransaction = true;
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
1299
|
-
getCacheTTL() {
|
|
1300
|
-
return (this.cacheConfig && this.cacheConfig.ttl) || getAkitaConfig().ttl;
|
|
1301
|
-
}
|
|
1302
|
-
}
|
|
1303
|
-
|
|
1304
|
-
// @internal
|
|
1305
|
-
function updateEntities({ state, ids, idKey, newStateOrFn, preUpdateEntity, producerFn, onEntityIdChanges }) {
|
|
1306
|
-
const updatedEntities = {};
|
|
1307
|
-
let isUpdatingIdKey = false;
|
|
1308
|
-
let idToUpdate;
|
|
1309
|
-
for (const id of ids) {
|
|
1310
|
-
// if the entity doesn't exist don't do anything
|
|
1311
|
-
if (hasEntity(state.entities, id) === false) {
|
|
1312
|
-
continue;
|
|
1313
|
-
}
|
|
1314
|
-
const oldEntity = state.entities[id];
|
|
1315
|
-
let newState;
|
|
1316
|
-
if (isFunction(newStateOrFn)) {
|
|
1317
|
-
newState = isFunction(producerFn) ? producerFn(oldEntity, newStateOrFn) : newStateOrFn(oldEntity);
|
|
1318
|
-
}
|
|
1319
|
-
else {
|
|
1320
|
-
newState = newStateOrFn;
|
|
1321
|
-
}
|
|
1322
|
-
const isIdChanged = newState.hasOwnProperty(idKey) && newState[idKey] !== oldEntity[idKey];
|
|
1323
|
-
let newEntity;
|
|
1324
|
-
idToUpdate = id;
|
|
1325
|
-
if (isIdChanged) {
|
|
1326
|
-
isUpdatingIdKey = true;
|
|
1327
|
-
idToUpdate = newState[idKey];
|
|
1328
|
-
}
|
|
1329
|
-
const merged = Object.assign(Object.assign({}, oldEntity), newState);
|
|
1330
|
-
if (isPlainObject(oldEntity)) {
|
|
1331
|
-
newEntity = merged;
|
|
1332
|
-
}
|
|
1333
|
-
else {
|
|
1334
|
-
/**
|
|
1335
|
-
* In case that new state is class of it's own, there's
|
|
1336
|
-
* a possibility that it will be different than the old
|
|
1337
|
-
* class.
|
|
1338
|
-
* For example, Old state is an instance of animal class
|
|
1339
|
-
* and new state is instance of person class.
|
|
1340
|
-
* To avoid run over new person class with the old animal
|
|
1341
|
-
* class we check if the new state is a class of it's own.
|
|
1342
|
-
* If so, use it. Otherwise, use the old state class
|
|
1343
|
-
*/
|
|
1344
|
-
if (isPlainObject(newState)) {
|
|
1345
|
-
newEntity = new oldEntity.constructor(merged);
|
|
1346
|
-
}
|
|
1347
|
-
else {
|
|
1348
|
-
newEntity = new newState.constructor(merged);
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
updatedEntities[idToUpdate] = preUpdateEntity(oldEntity, newEntity);
|
|
1352
|
-
}
|
|
1353
|
-
let updatedIds = state.ids;
|
|
1354
|
-
let stateEntities = state.entities;
|
|
1355
|
-
if (isUpdatingIdKey) {
|
|
1356
|
-
const [id] = ids;
|
|
1357
|
-
const _a = state.entities, _b = id, rest = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
1358
|
-
stateEntities = rest;
|
|
1359
|
-
updatedIds = state.ids.map((current) => (current === id ? idToUpdate : current));
|
|
1360
|
-
onEntityIdChanges(id, idToUpdate);
|
|
1361
|
-
}
|
|
1362
|
-
return Object.assign(Object.assign({}, state), { entities: Object.assign(Object.assign({}, stateEntities), updatedEntities), ids: updatedIds });
|
|
1363
|
-
}
|
|
1364
|
-
|
|
1365
|
-
var _b;
|
|
1366
|
-
/**
|
|
1367
|
-
*
|
|
1368
|
-
* Store for managing a collection of entities
|
|
1369
|
-
*
|
|
1370
|
-
* @example
|
|
1371
|
-
*
|
|
1372
|
-
* export interface WidgetsState extends EntityState<Widget> { }
|
|
1373
|
-
*
|
|
1374
|
-
* @StoreConfig({ name: 'widgets' })
|
|
1375
|
-
* export class WidgetsStore extends EntityStore<WidgetsState> {
|
|
1376
|
-
* constructor() {
|
|
1377
|
-
* super();
|
|
1378
|
-
* }
|
|
1379
|
-
* }
|
|
1380
|
-
*
|
|
1381
|
-
*
|
|
1382
|
-
*/
|
|
1383
|
-
class EntityStore extends Store {
|
|
1384
|
-
constructor(initialState = {}, options = {}) {
|
|
1385
|
-
super(Object.assign(Object.assign({}, getInitialEntitiesState()), initialState), options);
|
|
1386
|
-
this.options = options;
|
|
1387
|
-
this.entityActions = new Subject();
|
|
1388
|
-
this.entityIdChanges = new Subject();
|
|
1389
|
-
}
|
|
1390
|
-
// @internal
|
|
1391
|
-
get selectEntityAction$() {
|
|
1392
|
-
return this.entityActions.asObservable();
|
|
1393
|
-
}
|
|
1394
|
-
// @internal
|
|
1395
|
-
get selectEntityIdChanges$() {
|
|
1396
|
-
return this.entityIdChanges.asObservable();
|
|
1397
|
-
}
|
|
1398
|
-
// @internal
|
|
1399
|
-
get idKey() {
|
|
1400
|
-
return this.config.idKey || this.options.idKey || DEFAULT_ID_KEY;
|
|
1401
|
-
}
|
|
1402
|
-
/**
|
|
1403
|
-
*
|
|
1404
|
-
* Replace current collection with provided collection
|
|
1405
|
-
*
|
|
1406
|
-
* @example
|
|
1407
|
-
*
|
|
1408
|
-
* this.store.set([Entity, Entity])
|
|
1409
|
-
* this.store.set({ids: [], entities: {}})
|
|
1410
|
-
* this.store.set({ 1: {}, 2: {}})
|
|
1411
|
-
*
|
|
1412
|
-
*/
|
|
1413
|
-
set(entities, options = {}) {
|
|
1414
|
-
if (isNil(entities))
|
|
1415
|
-
return;
|
|
1416
|
-
isDev() && setAction('Set Entity');
|
|
1417
|
-
const isNativePreAdd = this.akitaPreAddEntity === EntityStore.prototype.akitaPreAddEntity;
|
|
1418
|
-
this.setHasCache(true, { restartTTL: true });
|
|
1419
|
-
this._setState((state) => {
|
|
1420
|
-
const newState = setEntities({
|
|
1421
|
-
state,
|
|
1422
|
-
entities,
|
|
1423
|
-
idKey: this.idKey,
|
|
1424
|
-
preAddEntity: this.akitaPreAddEntity,
|
|
1425
|
-
isNativePreAdd,
|
|
1426
|
-
});
|
|
1427
|
-
if (isUndefined(options.activeId) === false) {
|
|
1428
|
-
newState.active = options.activeId;
|
|
1429
|
-
}
|
|
1430
|
-
return newState;
|
|
1431
|
-
});
|
|
1432
|
-
if (this.hasInitialUIState()) {
|
|
1433
|
-
this.handleUICreation();
|
|
1434
|
-
}
|
|
1435
|
-
this.entityActions.next({ type: EntityActions.Set, ids: this.ids });
|
|
1436
|
-
}
|
|
1437
|
-
/**
|
|
1438
|
-
* Add entities
|
|
1439
|
-
*
|
|
1440
|
-
* @example
|
|
1441
|
-
*
|
|
1442
|
-
* this.store.add([Entity, Entity])
|
|
1443
|
-
* this.store.add(Entity)
|
|
1444
|
-
* this.store.add(Entity, { prepend: true })
|
|
1445
|
-
*
|
|
1446
|
-
* this.store.add(Entity, { loading: false })
|
|
1447
|
-
*/
|
|
1448
|
-
add(entities, options = { loading: false }) {
|
|
1449
|
-
const collection = coerceArray(entities);
|
|
1450
|
-
if (isEmpty(collection))
|
|
1451
|
-
return;
|
|
1452
|
-
const data = addEntities({
|
|
1453
|
-
state: this._value(),
|
|
1454
|
-
preAddEntity: this.akitaPreAddEntity,
|
|
1455
|
-
entities: collection,
|
|
1456
|
-
idKey: this.idKey,
|
|
1457
|
-
options,
|
|
1458
|
-
});
|
|
1459
|
-
if (data) {
|
|
1460
|
-
isDev() && setAction('Add Entity');
|
|
1461
|
-
data.newState.loading = options.loading;
|
|
1462
|
-
this._setState(() => data.newState);
|
|
1463
|
-
if (this.hasInitialUIState()) {
|
|
1464
|
-
this.handleUICreation(true);
|
|
1465
|
-
}
|
|
1466
|
-
this.entityActions.next({ type: EntityActions.Add, ids: data.newIds });
|
|
1467
|
-
}
|
|
1468
|
-
}
|
|
1469
|
-
update(idsOrFnOrState, newStateOrFn) {
|
|
1470
|
-
if (isUndefined(newStateOrFn)) {
|
|
1471
|
-
super.update(idsOrFnOrState);
|
|
1472
|
-
return;
|
|
1473
|
-
}
|
|
1474
|
-
let ids = [];
|
|
1475
|
-
if (isFunction(idsOrFnOrState)) {
|
|
1476
|
-
// We need to filter according the predicate function
|
|
1477
|
-
ids = this.ids.filter((id) => idsOrFnOrState(this.entities[id]));
|
|
1478
|
-
}
|
|
1479
|
-
else {
|
|
1480
|
-
// If it's nil we want all of them
|
|
1481
|
-
ids = isNil(idsOrFnOrState) ? this.ids : coerceArray(idsOrFnOrState);
|
|
1482
|
-
}
|
|
1483
|
-
if (isEmpty(ids))
|
|
1484
|
-
return;
|
|
1485
|
-
isDev() && setAction('Update Entity', ids);
|
|
1486
|
-
let entityIdChanged;
|
|
1487
|
-
this._setState((state) => updateEntities({
|
|
1488
|
-
idKey: this.idKey,
|
|
1489
|
-
ids,
|
|
1490
|
-
preUpdateEntity: this.akitaPreUpdateEntity,
|
|
1491
|
-
state,
|
|
1492
|
-
newStateOrFn,
|
|
1493
|
-
producerFn: this._producerFn,
|
|
1494
|
-
onEntityIdChanges: (oldId, newId) => {
|
|
1495
|
-
entityIdChanged = { oldId, newId };
|
|
1496
|
-
this.entityIdChanges.next(Object.assign(Object.assign({}, entityIdChanged), { pending: true }));
|
|
1497
|
-
},
|
|
1498
|
-
}));
|
|
1499
|
-
if (entityIdChanged) {
|
|
1500
|
-
this.entityIdChanges.next(Object.assign(Object.assign({}, entityIdChanged), { pending: false }));
|
|
1501
|
-
}
|
|
1502
|
-
this.entityActions.next({ type: EntityActions.Update, ids });
|
|
1503
|
-
}
|
|
1504
|
-
upsert(ids, newState, onCreate, options = {}) {
|
|
1505
|
-
const toArray = coerceArray(ids);
|
|
1506
|
-
const predicate = (isUpdate) => (id) => hasEntity(this.entities, id) === isUpdate;
|
|
1507
|
-
const baseClass = isFunction(onCreate) ? options.baseClass : onCreate ? onCreate.baseClass : undefined;
|
|
1508
|
-
const isClassBased = isFunction(baseClass);
|
|
1509
|
-
const updateIds = toArray.filter(predicate(true));
|
|
1510
|
-
const newEntities = toArray.filter(predicate(false)).map((id) => {
|
|
1511
|
-
const newStateObj = typeof newState === 'function' ? newState({}) : newState;
|
|
1512
|
-
const entity = isFunction(onCreate) ? onCreate(id, newStateObj) : newStateObj;
|
|
1513
|
-
const withId = Object.assign(Object.assign({}, entity), { [this.idKey]: id });
|
|
1514
|
-
if (isClassBased) {
|
|
1515
|
-
return new baseClass(withId);
|
|
1516
|
-
}
|
|
1517
|
-
return withId;
|
|
1518
|
-
});
|
|
1519
|
-
// it can be any of the three types
|
|
1520
|
-
this.update(updateIds, newState);
|
|
1521
|
-
this.add(newEntities);
|
|
1522
|
-
isDev() && logAction('Upsert Entity');
|
|
1523
|
-
}
|
|
1524
|
-
/**
|
|
1525
|
-
*
|
|
1526
|
-
* Upsert entity collection (idKey must be present)
|
|
1527
|
-
*
|
|
1528
|
-
* @example
|
|
1529
|
-
*
|
|
1530
|
-
* store.upsertMany([ { id: 1 }, { id: 2 }]);
|
|
1531
|
-
*
|
|
1532
|
-
* store.upsertMany([ { id: 1 }, { id: 2 }], { loading: true });
|
|
1533
|
-
* store.upsertMany([ { id: 1 }, { id: 2 }], { baseClass: Todo });
|
|
1534
|
-
*
|
|
1535
|
-
*/
|
|
1536
|
-
upsertMany(entities, options = {}) {
|
|
1537
|
-
const addedIds = [];
|
|
1538
|
-
const updatedIds = [];
|
|
1539
|
-
const updatedEntities = {};
|
|
1540
|
-
// Update the state directly to optimize performance
|
|
1541
|
-
for (const entity of entities) {
|
|
1542
|
-
const withPreCheckHook = this.akitaPreCheckEntity(entity);
|
|
1543
|
-
const id = withPreCheckHook[this.idKey];
|
|
1544
|
-
if (hasEntity(this.entities, id)) {
|
|
1545
|
-
const prev = this._value().entities[id];
|
|
1546
|
-
const merged = Object.assign(Object.assign({}, this._value().entities[id]), withPreCheckHook);
|
|
1547
|
-
const next = options.baseClass ? new options.baseClass(merged) : merged;
|
|
1548
|
-
const withHook = this.akitaPreUpdateEntity(prev, next);
|
|
1549
|
-
const nextId = withHook[this.idKey];
|
|
1550
|
-
updatedEntities[nextId] = withHook;
|
|
1551
|
-
updatedIds.push(nextId);
|
|
1552
|
-
}
|
|
1553
|
-
else {
|
|
1554
|
-
const newEntity = options.baseClass ? new options.baseClass(withPreCheckHook) : withPreCheckHook;
|
|
1555
|
-
const withHook = this.akitaPreAddEntity(newEntity);
|
|
1556
|
-
const nextId = withHook[this.idKey];
|
|
1557
|
-
addedIds.push(nextId);
|
|
1558
|
-
updatedEntities[nextId] = withHook;
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
isDev() && logAction('Upsert Many');
|
|
1562
|
-
this._setState((state) => (Object.assign(Object.assign({}, state), { ids: addedIds.length ? [...state.ids, ...addedIds] : state.ids, entities: Object.assign(Object.assign({}, state.entities), updatedEntities), loading: !!options.loading })));
|
|
1563
|
-
updatedIds.length && this.entityActions.next({ type: EntityActions.Update, ids: updatedIds });
|
|
1564
|
-
addedIds.length && this.entityActions.next({ type: EntityActions.Add, ids: addedIds });
|
|
1565
|
-
if (addedIds.length && this.hasUIStore()) {
|
|
1566
|
-
this.handleUICreation(true);
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
/**
|
|
1570
|
-
*
|
|
1571
|
-
* Replace one or more entities (except the id property)
|
|
1572
|
-
*
|
|
1573
|
-
*
|
|
1574
|
-
* @example
|
|
1575
|
-
*
|
|
1576
|
-
* this.store.replace(5, newEntity)
|
|
1577
|
-
* this.store.replace([1,2,3], newEntity)
|
|
1578
|
-
*/
|
|
1579
|
-
replace(ids, newState) {
|
|
1580
|
-
const toArray = coerceArray(ids);
|
|
1581
|
-
if (isEmpty(toArray))
|
|
1582
|
-
return;
|
|
1583
|
-
const replaced = {};
|
|
1584
|
-
for (const id of toArray) {
|
|
1585
|
-
replaced[id] = Object.assign(Object.assign({}, newState), { [this.idKey]: id });
|
|
1586
|
-
}
|
|
1587
|
-
isDev() && setAction('Replace Entity', ids);
|
|
1588
|
-
this._setState((state) => (Object.assign(Object.assign({}, state), { entities: Object.assign(Object.assign({}, state.entities), replaced) })));
|
|
1589
|
-
}
|
|
1590
|
-
/**
|
|
1591
|
-
*
|
|
1592
|
-
* Move entity inside the collection
|
|
1593
|
-
*
|
|
1594
|
-
*
|
|
1595
|
-
* @example
|
|
1596
|
-
*
|
|
1597
|
-
* this.store.move(fromIndex, toIndex)
|
|
1598
|
-
*/
|
|
1599
|
-
move(from, to) {
|
|
1600
|
-
const ids = this.ids.slice();
|
|
1601
|
-
ids.splice(to < 0 ? ids.length + to : to, 0, ids.splice(from, 1)[0]);
|
|
1602
|
-
isDev() && setAction('Move Entity');
|
|
1603
|
-
this._setState((state) => (Object.assign(Object.assign({}, state), {
|
|
1604
|
-
// Change the entities reference so that selectAll emit
|
|
1605
|
-
entities: Object.assign({}, state.entities), ids })));
|
|
1606
|
-
}
|
|
1607
|
-
remove(idsOrFn) {
|
|
1608
|
-
if (isEmpty(this.ids))
|
|
1609
|
-
return;
|
|
1610
|
-
const idPassed = isDefined(idsOrFn);
|
|
1611
|
-
// null means remove all
|
|
1612
|
-
let ids = [];
|
|
1613
|
-
if (isFunction(idsOrFn)) {
|
|
1614
|
-
ids = this.ids.filter((entityId) => idsOrFn(this.entities[entityId]));
|
|
1615
|
-
}
|
|
1616
|
-
else {
|
|
1617
|
-
ids = idPassed ? coerceArray(idsOrFn) : this.ids;
|
|
1618
|
-
}
|
|
1619
|
-
if (isEmpty(ids))
|
|
1620
|
-
return;
|
|
1621
|
-
isDev() && setAction('Remove Entity', ids);
|
|
1622
|
-
this._setState((state) => removeEntities({ state, ids }));
|
|
1623
|
-
if (!idPassed) {
|
|
1624
|
-
this.setHasCache(false);
|
|
1625
|
-
}
|
|
1626
|
-
this.handleUIRemove(ids);
|
|
1627
|
-
this.entityActions.next({ type: EntityActions.Remove, ids });
|
|
1628
|
-
}
|
|
1629
|
-
/**
|
|
1630
|
-
*
|
|
1631
|
-
* Update the active entity
|
|
1632
|
-
*
|
|
1633
|
-
* @example
|
|
1634
|
-
*
|
|
1635
|
-
* this.store.updateActive({ completed: true })
|
|
1636
|
-
* this.store.updateActive(active => {
|
|
1637
|
-
* return {
|
|
1638
|
-
* config: {
|
|
1639
|
-
* ..active.config,
|
|
1640
|
-
* date
|
|
1641
|
-
* }
|
|
1642
|
-
* }
|
|
1643
|
-
* })
|
|
1644
|
-
*/
|
|
1645
|
-
updateActive(newStateOrCallback) {
|
|
1646
|
-
const ids = coerceArray(this.active);
|
|
1647
|
-
isDev() && setAction('Update Active', ids);
|
|
1648
|
-
this.update(ids, newStateOrCallback);
|
|
1649
|
-
}
|
|
1650
|
-
setActive(idOrOptions) {
|
|
1651
|
-
const active = getActiveEntities(idOrOptions, this.ids, this.active);
|
|
1652
|
-
if (active === undefined) {
|
|
1653
|
-
return;
|
|
1654
|
-
}
|
|
1655
|
-
isDev() && setAction('Set Active', active);
|
|
1656
|
-
this._setActive(active);
|
|
1657
|
-
}
|
|
1658
|
-
/**
|
|
1659
|
-
* Add active entities
|
|
1660
|
-
*
|
|
1661
|
-
* @example
|
|
1662
|
-
*
|
|
1663
|
-
* store.addActive(2);
|
|
1664
|
-
* store.addActive([3, 4, 5]);
|
|
1665
|
-
*/
|
|
1666
|
-
addActive(ids) {
|
|
1667
|
-
const toArray = coerceArray(ids);
|
|
1668
|
-
if (isEmpty(toArray))
|
|
1669
|
-
return;
|
|
1670
|
-
const everyExist = toArray.every((id) => this.active.indexOf(id) > -1);
|
|
1671
|
-
if (everyExist)
|
|
1672
|
-
return;
|
|
1673
|
-
isDev() && setAction('Add Active', ids);
|
|
1674
|
-
this._setState((state) => {
|
|
1675
|
-
/** Protect against case that one of the items in the array exist */
|
|
1676
|
-
const uniques = Array.from(new Set([...state.active, ...toArray]));
|
|
1677
|
-
return Object.assign(Object.assign({}, state), { active: uniques });
|
|
1678
|
-
});
|
|
1679
|
-
}
|
|
1680
|
-
/**
|
|
1681
|
-
* Remove active entities
|
|
1682
|
-
*
|
|
1683
|
-
* @example
|
|
1684
|
-
*
|
|
1685
|
-
* store.removeActive(2)
|
|
1686
|
-
* store.removeActive([3, 4, 5])
|
|
1687
|
-
*/
|
|
1688
|
-
removeActive(ids) {
|
|
1689
|
-
const toArray = coerceArray(ids);
|
|
1690
|
-
if (isEmpty(toArray))
|
|
1691
|
-
return;
|
|
1692
|
-
const someExist = toArray.some((id) => this.active.indexOf(id) > -1);
|
|
1693
|
-
if (!someExist)
|
|
1694
|
-
return;
|
|
1695
|
-
isDev() && setAction('Remove Active', ids);
|
|
1696
|
-
this._setState((state) => {
|
|
1697
|
-
return Object.assign(Object.assign({}, state), { active: Array.isArray(state.active) ? state.active.filter((currentId) => toArray.indexOf(currentId) === -1) : null });
|
|
1698
|
-
});
|
|
1699
|
-
}
|
|
1700
|
-
/**
|
|
1701
|
-
* Toggle active entities
|
|
1702
|
-
*
|
|
1703
|
-
* @example
|
|
1704
|
-
*
|
|
1705
|
-
* store.toggle(2)
|
|
1706
|
-
* store.toggle([3, 4, 5])
|
|
1707
|
-
*/
|
|
1708
|
-
toggleActive(ids) {
|
|
1709
|
-
const toArray = coerceArray(ids);
|
|
1710
|
-
const filterExists = (remove) => (id) => this.active.includes(id) === remove;
|
|
1711
|
-
const remove = toArray.filter(filterExists(true));
|
|
1712
|
-
const add = toArray.filter(filterExists(false));
|
|
1713
|
-
this.removeActive(remove);
|
|
1714
|
-
this.addActive(add);
|
|
1715
|
-
isDev() && logAction('Toggle Active');
|
|
1716
|
-
}
|
|
1717
|
-
/**
|
|
1718
|
-
*
|
|
1719
|
-
* Create sub UI store for managing Entity's UI state
|
|
1720
|
-
*
|
|
1721
|
-
* @example
|
|
1722
|
-
*
|
|
1723
|
-
* export type ProductUI = {
|
|
1724
|
-
* isLoading: boolean;
|
|
1725
|
-
* isOpen: boolean
|
|
1726
|
-
* }
|
|
1727
|
-
*
|
|
1728
|
-
* interface ProductsUIState extends EntityState<ProductUI> {}
|
|
1729
|
-
*
|
|
1730
|
-
* export class ProductsStore EntityStore<ProductsState, Product> {
|
|
1731
|
-
* ui: EntityUIStore<ProductsUIState, ProductUI>;
|
|
1732
|
-
*
|
|
1733
|
-
* constructor() {
|
|
1734
|
-
* super();
|
|
1735
|
-
* this.createUIStore();
|
|
1736
|
-
* }
|
|
1737
|
-
*
|
|
1738
|
-
* }
|
|
1739
|
-
*/
|
|
1740
|
-
createUIStore(initialState = {}, storeConfig = {}) {
|
|
1741
|
-
const defaults = { name: `UI/${this.storeName}`, idKey: this.idKey };
|
|
1742
|
-
this.ui = new EntityUIStore(initialState, Object.assign(Object.assign({}, defaults), storeConfig));
|
|
1743
|
-
return this.ui;
|
|
1744
|
-
}
|
|
1745
|
-
// @internal
|
|
1746
|
-
destroy() {
|
|
1747
|
-
super.destroy();
|
|
1748
|
-
if (this.ui instanceof EntityStore) {
|
|
1749
|
-
this.ui.destroy();
|
|
1750
|
-
}
|
|
1751
|
-
this.entityActions.complete();
|
|
1752
|
-
}
|
|
1753
|
-
// @internal
|
|
1754
|
-
akitaPreUpdateEntity(_, nextEntity) {
|
|
1755
|
-
return nextEntity;
|
|
1756
|
-
}
|
|
1757
|
-
// @internal
|
|
1758
|
-
akitaPreAddEntity(newEntity) {
|
|
1759
|
-
return newEntity;
|
|
1760
|
-
}
|
|
1761
|
-
// @internal
|
|
1762
|
-
akitaPreCheckEntity(newEntity) {
|
|
1763
|
-
return newEntity;
|
|
1764
|
-
}
|
|
1765
|
-
get ids() {
|
|
1766
|
-
return this._value().ids;
|
|
1767
|
-
}
|
|
1768
|
-
get entities() {
|
|
1769
|
-
return this._value().entities;
|
|
1770
|
-
}
|
|
1771
|
-
get active() {
|
|
1772
|
-
return this._value().active;
|
|
1773
|
-
}
|
|
1774
|
-
_setActive(ids) {
|
|
1775
|
-
this._setState((state) => {
|
|
1776
|
-
return Object.assign(Object.assign({}, state), { active: ids });
|
|
1777
|
-
});
|
|
1778
|
-
}
|
|
1779
|
-
handleUICreation(add = false) {
|
|
1780
|
-
const ids = this.ids;
|
|
1781
|
-
const isFunc = isFunction(this.ui._akitaCreateEntityFn);
|
|
1782
|
-
let uiEntities;
|
|
1783
|
-
const createFn = (id) => {
|
|
1784
|
-
const current = this.entities[id];
|
|
1785
|
-
const ui = isFunc ? this.ui._akitaCreateEntityFn(current) : this.ui._akitaCreateEntityFn;
|
|
1786
|
-
return Object.assign({ [this.idKey]: current[this.idKey] }, ui);
|
|
1787
|
-
};
|
|
1788
|
-
if (add) {
|
|
1789
|
-
uiEntities = this.ids.filter((id) => isUndefined(this.ui.entities[id])).map(createFn);
|
|
1790
|
-
}
|
|
1791
|
-
else {
|
|
1792
|
-
uiEntities = ids.map(createFn);
|
|
1793
|
-
}
|
|
1794
|
-
add ? this.ui.add(uiEntities) : this.ui.set(uiEntities);
|
|
1795
|
-
}
|
|
1796
|
-
hasInitialUIState() {
|
|
1797
|
-
return this.hasUIStore() && isUndefined(this.ui._akitaCreateEntityFn) === false;
|
|
1798
|
-
}
|
|
1799
|
-
handleUIRemove(ids) {
|
|
1800
|
-
if (this.hasUIStore()) {
|
|
1801
|
-
this.ui.remove(ids);
|
|
1802
|
-
}
|
|
1803
|
-
}
|
|
1804
|
-
hasUIStore() {
|
|
1805
|
-
return this.ui instanceof EntityUIStore;
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1808
|
-
__decorate([
|
|
1809
|
-
transaction(),
|
|
1810
|
-
__metadata("design:type", Function),
|
|
1811
|
-
__metadata("design:paramtypes", [Object, Object, Object, Object]),
|
|
1812
|
-
__metadata("design:returntype", void 0)
|
|
1813
|
-
], EntityStore.prototype, "upsert", null);
|
|
1814
|
-
__decorate([
|
|
1815
|
-
transaction(),
|
|
1816
|
-
__metadata("design:type", Function),
|
|
1817
|
-
__metadata("design:paramtypes", [typeof (_b = typeof T !== "undefined" && T) === "function" ? _b : Object]),
|
|
1818
|
-
__metadata("design:returntype", void 0)
|
|
1819
|
-
], EntityStore.prototype, "toggleActive", null);
|
|
1820
|
-
// @internal
|
|
1821
|
-
class EntityUIStore extends EntityStore {
|
|
1822
|
-
constructor(initialState = {}, storeConfig = {}) {
|
|
1823
|
-
super(initialState, storeConfig);
|
|
1824
|
-
}
|
|
1825
|
-
/**
|
|
1826
|
-
*
|
|
1827
|
-
* Set the initial UI entity state. This function will determine the entity's
|
|
1828
|
-
* initial state when we call `set()` or `add()`.
|
|
1829
|
-
*
|
|
1830
|
-
* @example
|
|
1831
|
-
*
|
|
1832
|
-
* constructor() {
|
|
1833
|
-
* super();
|
|
1834
|
-
* this.createUIStore().setInitialEntityState(entity => ({ isLoading: false, isOpen: true }));
|
|
1835
|
-
* this.createUIStore().setInitialEntityState({ isLoading: false, isOpen: true });
|
|
1836
|
-
* }
|
|
1837
|
-
*
|
|
1838
|
-
*/
|
|
1839
|
-
setInitialEntityState(createFn) {
|
|
1840
|
-
this._akitaCreateEntityFn = createFn;
|
|
1841
|
-
}
|
|
1842
|
-
}
|
|
1843
|
-
/**
|
|
1844
|
-
* @example
|
|
1845
|
-
*
|
|
1846
|
-
* query.selectEntity(2).pipe(filterNilValue())
|
|
1847
|
-
*/
|
|
1848
|
-
function filterNilValue() {
|
|
1849
|
-
return filter((value) => value !== null && value !== undefined);
|
|
1850
|
-
}
|
|
1851
|
-
|
|
1852
|
-
const queryConfigKey = 'akitaQueryConfig';
|
|
1853
|
-
|
|
1854
|
-
// @internal
|
|
1855
|
-
function isString(value) {
|
|
1856
|
-
return typeof value === 'string';
|
|
1857
|
-
}
|
|
1858
|
-
|
|
1859
|
-
function compareKeys(keysOrFuncs) {
|
|
1860
|
-
return function (prevState, currState) {
|
|
1861
|
-
const isFns = isFunction(keysOrFuncs[0]);
|
|
1862
|
-
// Return when they are NOT changed
|
|
1863
|
-
return keysOrFuncs.some(keyOrFunc => {
|
|
1864
|
-
if (isFns) {
|
|
1865
|
-
return keyOrFunc(prevState) !== keyOrFunc(currState);
|
|
1866
|
-
}
|
|
1867
|
-
return prevState[keyOrFunc] !== currState[keyOrFunc];
|
|
1868
|
-
}) === false;
|
|
1869
|
-
};
|
|
1870
|
-
}
|
|
1871
|
-
|
|
1872
|
-
class Query {
|
|
1873
|
-
constructor(store) {
|
|
1874
|
-
this.store = store;
|
|
1875
|
-
this.__store__ = store;
|
|
1876
|
-
if (isDev()) {
|
|
1877
|
-
// @internal
|
|
1878
|
-
__queries__[store.storeName] = this;
|
|
1879
|
-
}
|
|
1880
|
-
}
|
|
1881
|
-
select(project) {
|
|
1882
|
-
let mapFn;
|
|
1883
|
-
if (isFunction(project)) {
|
|
1884
|
-
mapFn = project;
|
|
1885
|
-
}
|
|
1886
|
-
else if (isString(project)) {
|
|
1887
|
-
mapFn = state => state[project];
|
|
1888
|
-
}
|
|
1889
|
-
else if (Array.isArray(project)) {
|
|
1890
|
-
return this.store
|
|
1891
|
-
._select(state => state)
|
|
1892
|
-
.pipe(distinctUntilChanged(compareKeys(project)), map(state => {
|
|
1893
|
-
if (isFunction(project[0])) {
|
|
1894
|
-
return project.map(func => func(state));
|
|
1895
|
-
}
|
|
1896
|
-
return project.reduce((acc, k) => {
|
|
1897
|
-
acc[k] = state[k];
|
|
1898
|
-
return acc;
|
|
1899
|
-
}, {});
|
|
1900
|
-
}));
|
|
1901
|
-
}
|
|
1902
|
-
else {
|
|
1903
|
-
mapFn = state => state;
|
|
1904
|
-
}
|
|
1905
|
-
return this.store._select(mapFn);
|
|
1906
|
-
}
|
|
1907
|
-
/**
|
|
1908
|
-
* Select the loading state
|
|
1909
|
-
*
|
|
1910
|
-
* @example
|
|
1911
|
-
*
|
|
1912
|
-
* this.query.selectLoading().subscribe(isLoading => {})
|
|
1913
|
-
*/
|
|
1914
|
-
selectLoading() {
|
|
1915
|
-
return this.select(state => state.loading);
|
|
1916
|
-
}
|
|
1917
|
-
/**
|
|
1918
|
-
* Select the error state
|
|
1919
|
-
*
|
|
1920
|
-
* @example
|
|
1921
|
-
*
|
|
1922
|
-
* this.query.selectError().subscribe(error => {})
|
|
1923
|
-
*/
|
|
1924
|
-
selectError() {
|
|
1925
|
-
return this.select(state => state.error);
|
|
1926
|
-
}
|
|
1927
|
-
/**
|
|
1928
|
-
* Get the store's value
|
|
1929
|
-
*
|
|
1930
|
-
* @example
|
|
1931
|
-
*
|
|
1932
|
-
* this.query.getValue()
|
|
1933
|
-
*
|
|
1934
|
-
*/
|
|
1935
|
-
getValue() {
|
|
1936
|
-
return this.store._value();
|
|
1937
|
-
}
|
|
1938
|
-
/**
|
|
1939
|
-
* Select the cache state
|
|
1940
|
-
*
|
|
1941
|
-
* @example
|
|
1942
|
-
*
|
|
1943
|
-
* this.query.selectHasCache().pipe(
|
|
1944
|
-
* switchMap(hasCache => {
|
|
1945
|
-
* return hasCache ? of() : http().pipe(res => store.set(res))
|
|
1946
|
-
* })
|
|
1947
|
-
* )
|
|
1948
|
-
*/
|
|
1949
|
-
selectHasCache() {
|
|
1950
|
-
return this.store._cache().asObservable();
|
|
1951
|
-
}
|
|
1952
|
-
/**
|
|
1953
|
-
* Whether we've cached data
|
|
1954
|
-
*
|
|
1955
|
-
* @example
|
|
1956
|
-
*
|
|
1957
|
-
* this.query.getHasCache()
|
|
1958
|
-
*
|
|
1959
|
-
*/
|
|
1960
|
-
getHasCache() {
|
|
1961
|
-
return this.store._cache().value;
|
|
1962
|
-
}
|
|
1963
|
-
// @internal
|
|
1964
|
-
get config() {
|
|
1965
|
-
return this.constructor[queryConfigKey];
|
|
1966
|
-
}
|
|
1967
|
-
}
|
|
1968
|
-
|
|
1969
|
-
/**
|
|
1970
|
-
* @internal
|
|
1971
|
-
*
|
|
1972
|
-
* @example
|
|
1973
|
-
*
|
|
1974
|
-
* getValue(state, 'todos.ui')
|
|
1975
|
-
*
|
|
1976
|
-
*/
|
|
1977
|
-
function getValue(obj, prop) {
|
|
1978
|
-
/** return the whole state */
|
|
1979
|
-
if (prop.split('.').length === 1) {
|
|
1980
|
-
return obj;
|
|
1981
|
-
}
|
|
1982
|
-
const removeStoreName = prop
|
|
1983
|
-
.split('.')
|
|
1984
|
-
.slice(1)
|
|
1985
|
-
.join('.');
|
|
1986
|
-
return removeStoreName.split('.').reduce((acc, part) => acc && acc[part], obj);
|
|
1987
|
-
}
|
|
1988
|
-
|
|
1989
|
-
/**
|
|
1990
|
-
* @internal
|
|
1991
|
-
*
|
|
1992
|
-
* @example
|
|
1993
|
-
* setValue(state, 'todos.ui', { filter: {} })
|
|
1994
|
-
*/
|
|
1995
|
-
function setValue(obj, prop, val, replace = false) {
|
|
1996
|
-
const split = prop.split('.');
|
|
1997
|
-
if (split.length === 1) {
|
|
1998
|
-
return Object.assign(Object.assign({}, obj), val);
|
|
1999
|
-
}
|
|
2000
|
-
obj = Object.assign({}, obj);
|
|
2001
|
-
const lastIndex = split.length - 2;
|
|
2002
|
-
const removeStoreName = prop.split('.').slice(1);
|
|
2003
|
-
removeStoreName.reduce((acc, part, index) => {
|
|
2004
|
-
if (index !== lastIndex) {
|
|
2005
|
-
acc[part] = Object.assign({}, acc[part]);
|
|
2006
|
-
return acc && acc[part];
|
|
2007
|
-
}
|
|
2008
|
-
acc[part] = replace || Array.isArray(acc[part]) || !isObject(acc[part]) ? val : Object.assign(Object.assign({}, acc[part]), val);
|
|
2009
|
-
return acc && acc[part];
|
|
2010
|
-
}, obj);
|
|
2011
|
-
return obj;
|
|
2012
|
-
}
|
|
2013
|
-
|
|
2014
|
-
let skipStorageUpdate = false;
|
|
2015
|
-
const _persistStateInit = new ReplaySubject(1);
|
|
2016
|
-
function getSkipStorageUpdate() {
|
|
2017
|
-
return skipStorageUpdate;
|
|
2018
|
-
}
|
|
2019
|
-
function isPromise(v) {
|
|
2020
|
-
return v && isFunction(v.then);
|
|
2021
|
-
}
|
|
2022
|
-
function observify(asyncOrValue) {
|
|
2023
|
-
if (isPromise(asyncOrValue) || isObservable(asyncOrValue)) {
|
|
2024
|
-
return from(asyncOrValue);
|
|
2025
|
-
}
|
|
2026
|
-
return of(asyncOrValue);
|
|
2027
|
-
}
|
|
2028
|
-
function persistState(params) {
|
|
2029
|
-
const defaults = {
|
|
2030
|
-
key: 'AkitaStores',
|
|
2031
|
-
enableInNonBrowser: false,
|
|
2032
|
-
storage: !hasLocalStorage() ? params.storage : localStorage,
|
|
2033
|
-
deserialize: JSON.parse,
|
|
2034
|
-
serialize: JSON.stringify,
|
|
2035
|
-
include: [],
|
|
2036
|
-
select: [],
|
|
2037
|
-
persistOnDestroy: false,
|
|
2038
|
-
preStorageUpdate: function (storeName, state) {
|
|
2039
|
-
return state;
|
|
2040
|
-
},
|
|
2041
|
-
preStoreUpdate: function (storeName, state) {
|
|
2042
|
-
return state;
|
|
2043
|
-
},
|
|
2044
|
-
skipStorageUpdate: getSkipStorageUpdate,
|
|
2045
|
-
preStorageUpdateOperator: () => (source) => source,
|
|
2046
|
-
};
|
|
2047
|
-
const { storage, enableInNonBrowser, deserialize, serialize, include, select, key, preStorageUpdate, persistOnDestroy, preStorageUpdateOperator, preStoreUpdate, skipStorageUpdate } = Object.assign({}, defaults, params);
|
|
2048
|
-
if ((isNotBrowser && !enableInNonBrowser) || !storage)
|
|
2049
|
-
return;
|
|
2050
|
-
const hasInclude = include.length > 0;
|
|
2051
|
-
const hasSelect = select.length > 0;
|
|
2052
|
-
let includeStores;
|
|
2053
|
-
let selectStores;
|
|
2054
|
-
if (hasInclude) {
|
|
2055
|
-
includeStores = include.reduce((acc, path) => {
|
|
2056
|
-
if (isFunction(path)) {
|
|
2057
|
-
acc.fns.push(path);
|
|
2058
|
-
}
|
|
2059
|
-
else {
|
|
2060
|
-
const storeName = path.split('.')[0];
|
|
2061
|
-
acc[storeName] = path;
|
|
2062
|
-
}
|
|
2063
|
-
return acc;
|
|
2064
|
-
}, { fns: [] });
|
|
2065
|
-
}
|
|
2066
|
-
if (hasSelect) {
|
|
2067
|
-
selectStores = select.reduce((acc, selectFn) => {
|
|
2068
|
-
acc[selectFn.storeName] = selectFn;
|
|
2069
|
-
return acc;
|
|
2070
|
-
}, {});
|
|
2071
|
-
}
|
|
2072
|
-
let stores = {};
|
|
2073
|
-
let acc = {};
|
|
2074
|
-
let subscriptions = [];
|
|
2075
|
-
const buffer = [];
|
|
2076
|
-
function _save(v) {
|
|
2077
|
-
observify(v).subscribe(() => {
|
|
2078
|
-
const next = buffer.shift();
|
|
2079
|
-
next && _save(next);
|
|
2080
|
-
});
|
|
2081
|
-
}
|
|
2082
|
-
// when we use the local/session storage we perform the serialize, otherwise we let the passed storage implementation to do it
|
|
2083
|
-
const isLocalStorage = (hasLocalStorage() && storage === localStorage) || (hasSessionStorage() && storage === sessionStorage);
|
|
2084
|
-
observify(storage.getItem(key)).subscribe((value) => {
|
|
2085
|
-
let storageState = isObject(value) ? value : deserialize(value || '{}');
|
|
2086
|
-
function save(storeCache) {
|
|
2087
|
-
storageState['$cache'] = Object.assign(Object.assign({}, (storageState['$cache'] || {})), storeCache);
|
|
2088
|
-
storageState = Object.assign({}, storageState, acc);
|
|
2089
|
-
buffer.push(storage.setItem(key, isLocalStorage ? serialize(storageState) : storageState));
|
|
2090
|
-
_save(buffer.shift());
|
|
2091
|
-
}
|
|
2092
|
-
function subscribe(storeName, path) {
|
|
2093
|
-
stores[storeName] = __stores__[storeName]
|
|
2094
|
-
._select((state) => getValue(state, path))
|
|
2095
|
-
.pipe(skip(1), map((store) => {
|
|
2096
|
-
if (hasSelect && selectStores[storeName]) {
|
|
2097
|
-
return selectStores[storeName](store);
|
|
2098
|
-
}
|
|
2099
|
-
return store;
|
|
2100
|
-
}), filter(() => skipStorageUpdate() === false), preStorageUpdateOperator())
|
|
2101
|
-
.subscribe((data) => {
|
|
2102
|
-
acc[storeName] = preStorageUpdate(storeName, data);
|
|
2103
|
-
Promise.resolve().then(() => save({ [storeName]: __stores__[storeName]._cache().getValue() }));
|
|
2104
|
-
});
|
|
2105
|
-
}
|
|
2106
|
-
function setInitial(storeName, store, path) {
|
|
2107
|
-
if (storeName in storageState) {
|
|
2108
|
-
setAction('@PersistState');
|
|
2109
|
-
store._setState((state) => {
|
|
2110
|
-
return setValue(state, path, preStoreUpdate(storeName, storageState[storeName], state));
|
|
2111
|
-
});
|
|
2112
|
-
const hasCache = storageState['$cache'] ? storageState['$cache'][storeName] : false;
|
|
2113
|
-
__stores__[storeName].setHasCache(hasCache, { restartTTL: true });
|
|
2114
|
-
}
|
|
2115
|
-
}
|
|
2116
|
-
subscriptions.push($$deleteStore.subscribe((storeName) => {
|
|
2117
|
-
if (stores[storeName]) {
|
|
2118
|
-
if (persistOnDestroy === false) {
|
|
2119
|
-
save({ [storeName]: false });
|
|
2120
|
-
}
|
|
2121
|
-
stores[storeName].unsubscribe();
|
|
2122
|
-
delete stores[storeName];
|
|
2123
|
-
}
|
|
2124
|
-
}));
|
|
2125
|
-
subscriptions.push($$addStore.subscribe((storeName) => {
|
|
2126
|
-
if (storeName === 'router') {
|
|
2127
|
-
return;
|
|
2128
|
-
}
|
|
2129
|
-
const store = __stores__[storeName];
|
|
2130
|
-
if (hasInclude) {
|
|
2131
|
-
let path = includeStores[storeName];
|
|
2132
|
-
if (!path) {
|
|
2133
|
-
const passPredicate = includeStores.fns.some((fn) => fn(storeName));
|
|
2134
|
-
if (passPredicate) {
|
|
2135
|
-
path = storeName;
|
|
2136
|
-
}
|
|
2137
|
-
else {
|
|
2138
|
-
return;
|
|
2139
|
-
}
|
|
2140
|
-
}
|
|
2141
|
-
setInitial(storeName, store, path);
|
|
2142
|
-
subscribe(storeName, path);
|
|
2143
|
-
}
|
|
2144
|
-
else {
|
|
2145
|
-
setInitial(storeName, store, storeName);
|
|
2146
|
-
subscribe(storeName, storeName);
|
|
2147
|
-
}
|
|
2148
|
-
}));
|
|
2149
|
-
_persistStateInit.next();
|
|
2150
|
-
});
|
|
2151
|
-
return {
|
|
2152
|
-
destroy() {
|
|
2153
|
-
subscriptions.forEach((s) => s.unsubscribe());
|
|
2154
|
-
for (let i = 0, keys = Object.keys(stores); i < keys.length; i++) {
|
|
2155
|
-
const storeName = keys[i];
|
|
2156
|
-
stores[storeName].unsubscribe();
|
|
2157
|
-
}
|
|
2158
|
-
stores = {};
|
|
2159
|
-
},
|
|
2160
|
-
clear() {
|
|
2161
|
-
storage.clear();
|
|
2162
|
-
},
|
|
2163
|
-
clearStore(storeName) {
|
|
2164
|
-
if (isNil(storeName)) {
|
|
2165
|
-
const value = observify(storage.setItem(key, '{}'));
|
|
2166
|
-
value.subscribe();
|
|
2167
|
-
return;
|
|
2168
|
-
}
|
|
2169
|
-
const value = storage.getItem(key);
|
|
2170
|
-
observify(value).subscribe((v) => {
|
|
2171
|
-
const storageState = deserialize(v || '{}');
|
|
2172
|
-
if (storageState[storeName]) {
|
|
2173
|
-
delete storageState[storeName];
|
|
2174
|
-
const value = observify(storage.setItem(key, serialize(storageState)));
|
|
2175
|
-
value.subscribe();
|
|
2176
|
-
}
|
|
2177
|
-
});
|
|
2178
|
-
},
|
|
2179
|
-
};
|
|
2180
|
-
}
|
|
2181
|
-
|
|
2182
|
-
class AkitaPlugin {
|
|
2183
|
-
constructor(query, config) {
|
|
2184
|
-
this.query = query;
|
|
2185
|
-
if (config && config.resetFn) {
|
|
2186
|
-
if (getAkitaConfig().resettable) {
|
|
2187
|
-
this.onReset(config.resetFn);
|
|
2188
|
-
}
|
|
2189
|
-
}
|
|
2190
|
-
}
|
|
2191
|
-
/** This method is responsible for getting access to the query. */
|
|
2192
|
-
getQuery() {
|
|
2193
|
-
return this.query;
|
|
2194
|
-
}
|
|
2195
|
-
/** This method is responsible for getting access to the store. */
|
|
2196
|
-
getStore() {
|
|
2197
|
-
return this.getQuery().__store__;
|
|
2198
|
-
}
|
|
2199
|
-
/** This method is responsible tells whether the plugin is entityBased or not. */
|
|
2200
|
-
isEntityBased(entityId) {
|
|
2201
|
-
return toBoolean(entityId);
|
|
2202
|
-
}
|
|
2203
|
-
/** This method is responsible for selecting the source; it can be the whole store or one entity. */
|
|
2204
|
-
selectSource(entityId, property) {
|
|
2205
|
-
if (this.isEntityBased(entityId)) {
|
|
2206
|
-
return this.getQuery().selectEntity(entityId).pipe(filterNilValue());
|
|
2207
|
-
}
|
|
2208
|
-
if (property) {
|
|
2209
|
-
return this.getQuery().select((state) => getValue(state, this.withStoreName(property)));
|
|
2210
|
-
}
|
|
2211
|
-
return this.getQuery().select();
|
|
2212
|
-
}
|
|
2213
|
-
getSource(entityId, property) {
|
|
2214
|
-
if (this.isEntityBased(entityId)) {
|
|
2215
|
-
return this.getQuery().getEntity(entityId);
|
|
2216
|
-
}
|
|
2217
|
-
const state = this.getQuery().getValue();
|
|
2218
|
-
if (property) {
|
|
2219
|
-
return getValue(state, this.withStoreName(property));
|
|
2220
|
-
}
|
|
2221
|
-
return state;
|
|
2222
|
-
}
|
|
2223
|
-
withStoreName(prop) {
|
|
2224
|
-
return `${this.storeName}.${prop}`;
|
|
2225
|
-
}
|
|
2226
|
-
get storeName() {
|
|
2227
|
-
return this.getStore().storeName;
|
|
2228
|
-
}
|
|
2229
|
-
/** This method is responsible for updating the store or one entity; it can be the whole store or one entity. */
|
|
2230
|
-
updateStore(newState, entityId, property, replace = false) {
|
|
2231
|
-
if (this.isEntityBased(entityId)) {
|
|
2232
|
-
const store = this.getStore();
|
|
2233
|
-
replace ? store.replace(entityId, newState) : store.update(entityId, newState);
|
|
2234
|
-
}
|
|
2235
|
-
else {
|
|
2236
|
-
if (property) {
|
|
2237
|
-
this.getStore()._setState((state) => {
|
|
2238
|
-
return setValue(state, this.withStoreName(property), newState, true);
|
|
2239
|
-
});
|
|
2240
|
-
return;
|
|
2241
|
-
}
|
|
2242
|
-
const nextState = replace ? newState : (state) => (Object.assign(Object.assign({}, state), newState));
|
|
2243
|
-
this.getStore()._setState(nextState);
|
|
2244
|
-
}
|
|
2245
|
-
}
|
|
2246
|
-
/**
|
|
2247
|
-
* Function to invoke upon reset
|
|
2248
|
-
*/
|
|
2249
|
-
onReset(fn) {
|
|
2250
|
-
const original = this.getStore().reset;
|
|
2251
|
-
this.getStore().reset = (...params) => {
|
|
2252
|
-
/** It should run after the plugin destroy method */
|
|
2253
|
-
setTimeout(() => {
|
|
2254
|
-
original.apply(this.getStore(), params);
|
|
2255
|
-
fn();
|
|
2256
|
-
});
|
|
2257
|
-
};
|
|
2258
|
-
}
|
|
2259
|
-
}
|
|
2260
|
-
|
|
2261
|
-
const paginatorDefaults = {
|
|
2262
|
-
pagesControls: false,
|
|
2263
|
-
range: false,
|
|
2264
|
-
startWith: 1,
|
|
2265
|
-
cacheTimeout: undefined,
|
|
2266
|
-
clearStoreWithCache: true,
|
|
2267
|
-
};
|
|
2268
|
-
class PaginatorPlugin extends AkitaPlugin {
|
|
2269
|
-
constructor(query, config = {}) {
|
|
2270
|
-
super(query, {
|
|
2271
|
-
resetFn: () => {
|
|
2272
|
-
this.initial = false;
|
|
2273
|
-
this.destroy({ clearCache: true, currentPage: 1 });
|
|
2274
|
-
},
|
|
2275
|
-
});
|
|
2276
|
-
this.query = query;
|
|
2277
|
-
this.config = config;
|
|
2278
|
-
/** Save current filters, sorting, etc. in cache */
|
|
2279
|
-
this.metadata = new Map();
|
|
2280
|
-
this.pages = new Map();
|
|
2281
|
-
this.pagination = {
|
|
2282
|
-
currentPage: 1,
|
|
2283
|
-
perPage: 0,
|
|
2284
|
-
total: 0,
|
|
2285
|
-
lastPage: 0,
|
|
2286
|
-
data: [],
|
|
2287
|
-
};
|
|
2288
|
-
/**
|
|
2289
|
-
* When the user navigates to a different page and return
|
|
2290
|
-
* we don't want to call `clearCache` on first time.
|
|
2291
|
-
*/
|
|
2292
|
-
this.initial = true;
|
|
2293
|
-
/**
|
|
2294
|
-
* Proxy to the query loading
|
|
2295
|
-
*/
|
|
2296
|
-
this.isLoading$ = this.query.selectLoading().pipe(delay(0));
|
|
2297
|
-
this.config = Object.assign(Object.assign({}, paginatorDefaults), config);
|
|
2298
|
-
const { startWith, cacheTimeout } = this.config;
|
|
2299
|
-
this.page = new BehaviorSubject(startWith);
|
|
2300
|
-
if (isObservable(cacheTimeout)) {
|
|
2301
|
-
this.clearCacheSubscription = cacheTimeout.subscribe(() => this.clearCache());
|
|
2302
|
-
}
|
|
2303
|
-
}
|
|
2304
|
-
/**
|
|
2305
|
-
* Listen to page changes
|
|
2306
|
-
*/
|
|
2307
|
-
get pageChanges() {
|
|
2308
|
-
return this.page.asObservable();
|
|
2309
|
-
}
|
|
2310
|
-
/**
|
|
2311
|
-
* Get the current page number
|
|
2312
|
-
*/
|
|
2313
|
-
get currentPage() {
|
|
2314
|
-
return this.pagination.currentPage;
|
|
2315
|
-
}
|
|
2316
|
-
/**
|
|
2317
|
-
* Check if current page is the first one
|
|
2318
|
-
*/
|
|
2319
|
-
get isFirst() {
|
|
2320
|
-
return this.currentPage === 1;
|
|
2321
|
-
}
|
|
2322
|
-
/**
|
|
2323
|
-
* Check if current page is the last one
|
|
2324
|
-
*/
|
|
2325
|
-
get isLast() {
|
|
2326
|
-
return this.currentPage === this.pagination.lastPage;
|
|
2327
|
-
}
|
|
2328
|
-
/**
|
|
2329
|
-
* Whether to generate an array of pages for *ngFor
|
|
2330
|
-
* [1, 2, 3, 4]
|
|
2331
|
-
*/
|
|
2332
|
-
withControls() {
|
|
2333
|
-
this.config.pagesControls = true;
|
|
2334
|
-
return this;
|
|
2335
|
-
}
|
|
2336
|
-
/**
|
|
2337
|
-
* Whether to generate the `from` and `to` keys
|
|
2338
|
-
* [1, 2, 3, 4]
|
|
2339
|
-
*/
|
|
2340
|
-
withRange() {
|
|
2341
|
-
this.config.range = true;
|
|
2342
|
-
return this;
|
|
2343
|
-
}
|
|
2344
|
-
/**
|
|
2345
|
-
* Set the loading state
|
|
2346
|
-
*/
|
|
2347
|
-
setLoading(value = true) {
|
|
2348
|
-
this.getStore().setLoading(value);
|
|
2349
|
-
}
|
|
2350
|
-
/**
|
|
2351
|
-
* Update the pagination object and add the page
|
|
2352
|
-
*/
|
|
2353
|
-
update(response) {
|
|
2354
|
-
this.pagination = response;
|
|
2355
|
-
this.addPage(response.data);
|
|
2356
|
-
}
|
|
2357
|
-
/**
|
|
2358
|
-
*
|
|
2359
|
-
* Set the ids and add the page to store
|
|
2360
|
-
*/
|
|
2361
|
-
addPage(data) {
|
|
2362
|
-
this.pages.set(this.currentPage, { ids: data.map((entity) => entity[this.getStore().idKey]) });
|
|
2363
|
-
this.getStore().upsertMany(data);
|
|
2364
|
-
}
|
|
2365
|
-
/**
|
|
2366
|
-
* Clear the cache.
|
|
2367
|
-
*/
|
|
2368
|
-
clearCache(options = {}) {
|
|
2369
|
-
if (!this.initial) {
|
|
2370
|
-
logAction('@Pagination - Clear Cache');
|
|
2371
|
-
if (options.clearStore !== false && (this.config.clearStoreWithCache || options.clearStore)) {
|
|
2372
|
-
this.getStore().remove();
|
|
2373
|
-
}
|
|
2374
|
-
this.pages = new Map();
|
|
2375
|
-
this.metadata = new Map();
|
|
2376
|
-
}
|
|
2377
|
-
this.initial = false;
|
|
2378
|
-
}
|
|
2379
|
-
clearPage(page) {
|
|
2380
|
-
this.pages.delete(page);
|
|
2381
|
-
}
|
|
2382
|
-
/**
|
|
2383
|
-
* Clear the cache timeout and optionally the pages
|
|
2384
|
-
*/
|
|
2385
|
-
destroy({ clearCache, currentPage } = {}) {
|
|
2386
|
-
if (this.clearCacheSubscription) {
|
|
2387
|
-
this.clearCacheSubscription.unsubscribe();
|
|
2388
|
-
}
|
|
2389
|
-
if (clearCache) {
|
|
2390
|
-
this.clearCache();
|
|
2391
|
-
}
|
|
2392
|
-
if (!isUndefined(currentPage)) {
|
|
2393
|
-
this.setPage(currentPage);
|
|
2394
|
-
}
|
|
2395
|
-
this.initial = true;
|
|
2396
|
-
}
|
|
2397
|
-
/**
|
|
2398
|
-
* Whether the provided page is active
|
|
2399
|
-
*/
|
|
2400
|
-
isPageActive(page) {
|
|
2401
|
-
return this.currentPage === page;
|
|
2402
|
-
}
|
|
2403
|
-
/**
|
|
2404
|
-
* Set the current page
|
|
2405
|
-
*/
|
|
2406
|
-
setPage(page) {
|
|
2407
|
-
if (page !== this.currentPage || !this.hasPage(page)) {
|
|
2408
|
-
this.page.next((this.pagination.currentPage = page));
|
|
2409
|
-
}
|
|
2410
|
-
}
|
|
2411
|
-
/**
|
|
2412
|
-
* Increment current page
|
|
2413
|
-
*/
|
|
2414
|
-
nextPage() {
|
|
2415
|
-
if (this.currentPage !== this.pagination.lastPage) {
|
|
2416
|
-
this.setPage(this.pagination.currentPage + 1);
|
|
2417
|
-
}
|
|
2418
|
-
}
|
|
2419
|
-
/**
|
|
2420
|
-
* Decrement current page
|
|
2421
|
-
*/
|
|
2422
|
-
prevPage() {
|
|
2423
|
-
if (this.pagination.currentPage > 1) {
|
|
2424
|
-
this.setPage(this.pagination.currentPage - 1);
|
|
2425
|
-
}
|
|
2426
|
-
}
|
|
2427
|
-
/**
|
|
2428
|
-
* Set current page to last
|
|
2429
|
-
*/
|
|
2430
|
-
setLastPage() {
|
|
2431
|
-
this.setPage(this.pagination.lastPage);
|
|
2432
|
-
}
|
|
2433
|
-
/**
|
|
2434
|
-
* Set current page to first
|
|
2435
|
-
*/
|
|
2436
|
-
setFirstPage() {
|
|
2437
|
-
this.setPage(1);
|
|
2438
|
-
}
|
|
2439
|
-
/**
|
|
2440
|
-
* Check if page exists in cache
|
|
2441
|
-
*/
|
|
2442
|
-
hasPage(page) {
|
|
2443
|
-
return this.pages.has(page);
|
|
2444
|
-
}
|
|
2445
|
-
/**
|
|
2446
|
-
* Get the current page if it's in cache, otherwise invoke the request
|
|
2447
|
-
*/
|
|
2448
|
-
getPage(req) {
|
|
2449
|
-
let page = this.pagination.currentPage;
|
|
2450
|
-
if (this.hasPage(page)) {
|
|
2451
|
-
return this.selectPage(page);
|
|
2452
|
-
}
|
|
2453
|
-
else {
|
|
2454
|
-
this.setLoading(true);
|
|
2455
|
-
return from(req()).pipe(switchMap((config) => {
|
|
2456
|
-
page = config.currentPage;
|
|
2457
|
-
applyTransaction(() => {
|
|
2458
|
-
this.setLoading(false);
|
|
2459
|
-
this.update(config);
|
|
2460
|
-
});
|
|
2461
|
-
return this.selectPage(page);
|
|
2462
|
-
}));
|
|
2463
|
-
}
|
|
2464
|
-
}
|
|
2465
|
-
getQuery() {
|
|
2466
|
-
return this.query;
|
|
2467
|
-
}
|
|
2468
|
-
refreshCurrentPage() {
|
|
2469
|
-
if (isNil(this.currentPage) === false) {
|
|
2470
|
-
this.clearPage(this.currentPage);
|
|
2471
|
-
this.setPage(this.currentPage);
|
|
2472
|
-
}
|
|
2473
|
-
}
|
|
2474
|
-
getFrom() {
|
|
2475
|
-
if (this.isFirst) {
|
|
2476
|
-
return 1;
|
|
2477
|
-
}
|
|
2478
|
-
return (this.currentPage - 1) * this.pagination.perPage + 1;
|
|
2479
|
-
}
|
|
2480
|
-
getTo() {
|
|
2481
|
-
if (this.isLast) {
|
|
2482
|
-
return this.pagination.total;
|
|
2483
|
-
}
|
|
2484
|
-
return this.currentPage * this.pagination.perPage;
|
|
2485
|
-
}
|
|
2486
|
-
/**
|
|
2487
|
-
* Select the page
|
|
2488
|
-
*/
|
|
2489
|
-
selectPage(page) {
|
|
2490
|
-
return this.query.selectAll({ asObject: true }).pipe(take(1), map((entities) => {
|
|
2491
|
-
const response = Object.assign(Object.assign({}, this.pagination), { data: this.pages.get(page).ids.map((id) => entities[id]) });
|
|
2492
|
-
const { range, pagesControls } = this.config;
|
|
2493
|
-
/** If no total - calc it */
|
|
2494
|
-
if (isNaN(this.pagination.total)) {
|
|
2495
|
-
if (response.lastPage === 1) {
|
|
2496
|
-
response.total = response.data ? response.data.length : 0;
|
|
2497
|
-
}
|
|
2498
|
-
else {
|
|
2499
|
-
response.total = response.perPage * response.lastPage;
|
|
2500
|
-
}
|
|
2501
|
-
this.pagination.total = response.total;
|
|
2502
|
-
}
|
|
2503
|
-
if (range) {
|
|
2504
|
-
response.from = this.getFrom();
|
|
2505
|
-
response.to = this.getTo();
|
|
2506
|
-
}
|
|
2507
|
-
if (pagesControls) {
|
|
2508
|
-
response.pageControls = generatePages(this.pagination.total, this.pagination.perPage);
|
|
2509
|
-
}
|
|
2510
|
-
return response;
|
|
2511
|
-
}));
|
|
2512
|
-
}
|
|
2513
|
-
}
|
|
2514
|
-
__decorate([
|
|
2515
|
-
action('@Pagination - New Page'),
|
|
2516
|
-
__metadata("design:type", Function),
|
|
2517
|
-
__metadata("design:paramtypes", [Object]),
|
|
2518
|
-
__metadata("design:returntype", void 0)
|
|
2519
|
-
], PaginatorPlugin.prototype, "update", null);
|
|
2520
|
-
/**
|
|
2521
|
-
* Generate an array so we can ngFor them to navigate between pages
|
|
2522
|
-
*/
|
|
2523
|
-
function generatePages(total, perPage) {
|
|
2524
|
-
const len = Math.ceil(total / perPage);
|
|
2525
|
-
const arr = [];
|
|
2526
|
-
for (let i = 0; i < len; i++) {
|
|
2527
|
-
arr.push(i + 1);
|
|
2528
|
-
}
|
|
2529
|
-
return arr;
|
|
2530
|
-
}
|
|
2531
|
-
|
|
2532
|
-
var StoreAction;
|
|
2533
|
-
(function (StoreAction) {
|
|
2534
|
-
StoreAction["Update"] = "UPDATE";
|
|
2535
|
-
})(StoreAction || (StoreAction = {}));
|
|
2536
|
-
var EntityStoreAction;
|
|
2537
|
-
(function (EntityStoreAction) {
|
|
2538
|
-
EntityStoreAction["Update"] = "UPDATE";
|
|
2539
|
-
EntityStoreAction["AddEntities"] = "ADD_ENTITIES";
|
|
2540
|
-
EntityStoreAction["SetEntities"] = "SET_ENTITIES";
|
|
2541
|
-
EntityStoreAction["UpdateEntities"] = "UPDATE_ENTITIES";
|
|
2542
|
-
EntityStoreAction["RemoveEntities"] = "REMOVE_ENTITIES";
|
|
2543
|
-
EntityStoreAction["UpsertEntities"] = "UPSERT_ENTITIES";
|
|
2544
|
-
EntityStoreAction["UpsertManyEntities"] = "UPSERT_MANY_ENTITIES";
|
|
2545
|
-
})(EntityStoreAction || (EntityStoreAction = {}));
|
|
2546
|
-
|
|
2547
|
-
export { Query as Q, StoreConfig as S, Store as a, enableAkitaProdMode as e, persistState as p };
|