@kaspernj/api-maker 1.0.2011 → 1.0.2013
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/{.eslintrc.cjs → .eslintrc.js} +10 -1
- package/README.md +35 -0
- package/android/build.gradle +43 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/expo/modules/api_maker/ApiMakerModule.kt +50 -0
- package/android/src/main/java/expo/modules/api_maker/ApiMakerView.kt +30 -0
- package/build/api.js +120 -0
- package/build/attribute-not-loaded-error.js +2 -0
- package/build/base-component.js +5 -0
- package/build/base-error.js +33 -0
- package/build/base-model/attribute.js +25 -0
- package/build/base-model/column.js +11 -0
- package/build/base-model/reflection.js +14 -0
- package/build/base-model/scope.js +11 -0
- package/build/base-model.js +828 -0
- package/build/bootstrap/attribute-row.js +135 -0
- package/build/bootstrap/attribute-rows.js +31 -0
- package/build/bootstrap/card.js +138 -0
- package/build/bootstrap/checkbox.js +97 -0
- package/build/bootstrap/checkboxes.js +183 -0
- package/build/bootstrap/index.js +2 -0
- package/build/bootstrap/input.js +129 -0
- package/build/bootstrap/invalid-feedback.js +27 -0
- package/build/bootstrap/paginate.js +150 -0
- package/build/bootstrap/radio-buttons.js +72 -0
- package/build/bootstrap/select.js +88 -0
- package/build/bootstrap/sort-link.js +131 -0
- package/build/cable-connection-pool.js +128 -0
- package/build/cable-subscription-pool.js +207 -0
- package/build/cable-subscription.js +21 -0
- package/build/cache-key-generator.js +81 -0
- package/build/can-can.js +134 -0
- package/build/channels-consumer.js +9 -0
- package/build/collection-loader.js +48 -0
- package/build/collection.js +280 -0
- package/build/command-submit-data.js +81 -0
- package/build/commands-pool.js +195 -0
- package/build/compose.js +9 -0
- package/build/config.js +62 -0
- package/build/custom-error.js +5 -0
- package/build/data-set-to-attributes.js +10 -0
- package/build/deserializer.js +56 -0
- package/build/destroy-error.js +5 -0
- package/build/devise.js +112 -0
- package/build/draggable-sort/controller.js +136 -0
- package/build/draggable-sort/index.js +114 -0
- package/build/draggable-sort/item.js +188 -0
- package/build/error-logger.js +101 -0
- package/build/error-messages.js +13 -0
- package/build/event-connection.js +32 -0
- package/build/event-emitter-listener.js +15 -0
- package/build/event-model-class.js +24 -0
- package/build/events.js +5 -0
- package/build/flash-message.js +79 -0
- package/build/form.js +83 -0
- package/build/history-expo.js +20 -0
- package/build/history-react-native.js +20 -0
- package/build/history.js +3 -0
- package/build/index.js +3 -0
- package/build/inputs/attachment.js +133 -0
- package/build/inputs/auto-submit.js +36 -0
- package/build/inputs/checkbox.js +138 -0
- package/build/inputs/checkboxes.js +112 -0
- package/build/inputs/id-for-component.js +15 -0
- package/build/inputs/input-wrapper.js +19 -0
- package/build/inputs/input.js +243 -0
- package/build/inputs/money.js +179 -0
- package/build/inputs/name-for-component.js +13 -0
- package/build/inputs/select.js +93 -0
- package/build/instance-of-class-name.js +23 -0
- package/build/is-expo.js +22 -0
- package/build/key-value-store.js +53 -0
- package/build/link.js +73 -0
- package/build/logger.js +30 -0
- package/build/modal.js +38 -0
- package/build/model-class-require.js +13 -0
- package/build/model-events.js +30 -0
- package/build/model-name.js +28 -0
- package/build/model-prop-type.js +101 -0
- package/build/model-recipes-loader.js +32 -0
- package/build/model-recipes-model-loader.js +357 -0
- package/build/models-response-reader.js +40 -0
- package/build/models.js +8 -0
- package/build/money-formatter.js +78 -0
- package/build/not-loaded-error.js +2 -0
- package/build/params.js +61 -0
- package/build/preloaded.js +38 -0
- package/build/resize-observer.js +11 -0
- package/build/result.js +13 -0
- package/build/router/route.js +270 -0
- package/build/router/switch.js +72 -0
- package/build/router.js +59 -0
- package/build/routes-native.js +202 -0
- package/build/routes.js +50 -0
- package/build/run-last.js +35 -0
- package/build/serializer.js +63 -0
- package/build/services.js +20 -0
- package/build/session-status-updater.js +134 -0
- package/build/source-maps-loader.js +184 -0
- package/build/super-admin/config-reader.js +85 -0
- package/build/super-admin/edit-page/edit-attribute-checkbox.js +85 -0
- package/build/super-admin/edit-page/edit-attribute-content.js +55 -0
- package/build/super-admin/edit-page/edit-attribute-input.js +79 -0
- package/build/super-admin/edit-page/edit-attribute.js +77 -0
- package/build/super-admin/edit-page.js +123 -0
- package/build/super-admin/has-edit-config.js +12 -0
- package/build/super-admin/index-page.js +25 -0
- package/build/super-admin/index.js +181 -0
- package/build/super-admin/layout/header/index.js +161 -0
- package/build/super-admin/layout/index.js +164 -0
- package/build/super-admin/layout/menu/index.js +206 -0
- package/build/super-admin/layout/menu/menu-content.js +46 -0
- package/build/super-admin/layout/menu/menu-item.js +84 -0
- package/build/super-admin/layout/no-access.js +27 -0
- package/build/super-admin/model-class-table.js +61 -0
- package/build/super-admin/models.js +8 -0
- package/build/super-admin/show-nav.js +51 -0
- package/build/super-admin/show-page/belongs-to-attribute-row.js +29 -0
- package/build/super-admin/show-page/index.js +141 -0
- package/build/super-admin/show-reflection-actions.js +47 -0
- package/build/super-admin/show-reflection-link.js +48 -0
- package/build/super-admin/show-reflection-page.js +48 -0
- package/build/table/column-content.js +117 -0
- package/build/table/column-identifier.js +18 -0
- package/build/table/column-visible.js +7 -0
- package/build/table/components/column.js +21 -0
- package/build/table/components/flat-list.js +21 -0
- package/build/table/components/header.js +26 -0
- package/build/table/components/row.js +26 -0
- package/build/table/filters/attribute-element.js +44 -0
- package/build/table/filters/filter-form.js +402 -0
- package/build/table/filters/filter.js +90 -0
- package/build/table/filters/index.js +184 -0
- package/build/table/filters/load-search-modal.js +175 -0
- package/build/table/filters/reflection-element.js +37 -0
- package/build/table/filters/save-search-modal.js +88 -0
- package/build/table/filters/scope-element.js +42 -0
- package/build/table/header-column-content.js +68 -0
- package/build/table/header-column.js +144 -0
- package/build/table/header-select.js +105 -0
- package/build/table/model-callback-args.js +10 -0
- package/build/table/model-column.js +97 -0
- package/build/table/model-row.js +193 -0
- package/build/table/select-calculator.js +63 -0
- package/build/table/settings/column-row.js +97 -0
- package/build/table/settings/download-action.js +79 -0
- package/build/table/settings/index.js +92 -0
- package/build/table/table-settings.js +219 -0
- package/build/table/table.js +972 -0
- package/build/table/use-sorting.js +34 -0
- package/build/table/widths.js +75 -0
- package/build/table/worker-plugins-check-all-checkbox.js +125 -0
- package/build/table/worker-plugins-checkbox.js +115 -0
- package/build/translated-attributes.js +10 -0
- package/build/translated-collections.js +12 -0
- package/build/updated-attribute.js +76 -0
- package/build/url-encode.js +15 -0
- package/build/use-breakpoint.js +71 -0
- package/build/use-can-can.js +55 -0
- package/build/use-collection.js +225 -0
- package/build/use-created-event.js +52 -0
- package/build/use-current-user.js +76 -0
- package/build/use-destroyed-event.js +60 -0
- package/build/use-event-emitter.js +13 -0
- package/build/use-event-listener.js +16 -0
- package/build/use-input.js +137 -0
- package/build/use-model-event.js +60 -0
- package/build/use-model.js +169 -0
- package/build/use-resize-observer.js +23 -0
- package/build/use-router.js +104 -0
- package/build/use-screen-layout.js +39 -0
- package/build/use-styles.js +41 -0
- package/build/use-updated-event.js +60 -0
- package/build/use-validation-errors.js +30 -0
- package/build/utils/card.js +51 -0
- package/build/utils/checkbox.js +78 -0
- package/build/utils/checkboxes.js +163 -0
- package/build/utils/default-style.js +18 -0
- package/build/utils/icon.js +23 -0
- package/build/utils/invalid-feedback.js +19 -0
- package/build/utils/modal.js +62 -0
- package/build/utils/text.js +44 -0
- package/build/validation-error.js +28 -0
- package/build/validation-errors.js +98 -0
- package/build/with-api-maker.js +29 -0
- package/build/with-collection.js +14 -0
- package/build/with-current-user.js +10 -0
- package/build/with-model.js +15 -0
- package/build/with-router.js +22 -0
- package/expo-module.config.json +17 -0
- package/ios/ApiMaker.podspec +29 -0
- package/ios/ApiMakerModule.swift +48 -0
- package/ios/ApiMakerView.swift +38 -0
- package/package.json +49 -46
- package/src/{api.mjs → api.js} +38 -37
- package/src/base-component.jsx +5 -0
- package/src/{base-error.mjs → base-error.js} +4 -6
- package/src/base-model/attribute.js +33 -0
- package/src/base-model/column.js +13 -0
- package/src/base-model/reflection.js +15 -0
- package/src/base-model/scope.js +12 -0
- package/src/{base-model.mjs → base-model.js} +302 -144
- package/src/bootstrap/attribute-row.jsx +135 -0
- package/src/bootstrap/attribute-rows.jsx +27 -0
- package/src/bootstrap/card.jsx +149 -0
- package/src/bootstrap/checkbox.jsx +86 -0
- package/src/bootstrap/checkboxes.jsx +185 -0
- package/src/bootstrap/index.js +0 -0
- package/src/bootstrap/input.jsx +173 -0
- package/src/bootstrap/invalid-feedback.jsx +31 -0
- package/src/bootstrap/paginate.jsx +187 -0
- package/src/bootstrap/radio-buttons.jsx +87 -0
- package/src/bootstrap/select.jsx +110 -0
- package/src/bootstrap/sort-link.jsx +106 -0
- package/src/{cable-connection-pool.mjs → cable-connection-pool.js} +16 -36
- package/src/{cable-subscription-pool.mjs → cable-subscription-pool.js} +26 -21
- package/src/{cable-subscription.mjs → cable-subscription.js} +6 -4
- package/src/cache-key-generator.js +100 -0
- package/src/{can-can.mjs → can-can.js} +13 -12
- package/src/channels-consumer.js +10 -0
- package/src/collection-loader.jsx +58 -224
- package/src/{collection.mjs → collection.js} +98 -44
- package/src/{command-submit-data.mjs → command-submit-data.js} +2 -7
- package/src/{commands-pool.mjs → commands-pool.js} +57 -41
- package/src/compose.js +11 -0
- package/src/{config.mjs → config.js} +6 -2
- package/src/{custom-error.mjs → custom-error.js} +1 -1
- package/src/data-set-to-attributes.js +13 -0
- package/src/{deserializer.mjs → deserializer.js} +3 -3
- package/src/destroy-error.js +7 -0
- package/src/devise.js +129 -0
- package/src/draggable-sort/controller.js +137 -0
- package/src/draggable-sort/index.jsx +108 -0
- package/src/draggable-sort/item.jsx +174 -0
- package/src/{error-logger.mjs → error-logger.js} +12 -7
- package/src/{error-messages.mjs → error-messages.js} +1 -0
- package/src/event-connection.jsx +1 -1
- package/src/event-emitter-listener.jsx +8 -27
- package/src/event-model-class.jsx +2 -4
- package/src/events.js +7 -0
- package/src/flash-message.js +70 -0
- package/src/form.jsx +91 -0
- package/src/history-expo.js +23 -0
- package/src/history-react-native.js +25 -0
- package/src/history.js +3 -0
- package/src/index.js +3 -0
- package/src/inputs/attachment.jsx +108 -0
- package/src/inputs/auto-submit.js +37 -0
- package/src/inputs/checkbox.jsx +125 -0
- package/src/inputs/checkboxes.jsx +116 -0
- package/src/inputs/id-for-component.js +15 -0
- package/src/inputs/input-wrapper.jsx +16 -0
- package/src/inputs/input.jsx +260 -0
- package/src/inputs/money.jsx +187 -0
- package/src/inputs/name-for-component.js +15 -0
- package/src/inputs/select.jsx +104 -0
- package/src/is-expo.js +18 -0
- package/src/{key-value-store.mjs → key-value-store.js} +1 -1
- package/src/link.jsx +54 -9
- package/src/logger.js +38 -0
- package/src/modal.jsx +37 -0
- package/src/model-class-require.js +17 -0
- package/src/{model-events.mjs → model-events.js} +1 -1
- package/src/{model-name.mjs → model-name.js} +8 -8
- package/src/{model-recipes-loader.mjs → model-recipes-loader.js} +1 -1
- package/src/{model-recipes-model-loader.mjs → model-recipes-model-loader.js} +5 -5
- package/src/{models-response-reader.mjs → models-response-reader.js} +3 -4
- package/src/models.js +7 -0
- package/src/{models.mjs.erb → models.js.erb} +6 -3
- package/src/{money-formatter.mjs → money-formatter.js} +5 -4
- package/src/{params.mjs → params.js} +17 -7
- package/src/{preloaded.mjs → preloaded.js} +2 -2
- package/src/resize-observer.jsx +10 -0
- package/src/result.js +13 -0
- package/src/router/route.jsx +246 -0
- package/src/router/switch.jsx +76 -0
- package/src/router.jsx +23 -21
- package/src/{routes-native.mjs → routes-native.js} +12 -6
- package/src/{routes.mjs → routes.js} +1 -1
- package/src/run-last.js +39 -0
- package/src/{serializer.mjs → serializer.js} +2 -2
- package/src/{services.mjs → services.js} +1 -1
- package/src/session-status-updater.js +172 -0
- package/src/{source-maps-loader.mjs → source-maps-loader.js} +54 -28
- package/src/super-admin/config-reader.jsx +93 -0
- package/src/super-admin/edit-page/edit-attribute-checkbox.jsx +81 -0
- package/src/super-admin/edit-page/edit-attribute-content.jsx +57 -0
- package/src/super-admin/edit-page/edit-attribute-input.jsx +71 -0
- package/src/super-admin/edit-page/edit-attribute.jsx +81 -0
- package/src/super-admin/edit-page.jsx +117 -0
- package/src/super-admin/has-edit-config.js +15 -0
- package/src/super-admin/index-page.jsx +23 -0
- package/src/super-admin/index.jsx +197 -0
- package/src/super-admin/layout/header/index.jsx +144 -0
- package/src/super-admin/layout/header/style.scss +45 -0
- package/src/super-admin/layout/index.jsx +154 -0
- package/src/super-admin/layout/menu/index.jsx +171 -0
- package/src/super-admin/layout/menu/menu-content.jsx +43 -0
- package/src/super-admin/layout/menu/menu-item.jsx +70 -0
- package/src/super-admin/layout/menu/style.scss +11 -0
- package/src/super-admin/layout/no-access.jsx +26 -0
- package/src/super-admin/model-class-table.jsx +66 -0
- package/src/super-admin/models.js +11 -0
- package/src/super-admin/show-nav.jsx +44 -0
- package/src/super-admin/show-page/belongs-to-attribute-row.jsx +30 -0
- package/src/super-admin/show-page/index.jsx +141 -0
- package/src/super-admin/show-reflection-actions.jsx +49 -0
- package/src/super-admin/show-reflection-link.jsx +40 -0
- package/src/super-admin/show-reflection-page.jsx +47 -0
- package/src/super-admin/stylesheets/variables.scss +11 -0
- package/src/table/column-content.jsx +122 -0
- package/src/table/column-identifier.js +23 -0
- package/src/table/column-visible.js +7 -0
- package/src/table/components/column.jsx +19 -0
- package/src/table/components/flat-list.jsx +19 -0
- package/src/table/components/header.jsx +21 -0
- package/src/table/components/row.jsx +23 -0
- package/src/table/filters/attribute-element.jsx +47 -0
- package/src/table/filters/filter-form.jsx +407 -0
- package/src/table/filters/filter.jsx +70 -0
- package/src/table/filters/index.jsx +170 -0
- package/src/table/filters/load-search-modal.jsx +146 -0
- package/src/table/filters/reflection-element.jsx +38 -0
- package/src/table/filters/save-search-modal.jsx +74 -0
- package/src/table/filters/scope-element.jsx +44 -0
- package/src/table/header-column-content.jsx +55 -0
- package/src/table/header-column.jsx +129 -0
- package/src/table/header-select.jsx +73 -0
- package/src/table/model-callback-args.js +10 -0
- package/src/table/model-column.jsx +82 -0
- package/src/table/model-row.jsx +136 -0
- package/src/table/select-calculator.js +65 -0
- package/src/table/settings/column-row.jsx +93 -0
- package/src/table/settings/download-action.jsx +68 -0
- package/src/table/settings/index.jsx +65 -0
- package/src/table/table-settings.js +263 -0
- package/src/table/table.jsx +950 -0
- package/src/table/use-sorting.js +35 -0
- package/src/table/variables.scss +11 -0
- package/src/table/widths.jsx +87 -0
- package/src/table/worker-plugins-check-all-checkbox.jsx +112 -0
- package/src/table/worker-plugins-checkbox.jsx +104 -0
- package/src/translated-attributes.js +11 -0
- package/src/{translated-collections.mjs → translated-collections.js} +3 -2
- package/src/updated-attribute.jsx +1 -1
- package/src/url-encode.js +18 -0
- package/src/use-breakpoint.js +87 -0
- package/src/use-can-can.js +55 -0
- package/src/use-collection.js +280 -0
- package/src/use-created-event.js +55 -0
- package/src/use-current-user.js +88 -0
- package/src/use-destroyed-event.js +60 -0
- package/src/use-event-emitter.js +15 -0
- package/src/use-event-listener.js +19 -0
- package/src/use-input.js +157 -0
- package/src/use-model-event.js +60 -0
- package/src/use-model.js +189 -0
- package/src/use-resize-observer.js +24 -0
- package/src/use-router.jsx +128 -0
- package/src/use-screen-layout.js +49 -0
- package/src/use-styles.js +50 -0
- package/src/use-updated-event.js +60 -0
- package/src/use-validation-errors.js +33 -0
- package/src/utils/card.jsx +49 -0
- package/src/utils/checkbox.jsx +80 -0
- package/src/utils/checkboxes.jsx +158 -0
- package/src/utils/default-style.jsx +25 -0
- package/src/utils/icon.jsx +21 -0
- package/src/utils/invalid-feedback.jsx +20 -0
- package/src/utils/modal.jsx +60 -0
- package/src/utils/text.jsx +38 -0
- package/src/{validation-error.mjs → validation-error.js} +9 -5
- package/src/{validation-errors.mjs → validation-errors.js} +15 -27
- package/src/with-api-maker.jsx +31 -0
- package/src/with-collection.jsx +17 -0
- package/src/with-current-user.jsx +7 -25
- package/src/with-model.jsx +16 -0
- package/src/with-router.jsx +7 -129
- package/__tests__/base-model.test.js +0 -71
- package/__tests__/cable-connection-pool.test.js +0 -227
- package/__tests__/cable-subscription-pool.test.js +0 -26
- package/__tests__/can-can.test.js +0 -34
- package/__tests__/collection.test.js +0 -51
- package/__tests__/custom-error.test.js +0 -13
- package/__tests__/model-name.test.js +0 -34
- package/__tests__/model-prop-type.test.js +0 -113
- package/__tests__/params.test.js +0 -40
- package/__tests__/routes-native.test.js +0 -103
- package/__tests__/routes.test.js +0 -46
- package/__tests__/serializer.test.js +0 -30
- package/__tests__/support/task.js +0 -27
- package/__tests__/support/user.js +0 -32
- package/index.js +0 -1
- package/jest.config.js +0 -4
- package/src/can-can-loader.jsx +0 -54
- package/src/channels-consumer.mjs +0 -3
- package/src/destroy-error.mjs +0 -7
- package/src/devise.mjs +0 -122
- package/src/event-created.jsx +0 -65
- package/src/event-destroyed.jsx +0 -29
- package/src/event-listener.jsx +0 -38
- package/src/event-updated.jsx +0 -74
- package/src/logger.mjs +0 -25
- package/src/model-class-require.mjs +0 -10
- package/src/model-load-wrapper.jsx +0 -116
- package/src/result.mjs +0 -29
- package/src/session-status-updater.mjs +0 -116
- package/webpack.config.js +0 -15
- /package/src/{attribute-not-loaded-error.mjs → attribute-not-loaded-error.js} +0 -0
- /package/src/{instance-of-class-name.mjs → instance-of-class-name.js} +0 -0
- /package/src/{model-prop-type.mjs → model-prop-type.js} +0 -0
- /package/src/{not-loaded-error.mjs → not-loaded-error.js} +0 -0
- /package/src/{translated-collections-data.mjs.erb → translated-collections-data.js.erb} +0 -0
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import CableSubscriptionPool from "./cable-subscription-pool
|
|
2
|
-
import CableSubscription from "./cable-subscription
|
|
1
|
+
import CableSubscriptionPool from "./cable-subscription-pool"
|
|
2
|
+
import CableSubscription from "./cable-subscription"
|
|
3
3
|
import {dig} from "diggerize"
|
|
4
|
+
import RunLast from "./run-last"
|
|
4
5
|
|
|
5
6
|
const shared = {}
|
|
6
7
|
|
|
7
8
|
export default class ApiMakerCableConnectionPool {
|
|
9
|
+
cableSubscriptionPools = []
|
|
10
|
+
connections = {}
|
|
11
|
+
upcomingSubscriptionData = {}
|
|
12
|
+
upcomingSubscriptions = {}
|
|
13
|
+
|
|
8
14
|
static current () {
|
|
9
15
|
if (!shared.apiMakerCableConnectionPool) shared.apiMakerCableConnectionPool = new ApiMakerCableConnectionPool()
|
|
10
16
|
|
|
11
17
|
return shared.apiMakerCableConnectionPool
|
|
12
18
|
}
|
|
13
19
|
|
|
14
|
-
constructor () {
|
|
15
|
-
this.cableSubscriptionPools = []
|
|
16
|
-
this.connections = {}
|
|
17
|
-
this.upcomingSubscriptionData = {}
|
|
18
|
-
this.upcomingSubscriptions = {}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
20
|
connectEventToExistingSubscription ({path, subscription, value}) {
|
|
22
21
|
for (const cableSubscriptionPool of this.cableSubscriptionPools) {
|
|
23
22
|
if (!cableSubscriptionPool.isConnected()) {
|
|
@@ -98,32 +97,18 @@ export default class ApiMakerCableConnectionPool {
|
|
|
98
97
|
currentSubscription[value].push(subscription)
|
|
99
98
|
}
|
|
100
99
|
|
|
101
|
-
this.
|
|
100
|
+
this.scheduleConnectUpcomingRunLast.queue()
|
|
102
101
|
|
|
103
102
|
return subscription
|
|
104
103
|
}
|
|
105
104
|
|
|
106
|
-
connectCreated (modelName, callback) {
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return this.connectModelEvent({callback, value: modelId, path: [modelName, "events", eventName]})
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
connectDestroyed (modelName, modelId, callback) {
|
|
115
|
-
return this.connectModelEvent({callback, value: modelId, path: [modelName, "destroys"]})
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
connectModelClassEvent (modelName, eventName, callback) {
|
|
119
|
-
return this.connectModelEvent({callback, value: eventName, path: [modelName, "model_class_events"]})
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
connectUpdate (modelName, modelId, callback) {
|
|
123
|
-
return this.connectModelEvent({callback, value: modelId, path: [modelName, "updates"]})
|
|
124
|
-
}
|
|
105
|
+
connectCreated = (modelName, callback) => this.connectModelEvent({callback, value: true, path: [modelName, "creates"]})
|
|
106
|
+
connectEvent = (modelName, modelId, eventName, callback) => this.connectModelEvent({callback, value: modelId, path: [modelName, "events", eventName]})
|
|
107
|
+
connectDestroyed = (modelName, modelId, callback) => this.connectModelEvent({callback, value: modelId, path: [modelName, "destroys"]})
|
|
108
|
+
connectModelClassEvent = (modelName, eventName, callback) => this.connectModelEvent({callback, value: eventName, path: [modelName, "model_class_events"]})
|
|
109
|
+
connectUpdate = (modelName, modelId, callback) => this.connectModelEvent({callback, value: modelId, path: [modelName, "updates"]})
|
|
125
110
|
|
|
126
|
-
connectUpcoming () {
|
|
111
|
+
connectUpcoming = () => {
|
|
127
112
|
const subscriptionData = this.upcomingSubscriptionData
|
|
128
113
|
const subscriptions = this.upcomingSubscriptions
|
|
129
114
|
|
|
@@ -138,10 +123,5 @@ export default class ApiMakerCableConnectionPool {
|
|
|
138
123
|
this.cableSubscriptionPools.push(cableSubscriptionPool)
|
|
139
124
|
}
|
|
140
125
|
|
|
141
|
-
|
|
142
|
-
if (this.scheduleConnectUpcomingTimeout)
|
|
143
|
-
clearTimeout(this.scheduleConnectUpcomingTimeout)
|
|
144
|
-
|
|
145
|
-
this.scheduleConnectUpcomingTimeout = setTimeout(() => this.connectUpcoming(), 0)
|
|
146
|
-
}
|
|
126
|
+
scheduleConnectUpcomingRunLast = new RunLast(this.connectUpcoming)
|
|
147
127
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import CommandsPool from "./commands-pool
|
|
3
|
-
import Deserializer from "./deserializer
|
|
1
|
+
import getChannelsConsumer from "./channels-consumer"
|
|
2
|
+
import CommandsPool from "./commands-pool"
|
|
3
|
+
import Deserializer from "./deserializer"
|
|
4
4
|
import {digg} from "diggerize"
|
|
5
|
-
import inflection from "inflection"
|
|
6
|
-
import Logger from "./logger
|
|
5
|
+
import * as inflection from "inflection"
|
|
6
|
+
import Logger from "./logger"
|
|
7
|
+
|
|
8
|
+
const logger = new Logger({name: "ApiMaker / CableSubscriptionPool"})
|
|
7
9
|
|
|
8
10
|
export default class ApiMakerCableSubscriptionPool {
|
|
9
11
|
constructor () {
|
|
@@ -14,15 +16,18 @@ export default class ApiMakerCableSubscriptionPool {
|
|
|
14
16
|
connect (subscriptionData) {
|
|
15
17
|
const globalData = CommandsPool.current().globalRequestData
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
logger.debug(() => ["Creating subscription", {subscriptionData}])
|
|
20
|
+
|
|
21
|
+
this.subscription = getChannelsConsumer().subscriptions.create(
|
|
18
22
|
{
|
|
19
23
|
channel: "ApiMaker::SubscriptionsChannel",
|
|
20
24
|
global: globalData,
|
|
21
25
|
subscription_data: subscriptionData
|
|
22
26
|
},
|
|
23
27
|
{
|
|
24
|
-
connected:
|
|
25
|
-
received:
|
|
28
|
+
connected: this.onConnected,
|
|
29
|
+
received: this.onReceived,
|
|
30
|
+
subscribed: this.onSubscribed
|
|
26
31
|
}
|
|
27
32
|
)
|
|
28
33
|
this.connected = true
|
|
@@ -69,17 +74,15 @@ export default class ApiMakerCableSubscriptionPool {
|
|
|
69
74
|
}
|
|
70
75
|
}
|
|
71
76
|
|
|
72
|
-
isConnected ()
|
|
73
|
-
return digg(this, "connected")
|
|
74
|
-
}
|
|
77
|
+
isConnected = () => digg(this, "connected")
|
|
75
78
|
|
|
76
|
-
onConnected () {
|
|
79
|
+
onConnected = () => {
|
|
77
80
|
this.forEachSubscription(({subscription}) => {
|
|
78
81
|
subscription.events.emit("connected")
|
|
79
82
|
})
|
|
80
83
|
}
|
|
81
84
|
|
|
82
|
-
onReceived (rawData) {
|
|
85
|
+
onReceived = (rawData) => {
|
|
83
86
|
const data = Deserializer.parse(rawData)
|
|
84
87
|
const {a: args, e: eventName, m: model, mi: modelId, mt: modelType, t: type} = data
|
|
85
88
|
const subscriptions = digg(this, "subscriptions")
|
|
@@ -124,13 +127,17 @@ export default class ApiMakerCableSubscriptionPool {
|
|
|
124
127
|
}
|
|
125
128
|
}
|
|
126
129
|
|
|
130
|
+
onSubscribed = () => {
|
|
131
|
+
logger.debug("onSubscribed")
|
|
132
|
+
}
|
|
133
|
+
|
|
127
134
|
onUnsubscribe () {
|
|
128
|
-
|
|
135
|
+
logger.debug(() => `activeSubscriptions before unsub: ${this.activeSubscriptions}`)
|
|
129
136
|
this.activeSubscriptions -= 1
|
|
130
|
-
|
|
137
|
+
logger.debug(() => `activeSubscriptions after unsub: ${this.activeSubscriptions}`)
|
|
131
138
|
|
|
132
139
|
if (this.activeSubscriptions <= 0) {
|
|
133
|
-
|
|
140
|
+
logger.debug("Unsubscribe from ActionCable subscription")
|
|
134
141
|
this.subscription.unsubscribe()
|
|
135
142
|
this.connected = false
|
|
136
143
|
}
|
|
@@ -139,8 +146,7 @@ export default class ApiMakerCableSubscriptionPool {
|
|
|
139
146
|
registerSubscriptions (subscriptions) {
|
|
140
147
|
this.subscriptions = subscriptions
|
|
141
148
|
|
|
142
|
-
|
|
143
|
-
Logger.log(subscriptions)
|
|
149
|
+
logger.debug(() => ["registerSubscriptions", {subscriptions}])
|
|
144
150
|
|
|
145
151
|
for (const modelName in subscriptions) {
|
|
146
152
|
if (subscriptions[modelName].creates) {
|
|
@@ -170,13 +176,12 @@ export default class ApiMakerCableSubscriptionPool {
|
|
|
170
176
|
}
|
|
171
177
|
|
|
172
178
|
connectUnsubscriptionForSubscription (subscription) {
|
|
173
|
-
|
|
174
|
-
Logger.log({subscription})
|
|
179
|
+
logger.debug(() => ["Connecting to unsubscribe on subscription", {subscription}])
|
|
175
180
|
|
|
176
181
|
this.activeSubscriptions += 1
|
|
177
182
|
|
|
178
183
|
subscription.events.addListener("unsubscribed", () => {
|
|
179
|
-
|
|
184
|
+
logger.debug("Call onUnsubscribe on self")
|
|
180
185
|
|
|
181
186
|
this.onUnsubscribe(subscription)
|
|
182
187
|
})
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import EventEmitter from "events"
|
|
2
|
-
import Logger from "./logger
|
|
2
|
+
import Logger from "./logger"
|
|
3
|
+
|
|
4
|
+
const logger = new Logger({name: "ApiMaker / CableSubscription"})
|
|
3
5
|
|
|
4
6
|
export default class ApiMakerCableSubscription {
|
|
5
7
|
constructor () {
|
|
@@ -9,13 +11,13 @@ export default class ApiMakerCableSubscription {
|
|
|
9
11
|
|
|
10
12
|
unsubscribe () {
|
|
11
13
|
if (!this.subscribed) {
|
|
12
|
-
|
|
14
|
+
logger.debug("Unsubscribed already called")
|
|
13
15
|
return
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
logger.debug("Unsubscribe called for subscription")
|
|
17
19
|
|
|
18
|
-
this.events.emit("unsubscribed")
|
|
19
20
|
this.subscribed = false
|
|
21
|
+
this.events.emit("unsubscribed")
|
|
20
22
|
}
|
|
21
23
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import SparkMD5 from "spark-md5"
|
|
2
|
+
|
|
3
|
+
export default class CacheKeyGenerator {
|
|
4
|
+
constructor(model) {
|
|
5
|
+
this.model = model
|
|
6
|
+
this.allModels = [model]
|
|
7
|
+
this.readModels = {}
|
|
8
|
+
this.recordModelType(model.modelClassData().name)
|
|
9
|
+
this.recordModel(model.modelClassData().name, model)
|
|
10
|
+
this.filledModels = false
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
local() {
|
|
14
|
+
const md5 = new SparkMD5()
|
|
15
|
+
|
|
16
|
+
this.feedModel(this.model, md5)
|
|
17
|
+
|
|
18
|
+
return md5.end()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
recordModelType(relationshipType) {
|
|
22
|
+
if (!(relationshipType in this.readModels)) {
|
|
23
|
+
this.readModels[relationshipType] = {}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
recordModel(relationshipType, model) {
|
|
28
|
+
this.allModels.push(model)
|
|
29
|
+
this.readModels[relationshipType][model.id() || model.uniqueKey()] = true
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
isModelRecorded(relationshipType, model) {
|
|
33
|
+
if (model.id() in this.readModels[relationshipType]) {
|
|
34
|
+
return true
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
fillModels(model) {
|
|
39
|
+
for (const relationshipType in model.relationships) {
|
|
40
|
+
this.recordModelType(relationshipType)
|
|
41
|
+
|
|
42
|
+
const loadedRelationship = model.relationships[relationshipType]
|
|
43
|
+
|
|
44
|
+
if (Array.isArray(loadedRelationship)) { // has_many
|
|
45
|
+
for (const anotherModel of loadedRelationship) {
|
|
46
|
+
if (this.isModelRecorded(relationshipType, anotherModel)) {
|
|
47
|
+
continue
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
this.recordModel(relationshipType, anotherModel)
|
|
51
|
+
this.fillModels(anotherModel)
|
|
52
|
+
}
|
|
53
|
+
} else if (loadedRelationship) { // belongs_to, has_one
|
|
54
|
+
if (this.isModelRecorded(relationshipType, loadedRelationship)) {
|
|
55
|
+
continue
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this.recordModel(relationshipType, loadedRelationship)
|
|
59
|
+
this.fillModels(loadedRelationship)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
this.filledModels = true
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
cacheKey() {
|
|
67
|
+
if (!this.filledModels) {
|
|
68
|
+
this.fillModels(this.model)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const md5 = new SparkMD5()
|
|
72
|
+
|
|
73
|
+
for (const model of this.allModels) {
|
|
74
|
+
this.feedModel(model, md5)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return md5.end()
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
feedModel(model, md5) {
|
|
81
|
+
md5.append("--model--")
|
|
82
|
+
md5.append(model.modelClassData().name)
|
|
83
|
+
md5.append("--unique-key--")
|
|
84
|
+
md5.append(model.id() || model.uniqueKey())
|
|
85
|
+
|
|
86
|
+
if (model.markedForDestruction()) {
|
|
87
|
+
md5.append("--marked-for-destruction--")
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
md5.append("-attributes-")
|
|
91
|
+
|
|
92
|
+
const attributes = model.attributes()
|
|
93
|
+
|
|
94
|
+
for (const attributeName in attributes) {
|
|
95
|
+
md5.append(attributeName)
|
|
96
|
+
md5.append("--attribute--")
|
|
97
|
+
md5.append(`${model.readAttributeUnderscore(attributeName)}`)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
import {digg} from "diggerize"
|
|
2
2
|
import EventEmitter from "events"
|
|
3
|
-
import inflection from "inflection"
|
|
3
|
+
import * as inflection from "inflection"
|
|
4
4
|
import {ReadersWriterLock} from "epic-locks"
|
|
5
|
-
import Services from "./services
|
|
5
|
+
import Services from "./services"
|
|
6
6
|
|
|
7
7
|
const shared = {}
|
|
8
8
|
|
|
9
9
|
export default class ApiMakerCanCan {
|
|
10
|
+
abilities = []
|
|
11
|
+
abilitiesToLoad = []
|
|
12
|
+
abilitiesToLoadData = []
|
|
13
|
+
events = new EventEmitter()
|
|
14
|
+
lock = new ReadersWriterLock()
|
|
15
|
+
|
|
10
16
|
static current () {
|
|
11
17
|
if (!shared.currentApiMakerCanCan) shared.currentApiMakerCanCan = new ApiMakerCanCan()
|
|
12
18
|
|
|
13
19
|
return shared.currentApiMakerCanCan
|
|
14
20
|
}
|
|
15
21
|
|
|
16
|
-
constructor () {
|
|
17
|
-
this.abilities = []
|
|
18
|
-
this.abilitiesToLoad = []
|
|
19
|
-
this.abilitiesToLoadData = []
|
|
20
|
-
this.events = new EventEmitter()
|
|
21
|
-
this.lock = new ReadersWriterLock()
|
|
22
|
-
}
|
|
23
|
-
|
|
24
22
|
can (ability, subject) {
|
|
25
23
|
let abilityToUse = inflection.underscore(ability)
|
|
26
24
|
const foundAbility = this.findAbility(abilityToUse, subject)
|
|
@@ -83,6 +81,9 @@ export default class ApiMakerCanCan {
|
|
|
83
81
|
for (const abilityData of abilities) {
|
|
84
82
|
const subject = abilityData[0]
|
|
85
83
|
|
|
84
|
+
if (!subject) throw new Error(`Invalid subject given in abilities: ${subject} - ${JSON.stringify(abilities)}`)
|
|
85
|
+
if (!Array.isArray(abilityData[1])) throw new Error(`Expected an array of abilities but got: ${typeof abilityData[1]}: ${abilityData[1]}`)
|
|
86
|
+
|
|
86
87
|
for (const ability of abilityData[1]) {
|
|
87
88
|
const promise = this.loadAbility(ability, subject)
|
|
88
89
|
|
|
@@ -121,7 +122,7 @@ export default class ApiMakerCanCan {
|
|
|
121
122
|
clearTimeout(this.queueAbilitiesRequestTimeout)
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
this.queueAbilitiesRequestTimeout = setTimeout(
|
|
125
|
+
this.queueAbilitiesRequestTimeout = setTimeout(this.sendAbilitiesRequest, 0)
|
|
125
126
|
}
|
|
126
127
|
|
|
127
128
|
async resetAbilities () {
|
|
@@ -131,7 +132,7 @@ export default class ApiMakerCanCan {
|
|
|
131
132
|
this.events.emit("onResetAbilities")
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
async
|
|
135
|
+
sendAbilitiesRequest = async () => {
|
|
135
136
|
const abilitiesToLoad = this.abilitiesToLoad
|
|
136
137
|
const abilitiesToLoadData = this.abilitiesToLoadData
|
|
137
138
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Config from "./config"
|
|
2
|
+
import {createConsumer} from "@rails/actioncable"
|
|
3
|
+
|
|
4
|
+
export default () => {
|
|
5
|
+
if (!globalThis.apiMakerChannelsConsumer) {
|
|
6
|
+
globalThis.apiMakerChannelsConsumer = createConsumer(Config.getCableUrl())
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return globalThis.apiMakerChannelsConsumer
|
|
10
|
+
}
|
|
@@ -1,226 +1,60 @@
|
|
|
1
|
-
import Collection from "
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import EventDestroyed from "@kaspernj/api-maker/src/event-destroyed"
|
|
6
|
-
import EventUpdated from "@kaspernj/api-maker/src/event-updated"
|
|
7
|
-
import instanceOfClassName from "@kaspernj/api-maker/src/instance-of-class-name"
|
|
8
|
-
import Params from "@kaspernj/api-maker/src/params"
|
|
1
|
+
import Collection from "./collection"
|
|
2
|
+
import {digg} from "diggerize"
|
|
3
|
+
import memo from "set-state-compare/src/memo"
|
|
4
|
+
import {useMemo} from "react"
|
|
9
5
|
import PropTypes from "prop-types"
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
selectColumns: PropTypes.object
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
shape = digg(this, "props", "component", "shape")
|
|
47
|
-
|
|
48
|
-
constructor (props) {
|
|
49
|
-
super(props)
|
|
50
|
-
|
|
51
|
-
let queryName = props.queryName
|
|
52
|
-
|
|
53
|
-
if (!queryName) queryName = digg(props.modelClass.modelClassData(), "collectionKey")
|
|
54
|
-
|
|
55
|
-
this.shape.set({
|
|
56
|
-
models: undefined,
|
|
57
|
-
overallCount: undefined,
|
|
58
|
-
query: undefined,
|
|
59
|
-
queryName,
|
|
60
|
-
queryQName: `${queryName}_q`,
|
|
61
|
-
queryPageName: `${queryName}_page`,
|
|
62
|
-
qParams: undefined,
|
|
63
|
-
result: undefined,
|
|
64
|
-
showNoRecordsAvailableContent: false,
|
|
65
|
-
showNoRecordsFoundContent: false
|
|
66
|
-
})
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
componentDidMount () {
|
|
70
|
-
this.loadQParams()
|
|
71
|
-
this.loadModels()
|
|
72
|
-
|
|
73
|
-
const {noRecordsAvailableContent} = digs(this.props, "noRecordsAvailableContent")
|
|
74
|
-
|
|
75
|
-
if (noRecordsAvailableContent) this.loadOverallCount()
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async loadOverallCount () {
|
|
79
|
-
const baseQuery = this.props.collection || this.props.modelClass.all()
|
|
80
|
-
const overallCount = await baseQuery.count()
|
|
81
|
-
|
|
82
|
-
this.shape.set({
|
|
83
|
-
overallCount,
|
|
84
|
-
showNoRecordsAvailableContent: this.showNoRecordsAvailableContent({overallCount}),
|
|
85
|
-
showNoRecordsFoundContent: this.showNoRecordsFoundContent({overallCount})
|
|
86
|
-
})
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
loadQParams () {
|
|
90
|
-
const {queryQName} = digs(this.shape, "queryQName")
|
|
91
|
-
const params = Params.parse()
|
|
92
|
-
const qParams = Object.assign({}, this.props.defaultParams, params[queryQName])
|
|
93
|
-
|
|
94
|
-
this.shape.set({qParams})
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
loadModels = async () => {
|
|
98
|
-
const params = Params.parse()
|
|
99
|
-
const {abilities, collection, groupBy, modelClass, onModelsLoaded, preloads, select, selectColumns} = this.props
|
|
100
|
-
const {qParams, queryPageName, queryQName} = digs(this.shape, "qParams", "queryPageName", "queryQName")
|
|
101
|
-
|
|
102
|
-
let query = collection?.clone() || modelClass.ransack()
|
|
103
|
-
|
|
104
|
-
if (groupBy) query = query.groupBy(...groupBy)
|
|
105
|
-
|
|
106
|
-
query = query
|
|
107
|
-
.ransack(qParams)
|
|
108
|
-
.searchKey(queryQName)
|
|
109
|
-
.page(params[queryPageName])
|
|
110
|
-
.pageKey(queryPageName)
|
|
111
|
-
.preload(preloads)
|
|
112
|
-
.select(select)
|
|
113
|
-
|
|
114
|
-
if (abilities) query = query.abilities(abilities)
|
|
115
|
-
if (selectColumns) query = query.selectColumns(selectColumns)
|
|
116
|
-
|
|
117
|
-
const result = await query.result()
|
|
118
|
-
const models = result.models()
|
|
119
|
-
|
|
120
|
-
if (onModelsLoaded) {
|
|
121
|
-
onModelsLoaded({
|
|
122
|
-
models,
|
|
123
|
-
qParams,
|
|
124
|
-
query,
|
|
125
|
-
result
|
|
126
|
-
})
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
this.shape.set({
|
|
130
|
-
query,
|
|
131
|
-
result,
|
|
132
|
-
models: result.models(),
|
|
133
|
-
showNoRecordsAvailableContent: this.showNoRecordsAvailableContent({models}),
|
|
134
|
-
showNoRecordsFoundContent: this.showNoRecordsFoundContent({models})
|
|
135
|
-
})
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
loadModelsDebounce = debounce(digg(this, "loadModels"))
|
|
139
|
-
onModelCreated = digg(this, "loadModels")
|
|
140
|
-
|
|
141
|
-
onModelDestroyed = (args) => {
|
|
142
|
-
const {models} = digs(this.shape, "models")
|
|
143
|
-
|
|
144
|
-
this.shape.set({
|
|
145
|
-
models: models.filter((model) => model.id() != args.model.id())
|
|
146
|
-
})
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
onModelUpdated = (args) => {
|
|
150
|
-
const {models} = digs(this.shape, "models")
|
|
151
|
-
const updatedModel = digg(args, "model")
|
|
152
|
-
const foundModel = models.find((model) => model.id() == updatedModel.id())
|
|
153
|
-
|
|
154
|
-
if (foundModel) this.loadModelsDebounce()
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
onLocationChanged = () => {
|
|
158
|
-
const {queryQName} = digs(this.shape, "queryQName")
|
|
159
|
-
const params = Params.parse()
|
|
160
|
-
const qParams = Object.assign({}, this.props.defaultParams, params[queryQName])
|
|
161
|
-
|
|
162
|
-
this.shape.set({qParams})
|
|
163
|
-
this.loadModels()
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
showNoRecordsAvailableContent (args) {
|
|
167
|
-
const {noRecordsAvailableContent} = digs(this.props, "noRecordsAvailableContent")
|
|
168
|
-
let models, overallCount
|
|
169
|
-
|
|
170
|
-
if (args.models !== undefined) {
|
|
171
|
-
models = args.models
|
|
172
|
-
} else if (this.shape.models !== undefined) {
|
|
173
|
-
models = this.shape.models
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (args.overallCount !== undefined) {
|
|
177
|
-
overallCount = args.overallCount
|
|
178
|
-
} else if (this.shape.overallCount !== undefined) {
|
|
179
|
-
overallCount = this.shape.overallCount
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (models === undefined || overallCount === undefined || noRecordsAvailableContent === undefined) return false
|
|
183
|
-
if (models.length === 0 && overallCount === 0 && noRecordsAvailableContent) return true
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
showNoRecordsFoundContent (args) {
|
|
187
|
-
const {noRecordsAvailableContent, noRecordsFoundContent} = digs(this.props, "noRecordsAvailableContent", "noRecordsFoundContent")
|
|
188
|
-
let models, overallCount
|
|
189
|
-
|
|
190
|
-
if (args.models !== undefined) {
|
|
191
|
-
models = args.models
|
|
192
|
-
} else if (this.shape.models !== undefined) {
|
|
193
|
-
models = this.shape.models
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (args.overallCount !== undefined) {
|
|
197
|
-
overallCount = args.overallCount
|
|
198
|
-
} else if (this.shape.overallCount !== undefined) {
|
|
199
|
-
overallCount = this.shape.overallCount
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (models === undefined || noRecordsFoundContent === undefined) return false
|
|
203
|
-
|
|
204
|
-
// Dont show noRecordsAvailableContent together with noRecordsAvailableContent
|
|
205
|
-
if (models.length === 0 && overallCount === 0 && noRecordsAvailableContent) return false
|
|
206
|
-
if (models.length === 0 && noRecordsFoundContent) return true
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
render() {
|
|
210
|
-
const {modelClass} = digs(this.props, "modelClass")
|
|
211
|
-
const {models} = digs(this.shape, "models")
|
|
212
|
-
|
|
213
|
-
return (
|
|
214
|
-
<>
|
|
215
|
-
<EventCreated modelClass={modelClass} onCreated={digg(this, "onModelCreated")} />
|
|
216
|
-
<LocationChanged onChanged={digg(this, "onLocationChanged")} />
|
|
217
|
-
{models && models.map((model) =>
|
|
218
|
-
<React.Fragment key={model.id()}>
|
|
219
|
-
<EventDestroyed model={model} onDestroyed={digg(this, "onModelDestroyed")} />
|
|
220
|
-
<EventUpdated model={model} onUpdated={digg(this, "onModelUpdated")} />
|
|
221
|
-
</React.Fragment>
|
|
222
|
-
)}
|
|
223
|
-
</>
|
|
224
|
-
)
|
|
225
|
-
}
|
|
6
|
+
import PropTypesExact from "prop-types-exact"
|
|
7
|
+
import useCollection from "./use-collection"
|
|
8
|
+
import useShape from "set-state-compare/src/use-shape"
|
|
9
|
+
|
|
10
|
+
const CollectionLoader = ({component, ...restProps}) => {
|
|
11
|
+
const s = useShape(restProps)
|
|
12
|
+
const useCollectionResult = useCollection(restProps)
|
|
13
|
+
const cachePartsKeys = [
|
|
14
|
+
"modelIdsCacheString",
|
|
15
|
+
"overallCount",
|
|
16
|
+
"qParams",
|
|
17
|
+
"queryName",
|
|
18
|
+
"queryPerKey",
|
|
19
|
+
"queryQName",
|
|
20
|
+
"querySName",
|
|
21
|
+
"queryPageName",
|
|
22
|
+
"searchParams",
|
|
23
|
+
"showNoRecordsAvailableContent",
|
|
24
|
+
"showNoRecordsFoundContent"
|
|
25
|
+
]
|
|
26
|
+
const cacheParts = []
|
|
27
|
+
|
|
28
|
+
for(const cachePartsKey of cachePartsKeys) {
|
|
29
|
+
cacheParts.push(digg(useCollectionResult, cachePartsKey))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
s.updateMeta({component, useCollectionResult})
|
|
33
|
+
|
|
34
|
+
useMemo(() => {
|
|
35
|
+
s.m.component.setState(s.m.useCollectionResult)
|
|
36
|
+
}, cacheParts)
|
|
37
|
+
|
|
38
|
+
return null
|
|
226
39
|
}
|
|
40
|
+
|
|
41
|
+
CollectionLoader.propTypes = PropTypesExact({
|
|
42
|
+
abilities: PropTypes.object,
|
|
43
|
+
collection: PropTypes.instanceOf(Collection),
|
|
44
|
+
component: PropTypes.object.isRequired,
|
|
45
|
+
defaultParams: PropTypes.object,
|
|
46
|
+
groupBy: PropTypes.array,
|
|
47
|
+
modelClass: PropTypes.func.isRequired,
|
|
48
|
+
noRecordsAvailableContent: PropTypes.func,
|
|
49
|
+
noRecordsFoundContent: PropTypes.func,
|
|
50
|
+
onModelsLoaded: PropTypes.func,
|
|
51
|
+
pagination: PropTypes.bool,
|
|
52
|
+
preloads: PropTypes.array,
|
|
53
|
+
queryMethod: PropTypes.func,
|
|
54
|
+
queryName: PropTypes.string,
|
|
55
|
+
ransack: PropTypes.object,
|
|
56
|
+
select: PropTypes.object,
|
|
57
|
+
selectColumns: PropTypes.object
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
export default memo(CollectionLoader)
|