@zajno/common 1.6.3 → 2.0.0-beta.2
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.js +1 -1
- package/README.md +6 -1
- package/coverage/clover.xml +344 -1066
- package/coverage/coverage-final.json +31 -45
- package/coverage/lcov-report/__tests__/helpers/expect.ts.html +1 -1
- package/coverage/lcov-report/__tests__/helpers/index.html +1 -1
- package/coverage/lcov-report/__tests__/helpers/main.ts.html +1 -1
- package/coverage/lcov-report/async/arrays.ts.html +1 -1
- package/coverage/lcov-report/async/index.html +36 -21
- package/coverage/lcov-report/async/timeout.ts.html +59 -59
- package/coverage/lcov-report/dates/calc.ts.html +1 -1
- package/coverage/lcov-report/dates/convert.ts.html +1 -1
- package/coverage/lcov-report/dates/datex.ts.html +1 -1
- package/coverage/lcov-report/dates/format.ts.html +1 -1
- package/coverage/lcov-report/dates/index.html +1 -1
- package/coverage/lcov-report/dates/index.ts.html +1 -1
- package/coverage/lcov-report/dates/parse.ts.html +1 -1
- package/coverage/lcov-report/dates/period.ts.html +1 -1
- package/coverage/lcov-report/dates/shift.ts.html +1 -1
- package/coverage/lcov-report/dates/types.ts.html +1 -1
- package/coverage/lcov-report/dates/yearDate.ts.html +1 -1
- package/coverage/lcov-report/fields/index.html +1 -1
- package/coverage/lcov-report/fields/update.ts.html +1 -1
- package/coverage/lcov-report/functions/index.html +17 -17
- package/coverage/lcov-report/functions/safeCall.ts.html +13 -13
- package/coverage/lcov-report/index.html +119 -74
- package/coverage/lcov-report/lazy/index.html +1 -1
- package/coverage/lcov-report/lazy/promise.ts.html +1 -1
- package/coverage/lcov-report/lazy/singleton.ts.html +1 -1
- package/coverage/lcov-report/logger/batch.ts.html +1 -1
- package/coverage/lcov-report/logger/console.ts.html +1 -1
- package/coverage/lcov-report/logger/index.html +1 -1
- package/coverage/lcov-report/logger/index.ts.html +1 -1
- package/coverage/lcov-report/logger/named.ts.html +1 -1
- package/coverage/lcov-report/logger/proxy.ts.html +1 -1
- package/coverage/lcov-report/math/arrays.ts.html +1 -1
- package/coverage/lcov-report/math/calc.ts.html +1 -1
- package/coverage/lcov-report/math/distribution.ts.html +1 -1
- package/coverage/lcov-report/math/index.html +1 -1
- package/coverage/lcov-report/math/index.ts.html +1 -1
- package/coverage/lcov-report/observing/event.ts.html +1 -1
- package/coverage/lcov-report/observing/index.html +1 -1
- package/coverage/lcov-report/structures/helpers/enum.ts.html +1 -1
- package/coverage/lcov-report/structures/helpers/index.html +1 -1
- package/coverage/lcov-report/structures/index.html +1 -1
- package/coverage/lcov-report/structures/queue/index.html +24 -9
- package/coverage/lcov-report/structures/queue/parallel.ts.html +1 -1
- package/coverage/lcov-report/structures/queue/tasks.ts.html +358 -0
- package/coverage/lcov-report/structures/tempoCache.ts.html +1 -1
- package/coverage/lcov-report/types/comparator.ts.html +1 -1
- package/coverage/lcov-report/types/getter.ts.html +1 -1
- package/coverage/lcov-report/types/index.html +1 -1
- package/coverage/lcov-report/types/index.ts.html +1 -1
- package/coverage/lcov-report/validation/ValidationErrors.ts.html +1 -1
- package/coverage/lcov-report/validation/creditCard.ts.html +1 -1
- package/coverage/lcov-report/validation/helpers.ts.html +1 -1
- package/coverage/lcov-report/validation/index.html +1 -1
- package/coverage/lcov-report/validation/index.ts.html +1 -1
- package/coverage/lcov-report/validation/types.ts.html +1 -1
- package/coverage/lcov-report/validation/validators.ts.html +1 -1
- package/coverage/lcov-report/validation/wrappers.ts.html +1 -1
- package/coverage/lcov.info +863 -2381
- package/lib/fields/update.js +3 -3
- package/lib/fields/update.js.map +1 -1
- package/lib/{assert.d.ts → functions/assert.d.ts} +1 -1
- package/lib/functions/assert.d.ts.map +1 -0
- package/lib/{assert.js → functions/assert.js} +2 -2
- package/lib/functions/assert.js.map +1 -0
- package/lib/{disposer.d.ts → functions/disposer.d.ts} +0 -0
- package/lib/functions/disposer.d.ts.map +1 -0
- package/lib/{disposer.js → functions/disposer.js} +1 -1
- package/lib/functions/disposer.js.map +1 -0
- package/lib/functions/safeCall.d.ts +2 -0
- package/lib/functions/safeCall.d.ts.map +1 -0
- package/lib/{functions.js → functions/safeCall.js} +1 -1
- package/lib/functions/safeCall.js.map +1 -0
- package/lib/{throttle.d.ts → functions/throttle.d.ts} +0 -0
- package/lib/functions/throttle.d.ts.map +1 -0
- package/lib/{throttle.js → functions/throttle.js} +1 -1
- package/lib/functions/throttle.js.map +1 -0
- package/lib/lazy/light.d.ts +1 -1
- package/lib/lazy/light.d.ts.map +1 -1
- package/lib/lazy/promise.d.ts +1 -1
- package/lib/lazy/promise.d.ts.map +1 -1
- package/lib/lazy/singleton.d.ts +1 -1
- package/lib/lazy/singleton.d.ts.map +1 -1
- package/lib/math/arrays.d.ts +1 -0
- package/lib/math/arrays.d.ts.map +1 -1
- package/lib/math/arrays.js +13 -1
- package/lib/math/arrays.js.map +1 -1
- package/lib/{event.d.ts → observing/event.d.ts} +2 -3
- package/lib/observing/event.d.ts.map +1 -0
- package/lib/{event.js → observing/event.js} +2 -3
- package/lib/{event.js.map → observing/event.js.map} +1 -1
- package/lib/{throttledEvent.d.ts → observing/throttledEvent.d.ts} +0 -0
- package/lib/observing/throttledEvent.d.ts.map +1 -0
- package/lib/{throttledEvent.js → observing/throttledEvent.js} +1 -1
- package/lib/observing/throttledEvent.js.map +1 -0
- package/lib/{timer.d.ts → observing/timer.d.ts} +1 -1
- package/lib/observing/timer.d.ts.map +1 -0
- package/lib/{timer.js → observing/timer.js} +0 -0
- package/lib/observing/timer.js.map +1 -0
- package/lib/{abstractions/services/storage.d.ts → storage/abstractions.d.ts} +3 -2
- package/lib/storage/abstractions.d.ts.map +1 -0
- package/lib/{services/localization → storage}/abstractions.js +0 -0
- package/lib/storage/abstractions.js.map +1 -0
- package/lib/storage/asyncWrapper.d.ts +10 -0
- package/lib/storage/asyncWrapper.d.ts.map +1 -0
- package/lib/storage/asyncWrapper.js +24 -0
- package/lib/storage/asyncWrapper.js.map +1 -0
- package/lib/storage/index.d.ts +2 -0
- package/lib/storage/index.d.ts.map +1 -0
- package/lib/storage/index.js +5 -0
- package/lib/storage/index.js.map +1 -0
- package/lib/{services/storage/index.d.ts → storage/keyStorage.d.ts} +2 -10
- package/lib/storage/keyStorage.d.ts.map +1 -0
- package/lib/{services/storage/index.js → storage/keyStorage.js} +2 -22
- package/lib/storage/keyStorage.js.map +1 -0
- package/lib/{enumHelper.d.ts → structures/helpers/enum.d.ts} +1 -1
- package/lib/structures/helpers/enum.d.ts.map +1 -0
- package/lib/{enumHelper.js → structures/helpers/enum.js} +1 -1
- package/lib/structures/helpers/enum.js.map +1 -0
- package/lib/{nameHelper.d.ts → structures/helpers/name.d.ts} +5 -5
- package/lib/structures/helpers/name.d.ts.map +1 -0
- package/lib/{nameHelper.js → structures/helpers/name.js} +7 -6
- package/lib/structures/helpers/name.js.map +1 -0
- package/lib/structures/linkedList.d.ts +39 -0
- package/lib/structures/linkedList.d.ts.map +1 -0
- package/lib/structures/linkedList.js +82 -0
- package/lib/structures/linkedList.js.map +1 -0
- package/lib/{pool.d.ts → structures/pool.d.ts} +1 -1
- package/lib/structures/pool.d.ts.map +1 -0
- package/lib/{pool.js → structures/pool.js} +2 -2
- package/lib/structures/pool.js.map +1 -0
- package/lib/{queue → structures/queue}/parallel.d.ts +3 -3
- package/lib/structures/queue/parallel.d.ts.map +1 -0
- package/lib/{queue → structures/queue}/parallel.js +2 -2
- package/lib/structures/queue/parallel.js.map +1 -0
- package/lib/{queue → structures/queue}/tasks.d.ts +1 -1
- package/lib/structures/queue/tasks.d.ts.map +1 -0
- package/lib/{queue → structures/queue}/tasks.js +0 -0
- package/lib/structures/queue/tasks.js.map +1 -0
- package/lib/{tempoCache.d.ts → structures/tempoCache.d.ts} +0 -0
- package/lib/structures/tempoCache.d.ts.map +1 -0
- package/lib/{tempoCache.js → structures/tempoCache.js} +0 -0
- package/lib/structures/tempoCache.js.map +1 -0
- package/lib/types/comparator.d.ts +5 -0
- package/lib/types/comparator.d.ts.map +1 -0
- package/lib/types/comparator.js +8 -0
- package/lib/types/comparator.js.map +1 -0
- package/lib/types/deep.d.ts +9 -0
- package/lib/types/deep.d.ts.map +1 -0
- package/lib/{viewModels/types.js → types/deep.js} +1 -1
- package/lib/types/deep.js.map +1 -0
- package/lib/types/functions.d.ts +7 -0
- package/lib/types/functions.d.ts.map +1 -0
- package/lib/{abstractions/services/storage.js → types/functions.js} +1 -1
- package/lib/types/functions.js.map +1 -0
- package/lib/types/getter.d.ts +5 -0
- package/lib/types/getter.d.ts.map +1 -0
- package/lib/{types.js → types/getter.js} +2 -6
- package/lib/types/getter.js.map +1 -0
- package/lib/{ident.d.ts → types/ident.d.ts} +0 -0
- package/lib/types/ident.d.ts.map +1 -0
- package/lib/{ident.js → types/ident.js} +0 -0
- package/lib/types/ident.js.map +1 -0
- package/lib/types/index.d.ts +8 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +7 -0
- package/lib/types/index.js.map +1 -0
- package/lib/validation/ValidationErrors.d.ts +1 -1
- package/lib/validation/ValidationErrors.d.ts.map +1 -1
- package/lib/validation/ValidationErrors.js +2 -2
- package/lib/validation/ValidationErrors.js.map +1 -1
- package/lib/{emails.d.ts → validation/emails.d.ts} +0 -0
- package/lib/validation/emails.d.ts.map +1 -0
- package/lib/{emails.js → validation/emails.js} +0 -0
- package/lib/validation/emails.js.map +1 -0
- package/package.json +16 -16
- package/src/async/__tests__/timeout.test.ts +1 -1
- package/src/fields/update.ts +1 -1
- package/src/{assert.ts → functions/assert.ts} +2 -2
- package/src/{disposer.ts → functions/disposer.ts} +1 -1
- package/src/functions/safeCall.ts +6 -0
- package/src/{throttle.ts → functions/throttle.ts} +1 -1
- package/src/lazy/__tests__/lazy.test.ts +1 -48
- package/src/lazy/light.ts +1 -1
- package/src/lazy/promise.ts +1 -1
- package/src/lazy/singleton.ts +1 -1
- package/src/math/arrays.ts +13 -0
- package/src/{event.ts → observing/event.ts} +3 -4
- package/src/{throttledEvent.ts → observing/throttledEvent.ts} +1 -1
- package/src/{timer.ts → observing/timer.ts} +1 -1
- package/src/{abstractions/services/storage.ts → storage/abstractions.ts} +3 -1
- package/src/storage/asyncWrapper.ts +24 -0
- package/src/storage/index.ts +2 -0
- package/src/{services/storage/index.ts → storage/keyStorage.ts} +1 -24
- package/src/{__tests__ → structures/__tests__}/enumHelper.test.ts +1 -1
- package/src/{__tests__ → structures/__tests__}/tempoCache.test.ts +1 -1
- package/src/{enumHelper.ts → structures/helpers/enum.ts} +0 -0
- package/src/{nameHelper.ts → structures/helpers/name.ts} +4 -4
- package/src/structures/linkedList.ts +129 -0
- package/src/{pool.ts → structures/pool.ts} +2 -2
- package/src/{queue → structures/queue}/__tests__/parallel.test.ts +2 -2
- package/src/{queue → structures/queue}/__tests__/tasks.test.ts +2 -2
- package/src/{queue → structures/queue}/parallel.ts +2 -2
- package/src/{queue → structures/queue}/tasks.ts +1 -1
- package/src/{tempoCache.ts → structures/tempoCache.ts} +0 -0
- package/src/types/comparator.ts +6 -0
- package/src/types/deep.ts +18 -0
- package/src/types/functions.ts +8 -0
- package/src/types/getter.ts +14 -0
- package/src/{ident.ts → types/ident.ts} +0 -0
- package/src/types/index.ts +9 -0
- package/src/validation/ValidationErrors.ts +1 -1
- package/src/{emails.ts → validation/emails.ts} +0 -0
- package/tsconfig.build.json +10 -0
- package/tsconfig.json +0 -1
- package/yarn.lock +467 -370
- package/lib/abstractions/services/storage.d.ts.map +0 -1
- package/lib/abstractions/services/storage.js.map +0 -1
- package/lib/assert.d.ts.map +0 -1
- package/lib/assert.js.map +0 -1
- package/lib/cache.d.ts +0 -36
- package/lib/cache.d.ts.map +0 -1
- package/lib/cache.js +0 -165
- package/lib/cache.js.map +0 -1
- package/lib/deepPartial.d.ts +0 -4
- package/lib/deepPartial.d.ts.map +0 -1
- package/lib/deepPartial.js +0 -3
- package/lib/deepPartial.js.map +0 -1
- package/lib/disposer.d.ts.map +0 -1
- package/lib/disposer.js.map +0 -1
- package/lib/emails.d.ts.map +0 -1
- package/lib/emails.js.map +0 -1
- package/lib/enumHelper.d.ts.map +0 -1
- package/lib/enumHelper.js.map +0 -1
- package/lib/event.d.ts.map +0 -1
- package/lib/functions.d.ts +0 -9
- package/lib/functions.d.ts.map +0 -1
- package/lib/functions.js.map +0 -1
- package/lib/ident.d.ts.map +0 -1
- package/lib/ident.js.map +0 -1
- package/lib/lazy/index.d.ts +0 -10
- package/lib/lazy/index.d.ts.map +0 -1
- package/lib/lazy/index.js +0 -23
- package/lib/lazy/index.js.map +0 -1
- package/lib/lazy/observable.d.ts +0 -9
- package/lib/lazy/observable.d.ts.map +0 -1
- package/lib/lazy/observable.js +0 -31
- package/lib/lazy/observable.js.map +0 -1
- package/lib/lazy.light.d.ts +0 -2
- package/lib/lazy.light.d.ts.map +0 -1
- package/lib/lazy.light.js +0 -8
- package/lib/lazy.light.js.map +0 -1
- package/lib/nameHelper.d.ts.map +0 -1
- package/lib/nameHelper.js.map +0 -1
- package/lib/observersMap.d.ts +0 -22
- package/lib/observersMap.d.ts.map +0 -1
- package/lib/observersMap.js +0 -93
- package/lib/observersMap.js.map +0 -1
- package/lib/observingCache.d.ts +0 -32
- package/lib/observingCache.d.ts.map +0 -1
- package/lib/observingCache.js +0 -128
- package/lib/observingCache.js.map +0 -1
- package/lib/pool.d.ts.map +0 -1
- package/lib/pool.js.map +0 -1
- package/lib/queue/parallel.d.ts.map +0 -1
- package/lib/queue/parallel.js.map +0 -1
- package/lib/queue/tasks.d.ts.map +0 -1
- package/lib/queue/tasks.js.map +0 -1
- package/lib/services/localization/LocalaziedValidationErrors.d.ts +0 -9
- package/lib/services/localization/LocalaziedValidationErrors.d.ts.map +0 -1
- package/lib/services/localization/LocalaziedValidationErrors.js +0 -27
- package/lib/services/localization/LocalaziedValidationErrors.js.map +0 -1
- package/lib/services/localization/LocalizationManager.d.ts +0 -18
- package/lib/services/localization/LocalizationManager.d.ts.map +0 -1
- package/lib/services/localization/LocalizationManager.js +0 -58
- package/lib/services/localization/LocalizationManager.js.map +0 -1
- package/lib/services/localization/abstractions.d.ts +0 -12
- package/lib/services/localization/abstractions.d.ts.map +0 -1
- package/lib/services/localization/abstractions.js.map +0 -1
- package/lib/services/localization/defaultShape.d.ts +0 -26
- package/lib/services/localization/defaultShape.d.ts.map +0 -1
- package/lib/services/localization/defaultShape.js +0 -28
- package/lib/services/localization/defaultShape.js.map +0 -1
- package/lib/services/localization/index.d.ts +0 -5
- package/lib/services/localization/index.d.ts.map +0 -1
- package/lib/services/localization/index.js +0 -10
- package/lib/services/localization/index.js.map +0 -1
- package/lib/services/storage/index.d.ts.map +0 -1
- package/lib/services/storage/index.js.map +0 -1
- package/lib/services/storage/web/localStorage.d.ts +0 -13
- package/lib/services/storage/web/localStorage.d.ts.map +0 -1
- package/lib/services/storage/web/localStorage.js +0 -29
- package/lib/services/storage/web/localStorage.js.map +0 -1
- package/lib/services/storage/web/sessionStorage.d.ts +0 -13
- package/lib/services/storage/web/sessionStorage.d.ts.map +0 -1
- package/lib/services/storage/web/sessionStorage.js +0 -29
- package/lib/services/storage/web/sessionStorage.js.map +0 -1
- package/lib/services/storage/web/webStorage.d.ts +0 -9
- package/lib/services/storage/web/webStorage.d.ts.map +0 -1
- package/lib/services/storage/web/webStorage.js +0 -24
- package/lib/services/storage/web/webStorage.js.map +0 -1
- package/lib/tempoCache.d.ts.map +0 -1
- package/lib/tempoCache.js.map +0 -1
- package/lib/throttle.d.ts.map +0 -1
- package/lib/throttle.js.map +0 -1
- package/lib/throttledEvent.d.ts.map +0 -1
- package/lib/throttledEvent.js.map +0 -1
- package/lib/timeHelper.d.ts +0 -7
- package/lib/timeHelper.d.ts.map +0 -1
- package/lib/timeHelper.js +0 -37
- package/lib/timeHelper.js.map +0 -1
- package/lib/timer.d.ts.map +0 -1
- package/lib/timer.js.map +0 -1
- package/lib/transitionObserver.d.ts +0 -36
- package/lib/transitionObserver.d.ts.map +0 -1
- package/lib/transitionObserver.js +0 -153
- package/lib/transitionObserver.js.map +0 -1
- package/lib/types.d.ts +0 -17
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/unsubscriber.d.ts +0 -2
- package/lib/unsubscriber.d.ts.map +0 -1
- package/lib/unsubscriber.js +0 -12
- package/lib/unsubscriber.js.map +0 -1
- package/lib/validation/ValidationErrorsLocalization.d.ts +0 -27
- package/lib/validation/ValidationErrorsLocalization.d.ts.map +0 -1
- package/lib/validation/ValidationErrorsLocalization.js +0 -26
- package/lib/validation/ValidationErrorsLocalization.js.map +0 -1
- package/lib/viewModels/CommonModel.d.ts +0 -13
- package/lib/viewModels/CommonModel.d.ts.map +0 -1
- package/lib/viewModels/CommonModel.js +0 -38
- package/lib/viewModels/CommonModel.js.map +0 -1
- package/lib/viewModels/FlagModel.d.ts +0 -22
- package/lib/viewModels/FlagModel.d.ts.map +0 -1
- package/lib/viewModels/FlagModel.js +0 -52
- package/lib/viewModels/FlagModel.js.map +0 -1
- package/lib/viewModels/InitializableModel.d.ts +0 -6
- package/lib/viewModels/InitializableModel.d.ts.map +0 -1
- package/lib/viewModels/InitializableModel.js +0 -23
- package/lib/viewModels/InitializableModel.js.map +0 -1
- package/lib/viewModels/LoadingModel.d.ts +0 -17
- package/lib/viewModels/LoadingModel.d.ts.map +0 -1
- package/lib/viewModels/LoadingModel.js +0 -42
- package/lib/viewModels/LoadingModel.js.map +0 -1
- package/lib/viewModels/MultiSelectModel.d.ts +0 -47
- package/lib/viewModels/MultiSelectModel.d.ts.map +0 -1
- package/lib/viewModels/MultiSelectModel.js +0 -144
- package/lib/viewModels/MultiSelectModel.js.map +0 -1
- package/lib/viewModels/NumberModel.d.ts +0 -19
- package/lib/viewModels/NumberModel.d.ts.map +0 -1
- package/lib/viewModels/NumberModel.js +0 -38
- package/lib/viewModels/NumberModel.js.map +0 -1
- package/lib/viewModels/PromptModal.d.ts +0 -31
- package/lib/viewModels/PromptModal.d.ts.map +0 -1
- package/lib/viewModels/PromptModal.js +0 -57
- package/lib/viewModels/PromptModal.js.map +0 -1
- package/lib/viewModels/SelectModel.d.ts +0 -35
- package/lib/viewModels/SelectModel.d.ts.map +0 -1
- package/lib/viewModels/SelectModel.js +0 -118
- package/lib/viewModels/SelectModel.js.map +0 -1
- package/lib/viewModels/TextModel.d.ts +0 -41
- package/lib/viewModels/TextModel.d.ts.map +0 -1
- package/lib/viewModels/TextModel.js +0 -98
- package/lib/viewModels/TextModel.js.map +0 -1
- package/lib/viewModels/Validatable.d.ts +0 -26
- package/lib/viewModels/Validatable.d.ts.map +0 -1
- package/lib/viewModels/Validatable.js +0 -81
- package/lib/viewModels/Validatable.js.map +0 -1
- package/lib/viewModels/ValueModel.d.ts +0 -12
- package/lib/viewModels/ValueModel.d.ts.map +0 -1
- package/lib/viewModels/ValueModel.js +0 -29
- package/lib/viewModels/ValueModel.js.map +0 -1
- package/lib/viewModels/ValuesCollector.d.ts +0 -26
- package/lib/viewModels/ValuesCollector.d.ts.map +0 -1
- package/lib/viewModels/ValuesCollector.js +0 -51
- package/lib/viewModels/ValuesCollector.js.map +0 -1
- package/lib/viewModels/index.d.ts +0 -12
- package/lib/viewModels/index.d.ts.map +0 -1
- package/lib/viewModels/index.js +0 -15
- package/lib/viewModels/index.js.map +0 -1
- package/lib/viewModels/types.d.ts +0 -19
- package/lib/viewModels/types.d.ts.map +0 -1
- package/lib/viewModels/types.js.map +0 -1
- package/lib/viewModels/wrappers.d.ts +0 -12
- package/lib/viewModels/wrappers.d.ts.map +0 -1
- package/lib/viewModels/wrappers.js +0 -43
- package/lib/viewModels/wrappers.js.map +0 -1
- package/src/__tests__/observingCache.test.ts +0 -127
- package/src/__tests__/transitionObserver.test.ts +0 -219
- package/src/cache.ts +0 -181
- package/src/deepPartial.ts +0 -4
- package/src/functions.ts +0 -14
- package/src/lazy/index.ts +0 -33
- package/src/lazy/observable.ts +0 -37
- package/src/lazy.light.ts +0 -8
- package/src/observersMap.ts +0 -105
- package/src/observingCache.ts +0 -160
- package/src/services/localization/LocalaziedValidationErrors.ts +0 -18
- package/src/services/localization/LocalizationManager.ts +0 -53
- package/src/services/localization/abstractions.ts +0 -16
- package/src/services/localization/defaultShape.ts +0 -26
- package/src/services/localization/index.ts +0 -6
- package/src/services/storage/web/localStorage.ts +0 -35
- package/src/services/storage/web/sessionStorage.ts +0 -35
- package/src/services/storage/web/webStorage.ts +0 -29
- package/src/timeHelper.ts +0 -39
- package/src/transitionObserver.ts +0 -183
- package/src/types.ts +0 -30
- package/src/unsubscriber.ts +0 -14
- package/src/validation/ValidationErrorsLocalization.ts +0 -27
- package/src/viewModels/CommonModel.ts +0 -45
- package/src/viewModels/FlagModel.ts +0 -70
- package/src/viewModels/InitializableModel.ts +0 -17
- package/src/viewModels/LoadingModel.ts +0 -52
- package/src/viewModels/MultiSelectModel.ts +0 -178
- package/src/viewModels/NumberModel.ts +0 -50
- package/src/viewModels/PromptModal.ts +0 -65
- package/src/viewModels/SelectModel.ts +0 -152
- package/src/viewModels/TextModel.ts +0 -127
- package/src/viewModels/Validatable.ts +0 -102
- package/src/viewModels/ValueModel.ts +0 -34
- package/src/viewModels/ValuesCollector.ts +0 -81
- package/src/viewModels/__tests__/common.test.ts +0 -107
- package/src/viewModels/__tests__/multiSelect.test.ts +0 -138
- package/src/viewModels/__tests__/select.test.ts +0 -71
- package/src/viewModels/__tests__/wrappers.test.ts +0 -79
- package/src/viewModels/index.ts +0 -15
- package/src/viewModels/types.ts +0 -23
- package/src/viewModels/wrappers.ts +0 -49
- package/tsconfig.eslint.json +0 -9
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { observable, makeObservable, reaction, action } from 'mobx';
|
|
2
|
-
import { Getter } from '../types';
|
|
3
|
-
import { IValueModel } from './types';
|
|
4
|
-
import logger from '../logger';
|
|
5
|
-
import { ValidatableModel } from './Validatable';
|
|
6
|
-
import { IResetableModel } from 'viewModels';
|
|
7
|
-
|
|
8
|
-
export type TextInputConfig = {
|
|
9
|
-
name?: Getter<string>;
|
|
10
|
-
title?: Getter<string>;
|
|
11
|
-
value?: Getter<string>;
|
|
12
|
-
async?: boolean;
|
|
13
|
-
|
|
14
|
-
noSubscribe?: boolean;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
function FromGetter(getter: Getter<string>, setter: (val: string) => void, autorunDelay: number = null, noAutorun: boolean = null) {
|
|
18
|
-
if (noAutorun || typeof getter !== 'function') {
|
|
19
|
-
setter(Getter.getValue(getter));
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return reaction(
|
|
24
|
-
() => Getter.getValue(getter),
|
|
25
|
-
setter,
|
|
26
|
-
{ delay: autorunDelay, fireImmediately: true },
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export class Text {
|
|
31
|
-
@observable
|
|
32
|
-
private _value: string = null;
|
|
33
|
-
|
|
34
|
-
constructor(config: { value: Getter<string>, async?: boolean, noSubscribe?: boolean }) {
|
|
35
|
-
makeObservable(this);
|
|
36
|
-
FromGetter(config.value, val => this._value = val, config.async ? 100 : null, config.noSubscribe);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
get value() { return this._value; }
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export class TextInputVM extends ValidatableModel<string> implements IValueModel<string>, IResetableModel {
|
|
43
|
-
// @observable
|
|
44
|
-
private _value = '';
|
|
45
|
-
|
|
46
|
-
// @observable
|
|
47
|
-
private _focused = false;
|
|
48
|
-
|
|
49
|
-
private _name: string = null;
|
|
50
|
-
private _title: string = null;
|
|
51
|
-
|
|
52
|
-
private readonly _valueObserving: () => void = null;
|
|
53
|
-
|
|
54
|
-
constructor(config?: TextInputConfig) {
|
|
55
|
-
super();
|
|
56
|
-
makeObservable<TextInputVM, '_value' | '_focused'>(this, {
|
|
57
|
-
_value: observable,
|
|
58
|
-
_focused: observable,
|
|
59
|
-
setValue: action,
|
|
60
|
-
setFocused: action,
|
|
61
|
-
});
|
|
62
|
-
config = config || {};
|
|
63
|
-
|
|
64
|
-
const delay = config.async ? 100 : null;
|
|
65
|
-
|
|
66
|
-
FromGetter(config.name, val => this._name = val, delay);
|
|
67
|
-
FromGetter(config.title, val => this._title = val, delay);
|
|
68
|
-
this._valueObserving = FromGetter(config.value, val => this._value = val, delay);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
get value() { return this._value; }
|
|
72
|
-
get name() { return this._name; }
|
|
73
|
-
get title() { return this._title; }
|
|
74
|
-
|
|
75
|
-
set value(val) {
|
|
76
|
-
this.setValue(val);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// @action
|
|
80
|
-
public readonly setValue = (value: string) => {
|
|
81
|
-
if (!this._valueObserving) {
|
|
82
|
-
this._value = value;
|
|
83
|
-
|
|
84
|
-
if (this._validateOnChange) {
|
|
85
|
-
this.validate();
|
|
86
|
-
}
|
|
87
|
-
} else {
|
|
88
|
-
logger.warn('[TextInputViewModel] Setting value is not allowed when value is observing');
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
get isEmpty() {
|
|
93
|
-
return !this._value;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
get focused() {
|
|
97
|
-
return this._focused;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
set focused(val: boolean) {
|
|
101
|
-
this.setFocused(val);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// @action
|
|
105
|
-
public readonly setFocused = (value = true) => {
|
|
106
|
-
this._focused = value;
|
|
107
|
-
if (!value) {
|
|
108
|
-
this.onBlur();
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
super.reset();
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
protected get valueToValidate() { return (this.value ?? '').trim(); }
|
|
116
|
-
|
|
117
|
-
private onBlur() {
|
|
118
|
-
this.validate();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
reset = () => {
|
|
122
|
-
this._value = '';
|
|
123
|
-
this._focused = false;
|
|
124
|
-
super.reset();
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { observable, makeObservable, action, runInAction } from 'mobx';
|
|
2
|
-
import { ValidatorFunction, ValidatorFunctionAsync, ValidationErrors, ValidationError } from '../validation';
|
|
3
|
-
import { someAsync } from '../async/arrays';
|
|
4
|
-
|
|
5
|
-
export type ValueValidator<T, TErrors = ValidationErrors> = ValidatorFunction<T, TErrors> | ValidatorFunctionAsync<T, TErrors>;
|
|
6
|
-
export type ValidationErrorsStrings<TErrors extends string | number = number> = Partial<Omit<Record<TErrors, string>, 0 | null>>;
|
|
7
|
-
|
|
8
|
-
export type ValidationConfig<T, TErrors extends string | number = ValidationErrors> = {
|
|
9
|
-
validator: ValueValidator<Readonly<T>, TErrors>,
|
|
10
|
-
errors: ValidationErrorsStrings<TErrors>,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const EmptyValidator = () => 0;
|
|
14
|
-
|
|
15
|
-
export abstract class ValidatableModel<T = string> {
|
|
16
|
-
|
|
17
|
-
private _validator: ValueValidator<T | Readonly<T>, any> = null;
|
|
18
|
-
private _strings: ValidationErrorsStrings<any> = null;
|
|
19
|
-
|
|
20
|
-
// @observable
|
|
21
|
-
private _error: string = null;
|
|
22
|
-
|
|
23
|
-
private _validationError: ValidationError = null;
|
|
24
|
-
protected _validateOnChange = false;
|
|
25
|
-
|
|
26
|
-
constructor() {
|
|
27
|
-
makeObservable<ValidatableModel<T>, '_error'>(this, {
|
|
28
|
-
'_error': observable,
|
|
29
|
-
reset: action,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
protected abstract get valueToValidate(): T | Readonly<T>;
|
|
34
|
-
|
|
35
|
-
get isValid() { return !this._error; }
|
|
36
|
-
|
|
37
|
-
get error() { return this._error; }
|
|
38
|
-
|
|
39
|
-
public setValidationConfig<TErrors extends string | number = ValidationErrors>(config?: ValidationConfig<T, TErrors>) {
|
|
40
|
-
this._validator = config?.validator || EmptyValidator;
|
|
41
|
-
this._strings = config?.errors;
|
|
42
|
-
return this;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public validateOnChange(enable = true) {
|
|
46
|
-
this._validateOnChange = enable;
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public async testValidate(value: T) {
|
|
51
|
-
if (this._validator) {
|
|
52
|
-
const res = await this._validator(value);
|
|
53
|
-
return res;
|
|
54
|
-
}
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async validate() {
|
|
59
|
-
if (!this._validator) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
const validationResult = await this._validator(this.valueToValidate);
|
|
65
|
-
this._validationError = !validationResult
|
|
66
|
-
? null
|
|
67
|
-
: new ValidationError('Unknown error', validationResult);
|
|
68
|
-
} catch (err) {
|
|
69
|
-
this._validationError = err as ValidationError;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
runInAction(() => {
|
|
73
|
-
if (!this._validationError) {
|
|
74
|
-
this._error = null;
|
|
75
|
-
} else {
|
|
76
|
-
const code = this._validationError.code;
|
|
77
|
-
this._error = this._strings && this._strings[code];
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
return this._validationError == null;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
async getIsInvalid() {
|
|
84
|
-
const valid = await this.validate();
|
|
85
|
-
return !valid;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// @action
|
|
89
|
-
reset() {
|
|
90
|
-
this._validationError = null;
|
|
91
|
-
this._error = null;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
static async IsSomeInvalid(validatables: ReadonlyArray<ValidatableModel<any>>, stopOnFail = true) {
|
|
95
|
-
if (stopOnFail) {
|
|
96
|
-
return someAsync(validatables, async v => !(await v.validate()));
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const results = await Promise.all(validatables.map(v => v.validate()));
|
|
100
|
-
return results.some(r => !r);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { action, makeObservable, observable } from 'mobx';
|
|
2
|
-
import { Getter } from '../types';
|
|
3
|
-
import { IValueModel } from './types';
|
|
4
|
-
|
|
5
|
-
export class ValueModel<T> implements IValueModel<T> {
|
|
6
|
-
// observable[.ref]
|
|
7
|
-
private _value: T;
|
|
8
|
-
|
|
9
|
-
private _defaultValue: Getter<T> = null;
|
|
10
|
-
|
|
11
|
-
constructor(v: Getter<T> = null, useRefObservable = true) {
|
|
12
|
-
this._value = Getter.getValue(v) || null;
|
|
13
|
-
this._defaultValue = v;
|
|
14
|
-
|
|
15
|
-
makeObservable<ValueModel<T>, '_value'>(this, {
|
|
16
|
-
_value: useRefObservable ? observable.ref : observable,
|
|
17
|
-
setValue: action,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public get value() { return this._value; }
|
|
22
|
-
public set value(v: T) {
|
|
23
|
-
this.setValue(v);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// action
|
|
27
|
-
public readonly setValue = (value: T) => {
|
|
28
|
-
this._value = value;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
reset = () => {
|
|
32
|
-
this._value = Getter.getValue(this._defaultValue);
|
|
33
|
-
};
|
|
34
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { IValueModel } from './types';
|
|
2
|
-
|
|
3
|
-
export interface IValueCollector<TSource, TValue> {
|
|
4
|
-
getValue(source: TSource): TValue;
|
|
5
|
-
setValue(source: TSource, value: TValue): void;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
type SimpleCollector<T> = {
|
|
9
|
-
get: () => T,
|
|
10
|
-
set: (t: T) => void,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
type SimpleCollectorsMap<T> = {
|
|
14
|
-
[P in keyof T]?: SimpleCollector<T[P]>;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export type ModelCollectorsMap<T> = {
|
|
18
|
-
[P in keyof T]?: IValueModel<T[P]>;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type CollectorsMap<T> = {
|
|
22
|
-
[P in keyof T]?: SimpleCollector<T[P]>;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export class ModelCollector<T extends Object> {
|
|
26
|
-
|
|
27
|
-
private readonly _collectors: SimpleCollectorsMap<T> = { };
|
|
28
|
-
|
|
29
|
-
public addModels(models: ModelCollectorsMap<T>) {
|
|
30
|
-
Object.entries(models).forEach(pair => this.addModel(pair[0] as keyof T, pair[1]));
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public addModel<TKey extends keyof T, TSource extends IValueModel<T[TKey]>>(key: TKey, source: TSource) {
|
|
35
|
-
this._collectors[key] = {
|
|
36
|
-
get: () => source.value,
|
|
37
|
-
set: v => { source.value = v; },
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public addCollector<TKey extends keyof T, TModel, TCollector extends IValueCollector<TModel, T[TKey]>>(key: TKey, model: TModel, collector: TCollector) {
|
|
44
|
-
this._collectors[key] = {
|
|
45
|
-
get: () => collector.getValue(model),
|
|
46
|
-
set: v => collector.setValue(model, v),
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
return this;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public remove(key: keyof T) {
|
|
53
|
-
delete this._collectors[key];
|
|
54
|
-
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public collect(): T {
|
|
59
|
-
const res = { } as T;
|
|
60
|
-
|
|
61
|
-
Object.entries(this._collectors).forEach(pair => {
|
|
62
|
-
const key = pair[0] as keyof T;
|
|
63
|
-
const collector = pair[1] as SimpleCollector<T[keyof T]>;
|
|
64
|
-
res[key] = collector.get();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
return res;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public populate(data: T) {
|
|
71
|
-
Object.entries(data).forEach(pair => {
|
|
72
|
-
const key = pair[0] as keyof T;
|
|
73
|
-
const value = pair[1] as T[keyof T];
|
|
74
|
-
|
|
75
|
-
const collector = this._collectors[key];
|
|
76
|
-
if (collector) {
|
|
77
|
-
collector.set(value);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { ValidationErrors } from '../../validation';
|
|
2
|
-
import { CommonModel } from '../CommonModel';
|
|
3
|
-
import { LoadingModel } from '../LoadingModel';
|
|
4
|
-
import { setTimeoutAsync } from '../../async/timeout';
|
|
5
|
-
import { SelectString } from '../SelectModel';
|
|
6
|
-
import { TextInputVM } from '../TextModel';
|
|
7
|
-
|
|
8
|
-
describe('CommonModel', () => {
|
|
9
|
-
const NotEmptyError = 'should be not empty';
|
|
10
|
-
|
|
11
|
-
it('works', async () => {
|
|
12
|
-
|
|
13
|
-
let m: CommonModel<string[]>;
|
|
14
|
-
|
|
15
|
-
const fn = async () => {
|
|
16
|
-
m = new CommonModel<string[]>(() => [], true)
|
|
17
|
-
.setValidationConfig({
|
|
18
|
-
validator: (v: readonly any[]) => v.length > 0 ? ValidationErrors.None : ValidationErrors.ShouldBeNonEmpty,
|
|
19
|
-
errors: {
|
|
20
|
-
[ValidationErrors.ShouldBeNonEmpty]: NotEmptyError,
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
await expect(fn()).resolves.not.toThrow();
|
|
26
|
-
expect(m).toBeDefined();
|
|
27
|
-
|
|
28
|
-
m.value = ['1'];
|
|
29
|
-
|
|
30
|
-
expect(m.value).toStrictEqual(['1']);
|
|
31
|
-
const valid1 = await m.validate();
|
|
32
|
-
expect(valid1).toBeTruthy();
|
|
33
|
-
|
|
34
|
-
m.reset();
|
|
35
|
-
|
|
36
|
-
expect(m.value).toStrictEqual([]);
|
|
37
|
-
|
|
38
|
-
const valid2 = await m.validate();
|
|
39
|
-
expect(valid2).toBeFalsy();
|
|
40
|
-
|
|
41
|
-
m.reset();
|
|
42
|
-
expect(m.error).toBeFalsy();
|
|
43
|
-
|
|
44
|
-
m.validateOnChange(true);
|
|
45
|
-
m.value = [];
|
|
46
|
-
|
|
47
|
-
// skip one frame
|
|
48
|
-
await Promise.resolve();
|
|
49
|
-
|
|
50
|
-
expect(m.error).toEqual(NotEmptyError);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe('LoadingModel works', () => {
|
|
55
|
-
const worker = async () => {
|
|
56
|
-
await setTimeoutAsync(100);
|
|
57
|
-
return 100;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
it('basic', async () => {
|
|
61
|
-
|
|
62
|
-
const m = new LoadingModel();
|
|
63
|
-
expect(m.value).toBe(false);
|
|
64
|
-
expect(m.isLoading).toBeFalsy();
|
|
65
|
-
|
|
66
|
-
const promise = m.useLoading(worker);
|
|
67
|
-
expect(m.isLoading).toBeTruthy();
|
|
68
|
-
|
|
69
|
-
await promise;
|
|
70
|
-
|
|
71
|
-
expect(m.isLoading).toBeFalsy();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('with exclusive', async () => {
|
|
75
|
-
const m = new LoadingModel();
|
|
76
|
-
|
|
77
|
-
const first = m.useLoading(worker, true);
|
|
78
|
-
expect(m.isLoading).toBeTruthy();
|
|
79
|
-
|
|
80
|
-
const second = m.useLoading(worker, true);
|
|
81
|
-
expect(m.isLoading).toBeTruthy();
|
|
82
|
-
|
|
83
|
-
await expect(() => m.useLoading(worker, 'throw')).rejects.toThrow();
|
|
84
|
-
|
|
85
|
-
expect(m.isLoading).toBeTruthy();
|
|
86
|
-
|
|
87
|
-
await expect(second).resolves.toBe(false);
|
|
88
|
-
await expect(first).resolves.toBe(100);
|
|
89
|
-
|
|
90
|
-
expect(m.value).toBe(false);
|
|
91
|
-
expect(m.isLoading).toBeFalsy();
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe('Others', () => {
|
|
96
|
-
it('has no mobx errors', async () => {
|
|
97
|
-
|
|
98
|
-
await expect((async () => {
|
|
99
|
-
return new SelectString([]);
|
|
100
|
-
})()).resolves.not.toThrow();
|
|
101
|
-
|
|
102
|
-
await expect((async () => {
|
|
103
|
-
return new TextInputVM();
|
|
104
|
-
})()).resolves.not.toThrow();
|
|
105
|
-
|
|
106
|
-
});
|
|
107
|
-
});
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { reaction, toJS } from 'mobx';
|
|
2
|
-
import { arrayRepeat } from '../../math';
|
|
3
|
-
import { MultiSelect, MultiSelectString } from '../MultiSelectModel';
|
|
4
|
-
|
|
5
|
-
type SetType<T> = { items: T[], selected: number[], accessor: (item: T) => string };
|
|
6
|
-
|
|
7
|
-
describe('MultiSelectModel', () => {
|
|
8
|
-
it('creates', () => {
|
|
9
|
-
expect(() => new MultiSelect(null, null).values).toThrow();
|
|
10
|
-
expect(() => new MultiSelect([1], null).values).toThrow();
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
const sets: SetType<any>[] = [
|
|
14
|
-
{ items: [1, 2, 3], selected: [1], accessor: i => `_${i}_` },
|
|
15
|
-
{ items: [1, 2, 3], selected: [], accessor: i => `_${i}_` },
|
|
16
|
-
{ items: ['a', 'b', 'c'], selected: [2], accessor: i => i },
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
describe('consistent', () => {
|
|
20
|
-
sets.forEach((set, setIndex) => {
|
|
21
|
-
it(`variant ${setIndex + 1}`, () => {
|
|
22
|
-
const items = set.items; // [1, 2, 3];
|
|
23
|
-
const accessor = set.accessor; // (i: number) => `_${i}_`;
|
|
24
|
-
const initialSelected = set.selected; // [1];
|
|
25
|
-
const values = items.map(accessor);
|
|
26
|
-
const selectedValues = initialSelected.map(i => accessor(items[i]));
|
|
27
|
-
|
|
28
|
-
const vm = new MultiSelect(items, accessor, ...initialSelected);
|
|
29
|
-
|
|
30
|
-
expect(vm.items).toStrictEqual(items);
|
|
31
|
-
expect(vm.values).toStrictEqual(values);
|
|
32
|
-
expect(vm.count).toBe(items.length);
|
|
33
|
-
expect(vm.selectedCount).toBe(initialSelected.length);
|
|
34
|
-
expect(vm.selectedIndexes).toStrictEqual(initialSelected);
|
|
35
|
-
expect(vm.selectedValues).toStrictEqual(selectedValues);
|
|
36
|
-
|
|
37
|
-
initialSelected.forEach(index => {
|
|
38
|
-
expect(vm.isIndexSelected(index)).toBe(initialSelected.includes(index));
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
values.forEach((value) => {
|
|
42
|
-
expect(vm.isValueSelected(value)).toBe(selectedValues.includes(value));
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('reacts', () => {
|
|
50
|
-
const vm = new MultiSelectString(['a', 'b', 'c']);
|
|
51
|
-
|
|
52
|
-
expect(vm.count).toBe(3);
|
|
53
|
-
expect(vm.selectedCount).toBe(0);
|
|
54
|
-
expect(vm.selectedIndexes).toHaveLength(0);
|
|
55
|
-
|
|
56
|
-
const mocks = arrayRepeat(() => jest.fn().mockImplementation(null), 5);
|
|
57
|
-
const [
|
|
58
|
-
onSelectedIndexes,
|
|
59
|
-
onSelectedItems,
|
|
60
|
-
onSelectedValues,
|
|
61
|
-
onIsIndexSelected,
|
|
62
|
-
onIsValueSelected,
|
|
63
|
-
] = mocks;
|
|
64
|
-
|
|
65
|
-
const wrapMock = mock => ((a: any) => mock(toJS(a)));
|
|
66
|
-
|
|
67
|
-
const expectEmptyCalls = () => {
|
|
68
|
-
expect(onSelectedIndexes).toHaveBeenCalledWith([]);
|
|
69
|
-
expect(onSelectedItems).toHaveBeenCalledWith([]);
|
|
70
|
-
expect(onSelectedValues).toHaveBeenCalledWith([]);
|
|
71
|
-
mocks.forEach(m => m.mockClear());
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
reaction(() => vm.selectedIndexes, wrapMock(onSelectedIndexes));
|
|
75
|
-
reaction(() => vm.selectedItems, wrapMock(onSelectedItems));
|
|
76
|
-
reaction(() => vm.selectedValues, wrapMock(onSelectedValues));
|
|
77
|
-
|
|
78
|
-
// initially – 'false', so expect only when 'true' should be passed
|
|
79
|
-
reaction(() => vm.isIndexSelected(0), wrapMock(onIsIndexSelected));
|
|
80
|
-
reaction(() => vm.isValueSelected('a'), wrapMock(onIsValueSelected));
|
|
81
|
-
|
|
82
|
-
vm.selectIndex(1);
|
|
83
|
-
|
|
84
|
-
expect(onSelectedIndexes).toHaveBeenCalledWith([1]);
|
|
85
|
-
expect(onSelectedItems).toHaveBeenCalledWith(['b']);
|
|
86
|
-
expect(onSelectedValues).toHaveBeenCalledWith(['b']);
|
|
87
|
-
expect(onIsIndexSelected).not.toHaveBeenCalled();
|
|
88
|
-
expect(onIsValueSelected).not.toHaveBeenCalled();
|
|
89
|
-
mocks.forEach(m => m.mockClear());
|
|
90
|
-
|
|
91
|
-
vm.deSelectIndex(1);
|
|
92
|
-
expect(onIsIndexSelected).not.toHaveBeenCalled();
|
|
93
|
-
expect(onIsValueSelected).not.toHaveBeenCalled();
|
|
94
|
-
expectEmptyCalls();
|
|
95
|
-
|
|
96
|
-
vm.selectItem('c');
|
|
97
|
-
|
|
98
|
-
expect(onSelectedIndexes).toHaveBeenCalledWith([2]);
|
|
99
|
-
expect(onSelectedItems).toHaveBeenCalledWith(['c']);
|
|
100
|
-
expect(onSelectedValues).toHaveBeenCalledWith(['c']);
|
|
101
|
-
expect(onIsIndexSelected).not.toHaveBeenCalled();
|
|
102
|
-
expect(onIsValueSelected).not.toHaveBeenCalled();
|
|
103
|
-
mocks.forEach(m => m.mockClear());
|
|
104
|
-
|
|
105
|
-
vm.deSelectItem('c');
|
|
106
|
-
expect(onIsIndexSelected).not.toHaveBeenCalled();
|
|
107
|
-
expect(onIsValueSelected).not.toHaveBeenCalled();
|
|
108
|
-
expectEmptyCalls();
|
|
109
|
-
|
|
110
|
-
vm.selectValue('a');
|
|
111
|
-
|
|
112
|
-
expect(onSelectedIndexes).toHaveBeenCalledWith([0]);
|
|
113
|
-
expect(onSelectedItems).toHaveBeenCalledWith(['a']);
|
|
114
|
-
expect(onSelectedValues).toHaveBeenCalledWith(['a']);
|
|
115
|
-
expect(onIsIndexSelected).toHaveBeenCalledWith(true);
|
|
116
|
-
expect(onIsValueSelected).toHaveBeenCalledWith(true);
|
|
117
|
-
mocks.forEach(m => m.mockClear());
|
|
118
|
-
|
|
119
|
-
vm.deSelectValue('a');
|
|
120
|
-
expect(onIsIndexSelected).toHaveBeenCalledWith(false);
|
|
121
|
-
expect(onIsValueSelected).toHaveBeenCalledWith(false);
|
|
122
|
-
expectEmptyCalls();
|
|
123
|
-
|
|
124
|
-
vm.selectItems(['a', 'b']);
|
|
125
|
-
|
|
126
|
-
expect(onSelectedIndexes).toHaveBeenCalledWith([0, 1]);
|
|
127
|
-
expect(onSelectedItems).toHaveBeenCalledWith(['a', 'b']);
|
|
128
|
-
expect(onSelectedValues).toHaveBeenCalledWith(['a', 'b']);
|
|
129
|
-
expect(onIsIndexSelected).toHaveBeenCalledWith(true);
|
|
130
|
-
expect(onIsValueSelected).toHaveBeenCalledWith(true);
|
|
131
|
-
mocks.forEach(m => m.mockClear());
|
|
132
|
-
|
|
133
|
-
vm.reset();
|
|
134
|
-
expect(onIsIndexSelected).toHaveBeenCalledWith(false);
|
|
135
|
-
expect(onIsValueSelected).toHaveBeenCalledWith(false);
|
|
136
|
-
expectEmptyCalls();
|
|
137
|
-
});
|
|
138
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { configure } from 'mobx';
|
|
2
|
-
import { Select, SelectString } from '../SelectModel';
|
|
3
|
-
|
|
4
|
-
configure({ enforceActions: 'never' });
|
|
5
|
-
|
|
6
|
-
describe('SelectViewModel', () => {
|
|
7
|
-
it('consistent', async () => {
|
|
8
|
-
expect(() => new Select(null, null).values).toThrow();
|
|
9
|
-
expect(() => new Select([1], null).values).toThrow();
|
|
10
|
-
|
|
11
|
-
const emptyVm = new Select([], null);
|
|
12
|
-
expect(emptyVm.selectedValue).toBeNull();
|
|
13
|
-
|
|
14
|
-
const items = [0, 1, 2];
|
|
15
|
-
const values = ['0!', '1!', '2!'];
|
|
16
|
-
const initialIndex = -1;
|
|
17
|
-
const vm = new Select(items, i => `${i}!`, initialIndex);
|
|
18
|
-
|
|
19
|
-
expect(vm.index).toEqual(initialIndex);
|
|
20
|
-
expect(vm.values).toStrictEqual(values);
|
|
21
|
-
expect(vm.items).toStrictEqual(items);
|
|
22
|
-
|
|
23
|
-
expect(vm.selectedItem).toBeUndefined();
|
|
24
|
-
expect(vm.selectedValue).toBeUndefined();
|
|
25
|
-
|
|
26
|
-
vm.selectedItem = 7;
|
|
27
|
-
expect(vm.index).toBe(initialIndex);
|
|
28
|
-
|
|
29
|
-
vm.selectedValue = '123';
|
|
30
|
-
expect(vm.index).toBe(initialIndex);
|
|
31
|
-
|
|
32
|
-
vm.opened.value = true;
|
|
33
|
-
expect(vm.opened.value).toBe(true);
|
|
34
|
-
|
|
35
|
-
vm.index = 1;
|
|
36
|
-
expect(vm.index).toBe(1);
|
|
37
|
-
|
|
38
|
-
expect(vm.flags).toHaveLength(items.length);
|
|
39
|
-
values.forEach((_currentValue, itemIndex) => {
|
|
40
|
-
vm.selectedValue = _currentValue;
|
|
41
|
-
expect(vm.selectedItem).toBe(items[itemIndex]);
|
|
42
|
-
vm.selectedItem = items[itemIndex];
|
|
43
|
-
expect(vm.selectedValue).toBe(_currentValue);
|
|
44
|
-
vm.flags.forEach((f, i) => {
|
|
45
|
-
expect(f.value).toBe(i === itemIndex);
|
|
46
|
-
expect(f.label).toBe(values[i]);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
vm.flags.forEach((f, i) => {
|
|
51
|
-
f.value = true;
|
|
52
|
-
vm.flags.forEach((ff, ii) => {
|
|
53
|
-
expect(ff.value).toBe(i === ii);
|
|
54
|
-
});
|
|
55
|
-
expect(vm.index).toBe(i);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
vm.selectedItem = items[1];
|
|
59
|
-
expect(vm.selectedValue).toBe(values[1]);
|
|
60
|
-
|
|
61
|
-
vm.reset();
|
|
62
|
-
expect(vm.index).toBe(initialIndex);
|
|
63
|
-
|
|
64
|
-
expect(vm.error).toBeNull();
|
|
65
|
-
|
|
66
|
-
await expect(vm.validate()).resolves.toBeTruthy();
|
|
67
|
-
|
|
68
|
-
const vmS = new SelectString(values);
|
|
69
|
-
expect(vmS.values).toStrictEqual(values);
|
|
70
|
-
});
|
|
71
|
-
});
|