@zajno/common 1.4.10 → 1.4.13
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/coverage/clover.xml +457 -374
- package/coverage/coverage-final.json +30 -27
- package/coverage/lcov-report/CommonModel.ts.html +215 -0
- package/coverage/lcov-report/FlagModel.ts.html +290 -0
- package/coverage/lcov-report/MultiSelectModel.ts.html +614 -0
- package/coverage/lcov-report/NumberModel.ts.html +230 -0
- package/coverage/lcov-report/SelectModel.ts.html +503 -0
- package/coverage/lcov-report/Validatable.ts.html +386 -0
- package/coverage/lcov-report/async/index.html +111 -0
- package/coverage/lcov-report/async/timeout.ts.html +230 -0
- package/coverage/lcov-report/index.html +24 -24
- package/coverage/lcov-report/src/__tests__/helpers/index.html +1 -1
- package/coverage/lcov-report/src/__tests__/helpers/main.ts.html +1 -1
- package/coverage/lcov-report/src/async/arrays.ts.html +5 -5
- package/coverage/lcov-report/src/async/index.html +1 -1
- package/coverage/lcov-report/src/async/timeout.ts.html +12 -12
- package/coverage/lcov-report/src/cache.ts.html +1 -1
- package/coverage/lcov-report/src/dates/calc.ts.html +1 -1
- package/coverage/lcov-report/src/dates/convert.ts.html +1 -1
- package/coverage/lcov-report/src/dates/datex.ts.html +1 -1
- package/coverage/lcov-report/src/dates/format.ts.html +1 -1
- package/coverage/lcov-report/src/dates/index.html +1 -1
- package/coverage/lcov-report/src/dates/index.ts.html +1 -1
- package/coverage/lcov-report/src/dates/parse.ts.html +1 -1
- package/coverage/lcov-report/src/dates/period.ts.html +1 -1
- package/coverage/lcov-report/src/dates/shift.ts.html +1 -1
- package/coverage/lcov-report/src/dates/types.ts.html +1 -1
- package/coverage/lcov-report/src/dates/yearDate.ts.html +1 -1
- package/coverage/lcov-report/src/disposer.ts.html +1 -1
- package/coverage/lcov-report/src/enumHelper.ts.html +10 -10
- package/coverage/lcov-report/src/event.ts.html +1 -1
- package/coverage/lcov-report/src/fields/index.html +1 -1
- package/coverage/lcov-report/src/fields/update.ts.html +1 -1
- package/coverage/lcov-report/src/functions.ts.html +1 -1
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/lazy.light.ts.html +6 -6
- package/coverage/lcov-report/src/logger/batch.ts.html +2 -2
- package/coverage/lcov-report/src/logger/console.ts.html +5 -5
- package/coverage/lcov-report/src/logger/index.html +1 -1
- package/coverage/lcov-report/src/logger/index.ts.html +22 -22
- package/coverage/lcov-report/src/logger/named.ts.html +13 -13
- package/coverage/lcov-report/src/logger/proxy.ts.html +7 -7
- package/coverage/lcov-report/src/math/arrays.ts.html +23 -23
- package/coverage/lcov-report/src/math/calc.ts.html +9 -9
- package/coverage/lcov-report/src/math/distribution.ts.html +2 -2
- package/coverage/lcov-report/src/math/index.html +1 -1
- package/coverage/lcov-report/src/math/index.ts.html +6 -6
- package/coverage/lcov-report/src/observersMap.ts.html +1 -1
- package/coverage/lcov-report/src/observingCache.ts.html +1 -1
- package/coverage/lcov-report/src/transitionObserver.ts.html +1 -1
- package/coverage/lcov-report/src/types.ts.html +8 -8
- package/coverage/lcov-report/src/validation/ValidationErrors.ts.html +22 -22
- package/coverage/lcov-report/src/validation/creditCard.ts.html +4 -4
- package/coverage/lcov-report/src/validation/helpers.ts.html +6 -6
- package/coverage/lcov-report/src/validation/index.html +16 -16
- package/coverage/lcov-report/src/validation/index.ts.html +6 -6
- package/coverage/lcov-report/src/validation/types.ts.html +16 -16
- package/coverage/lcov-report/src/validation/validators.ts.html +5 -5
- package/coverage/lcov-report/src/validation/wrappers.ts.html +5 -5
- package/coverage/lcov-report/src/viewModels/CommonModel.ts.html +215 -0
- package/coverage/lcov-report/src/viewModels/FlagModel.ts.html +41 -20
- package/coverage/lcov-report/src/viewModels/LoadingModel.ts.html +128 -0
- package/coverage/lcov-report/src/viewModels/MultiSelectModel.ts.html +50 -20
- package/coverage/lcov-report/src/viewModels/NumberModel.ts.html +41 -23
- package/coverage/lcov-report/src/viewModels/SelectModel.ts.html +42 -30
- package/coverage/lcov-report/src/viewModels/TextModel.ts.html +461 -0
- package/coverage/lcov-report/src/viewModels/Validatable.ts.html +69 -60
- package/coverage/lcov-report/src/viewModels/index.html +84 -39
- package/coverage/lcov-report/src/viewModels/wrappers.ts.html +6 -6
- package/coverage/lcov-report/validation/index.html +111 -0
- package/coverage/lcov-report/validation/index.ts.html +107 -0
- package/coverage/lcov-report/viewModels/CommonModel.ts.html +215 -0
- package/coverage/lcov-report/viewModels/FlagModel.ts.html +290 -0
- package/coverage/lcov-report/viewModels/LoadingModel.ts.html +128 -0
- package/coverage/lcov-report/viewModels/MultiSelectModel.ts.html +614 -0
- package/coverage/lcov-report/viewModels/NumberModel.ts.html +230 -0
- package/coverage/lcov-report/viewModels/SelectModel.ts.html +503 -0
- package/coverage/lcov-report/viewModels/TextModel.ts.html +461 -0
- package/coverage/lcov-report/viewModels/Validatable.ts.html +386 -0
- package/coverage/lcov-report/viewModels/index.html +216 -0
- package/coverage/lcov.info +773 -583
- package/lib/services/localization/LocalizationManager.d.ts +1 -0
- package/lib/services/localization/LocalizationManager.d.ts.map +1 -1
- package/lib/services/localization/LocalizationManager.js +7 -3
- package/lib/services/localization/LocalizationManager.js.map +1 -1
- package/lib/validation/ValidationErrorsLocalization.d.ts +1 -1
- package/lib/validation/ValidationErrorsLocalization.d.ts.map +1 -1
- package/lib/validation/ValidationErrorsLocalization.js +1 -1
- package/lib/validation/ValidationErrorsLocalization.js.map +1 -1
- package/lib/viewModels/FlagModel.d.ts.map +1 -1
- package/lib/viewModels/FlagModel.js +14 -26
- package/lib/viewModels/FlagModel.js.map +1 -1
- package/lib/viewModels/LoadingModel.d.ts +6 -0
- package/lib/viewModels/LoadingModel.d.ts.map +1 -0
- package/lib/viewModels/LoadingModel.js +19 -0
- package/lib/viewModels/LoadingModel.js.map +1 -0
- package/lib/viewModels/MultiSelectModel.d.ts.map +1 -1
- package/lib/viewModels/MultiSelectModel.js +20 -43
- package/lib/viewModels/MultiSelectModel.js.map +1 -1
- package/lib/viewModels/NumberModel.d.ts.map +1 -1
- package/lib/viewModels/NumberModel.js +12 -22
- package/lib/viewModels/NumberModel.js.map +1 -1
- package/lib/viewModels/SelectModel.d.ts.map +1 -1
- package/lib/viewModels/SelectModel.js +8 -15
- package/lib/viewModels/SelectModel.js.map +1 -1
- package/lib/viewModels/TextModel.d.ts.map +1 -1
- package/lib/viewModels/TextModel.js +10 -17
- package/lib/viewModels/TextModel.js.map +1 -1
- package/lib/viewModels/Validatable.d.ts.map +1 -1
- package/lib/viewModels/Validatable.js +6 -12
- package/lib/viewModels/Validatable.js.map +1 -1
- package/package.json +1 -1
- package/src/services/localization/LocalizationManager.ts +8 -3
- package/src/validation/ValidationErrorsLocalization.ts +3 -3
- package/src/viewModels/FlagModel.ts +14 -7
- package/src/viewModels/LoadingModel.ts +16 -0
- package/src/viewModels/MultiSelectModel.ts +20 -10
- package/src/viewModels/NumberModel.ts +12 -6
- package/src/viewModels/SelectModel.ts +8 -4
- package/src/viewModels/TextModel.ts +10 -5
- package/src/viewModels/Validatable.ts +6 -3
- package/src/viewModels/__tests__/common.test.ts +88 -0
- package/yarn.lock +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Validatable.d.ts","sourceRoot":"","sources":["../../src/viewModels/Validatable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,gBAAgB,EAAmB,MAAM,eAAe,CAAC;AAG7G,oBAAY,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,gBAAgB,IAAI,iBAAiB,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,sBAAsB,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;AAC/H,oBAAY,uBAAuB,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;AAEjI,oBA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,CAAC,UAAU,CAA0C;IAC5D,OAAO,CAAC,QAAQ,CAAsC;IAGtD,OAAO,CAAC,MAAM,CAAgB;IAE9B,OAAO,CAAC,gBAAgB,CAAyB;IACjD,SAAS,CAAC,iBAAiB,UAAS;;IASpC,SAAS,CAAC,QAAQ,KAAK,eAAe,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEtD,IAAI,OAAO,YAA2B;IAEtC,IAAI,KAAK,WAA0B;IAE5B,mBAAmB,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,GAAG,gBAAgB,EAAE,MAAM,CAAC,EAAE,gBAAgB,CAAC,CAAC,EAAE,OAAO,CAAC;IAM7G,gBAAgB,CAAC,MAAM,UAAO;IAKxB,YAAY,CAAC,KAAK,EAAE,CAAC;IAQ5B,QAAQ;IAyBR,YAAY;IAMlB,KAAK;WAKQ,aAAa,CAAC,YAAY,EAAE,aAAa,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC,EAAE,UAAU,UAAO;CAQxG"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ValidatableModel = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const mobx_1 = require("mobx");
|
|
6
5
|
const validation_1 = require("../validation");
|
|
7
6
|
const arrays_1 = require("../async/arrays");
|
|
@@ -10,10 +9,14 @@ class ValidatableModel {
|
|
|
10
9
|
constructor() {
|
|
11
10
|
this._validator = null;
|
|
12
11
|
this._strings = null;
|
|
12
|
+
// @observable
|
|
13
13
|
this._error = null;
|
|
14
14
|
this._validationError = null;
|
|
15
15
|
this._validateOnChange = false;
|
|
16
|
-
mobx_1.makeObservable(this
|
|
16
|
+
mobx_1.makeObservable(this, {
|
|
17
|
+
'_error': mobx_1.observable,
|
|
18
|
+
reset: mobx_1.action,
|
|
19
|
+
});
|
|
17
20
|
}
|
|
18
21
|
get isValid() { return !this._error; }
|
|
19
22
|
get error() { return this._error; }
|
|
@@ -61,6 +64,7 @@ class ValidatableModel {
|
|
|
61
64
|
const valid = await this.validate();
|
|
62
65
|
return !valid;
|
|
63
66
|
}
|
|
67
|
+
// @action
|
|
64
68
|
reset() {
|
|
65
69
|
this._validationError = null;
|
|
66
70
|
this._error = null;
|
|
@@ -73,15 +77,5 @@ class ValidatableModel {
|
|
|
73
77
|
return results.some(r => !r);
|
|
74
78
|
}
|
|
75
79
|
}
|
|
76
|
-
tslib_1.__decorate([
|
|
77
|
-
mobx_1.observable,
|
|
78
|
-
tslib_1.__metadata("design:type", String)
|
|
79
|
-
], ValidatableModel.prototype, "_error", void 0);
|
|
80
|
-
tslib_1.__decorate([
|
|
81
|
-
mobx_1.action,
|
|
82
|
-
tslib_1.__metadata("design:type", Function),
|
|
83
|
-
tslib_1.__metadata("design:paramtypes", []),
|
|
84
|
-
tslib_1.__metadata("design:returntype", void 0)
|
|
85
|
-
], ValidatableModel.prototype, "reset", null);
|
|
86
80
|
exports.ValidatableModel = ValidatableModel;
|
|
87
81
|
//# sourceMappingURL=Validatable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Validatable.js","sourceRoot":"","sources":["../../src/viewModels/Validatable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Validatable.js","sourceRoot":"","sources":["../../src/viewModels/Validatable.ts"],"names":[],"mappings":";;;AAAA,+BAAuE;AACvE,8CAA6G;AAC7G,4CAA4C;AAU5C,MAAM,cAAc,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC;AAE/B,MAAsB,gBAAgB;IAWlC;QATQ,eAAU,GAAqC,IAAI,CAAC;QACpD,aAAQ,GAAiC,IAAI,CAAC;QAEtD,cAAc;QACN,WAAM,GAAW,IAAI,CAAC;QAEtB,qBAAgB,GAAoB,IAAI,CAAC;QACvC,sBAAiB,GAAG,KAAK,CAAC;QAGhC,qBAAc,CAAgC,IAAI,EAAE;YAChD,QAAQ,EAAE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C,IAAI,CAAC,gBAAgB,EAAE;gBACxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;aACtB;iBAAM;gBACH,MAAM,IAAI,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC;gBACxC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;aACtD;QACL,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,gBAAgB,IAAI,IAAI,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,YAAY;QACd,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACpC,OAAO,CAAC,KAAK,CAAC;IAClB,CAAC;IAED,UAAU;IACV,KAAK;QACD,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,YAAuD,EAAE,UAAU,GAAG,IAAI;QACjG,IAAI,UAAU,EAAE;YACZ,OAAO,kBAAS,CAAC,YAAY,EAAE,KAAK,EAAC,CAAC,EAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;SACpE;QAED,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QACvE,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,CAAC;CACJ;AAvFD,4CAuFC"}
|
package/package.json
CHANGED
|
@@ -28,20 +28,25 @@ export class LocalizationManager<TLocaleType extends string, TStrings extends {
|
|
|
28
28
|
public useLocale(locale: TLocaleType) {
|
|
29
29
|
this._currentLocale = locale;
|
|
30
30
|
this._currentStrings = this.getStrings(this._currentLocale) || this._defaultStrings;
|
|
31
|
-
this.
|
|
31
|
+
this.updateDependencies();
|
|
32
32
|
return this;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
public useDependency(dep: ILocalizationDependency<TStrings, TLocaleType>, remove = false) {
|
|
36
36
|
const i = this._dependants.indexOf(dep);
|
|
37
|
-
if (i
|
|
37
|
+
if (i < 0 && !remove) {
|
|
38
38
|
this._dependants.push(dep);
|
|
39
|
-
|
|
39
|
+
this.updateDependencies();
|
|
40
|
+
} else if (i >= 0 && remove) {
|
|
40
41
|
this._dependants.splice(i, 1);
|
|
41
42
|
}
|
|
42
43
|
return this;
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
private updateDependencies() {
|
|
47
|
+
this._dependants.forEach(d => d.updateLocale(this._currentStrings, this._currentLocale));
|
|
48
|
+
}
|
|
49
|
+
|
|
45
50
|
private getStrings(locale: string): TStrings {
|
|
46
51
|
return this._dataSource[locale];
|
|
47
52
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ValidationErrorsStrings } from 'services/localization';
|
|
2
|
-
import { StringsShape } from 'services/localization/defaultShape';
|
|
3
|
-
import { LocalaziedValidationErrors } from 'services/localization/LocalaziedValidationErrors';
|
|
1
|
+
import { ValidationErrorsStrings } from '../services/localization';
|
|
2
|
+
import { StringsShape } from '../services/localization/defaultShape';
|
|
3
|
+
import { LocalaziedValidationErrors } from '../services/localization/LocalaziedValidationErrors';
|
|
4
4
|
import { ValidationErrors } from './ValidationErrors';
|
|
5
5
|
|
|
6
6
|
function locationFactory(strings: StringsShape): ValidationErrorsStrings<ValidationErrors> {
|
|
@@ -14,11 +14,18 @@ export type ILabeledFlagModel = IFlagModel & ILabel<string>;
|
|
|
14
14
|
|
|
15
15
|
export class FlagModel implements IFlagModel, IFlagModelReadonly {
|
|
16
16
|
|
|
17
|
-
@observable
|
|
17
|
+
// @observable
|
|
18
18
|
private _value: boolean = false;
|
|
19
19
|
|
|
20
20
|
constructor(initial = false) {
|
|
21
|
-
makeObservable(this
|
|
21
|
+
makeObservable<FlagModel, '_value'>(this, {
|
|
22
|
+
_value: observable,
|
|
23
|
+
setValue: action,
|
|
24
|
+
setTrue: action,
|
|
25
|
+
setFalse: action,
|
|
26
|
+
toggle: action,
|
|
27
|
+
reset: action,
|
|
28
|
+
});
|
|
22
29
|
this._value = initial;
|
|
23
30
|
}
|
|
24
31
|
|
|
@@ -30,33 +37,33 @@ export class FlagModel implements IFlagModel, IFlagModelReadonly {
|
|
|
30
37
|
this.setValue(value);
|
|
31
38
|
}
|
|
32
39
|
|
|
33
|
-
@action
|
|
40
|
+
// @action
|
|
34
41
|
public readonly setValue = (value: boolean) => {
|
|
35
42
|
this._value = value;
|
|
36
43
|
};
|
|
37
44
|
|
|
38
45
|
get isDefault() { return this._value === false; }
|
|
39
46
|
|
|
40
|
-
@action
|
|
47
|
+
// @action
|
|
41
48
|
setTrue = () => {
|
|
42
49
|
const v = this.value;
|
|
43
50
|
this.value = true;
|
|
44
51
|
return !v;
|
|
45
52
|
};
|
|
46
53
|
|
|
47
|
-
@action
|
|
54
|
+
// @action
|
|
48
55
|
setFalse = () => {
|
|
49
56
|
const v = this.value;
|
|
50
57
|
this.value = false;
|
|
51
58
|
return v;
|
|
52
59
|
};
|
|
53
60
|
|
|
54
|
-
@action
|
|
61
|
+
// @action
|
|
55
62
|
toggle = () => {
|
|
56
63
|
this._value = !this._value;
|
|
57
64
|
};
|
|
58
65
|
|
|
59
|
-
@action
|
|
66
|
+
// @action
|
|
60
67
|
reset = () => {
|
|
61
68
|
this._value = false;
|
|
62
69
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NumberModel } from './NumberModel';
|
|
2
|
+
|
|
3
|
+
export class LoadingModel extends NumberModel {
|
|
4
|
+
|
|
5
|
+
public get isLoading() { return this.value > 0; }
|
|
6
|
+
|
|
7
|
+
public async useLoading<T>(cb: () => (T | Promise<T>)): Promise<T> {
|
|
8
|
+
try {
|
|
9
|
+
this.increment();
|
|
10
|
+
const res = await cb();
|
|
11
|
+
return res;
|
|
12
|
+
} finally {
|
|
13
|
+
this.decrement();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -9,7 +9,7 @@ import { arraysCompareDistinct } from '../math';
|
|
|
9
9
|
|
|
10
10
|
export class MultiSelect<T = any> extends ValidatableModel<ReadonlyArray<T>> implements IValueModel<readonly string[]>, IResetableModel, ICountableModel {
|
|
11
11
|
|
|
12
|
-
@observable
|
|
12
|
+
// @observable
|
|
13
13
|
private readonly _indexes = new Set<number>();
|
|
14
14
|
|
|
15
15
|
public readonly opened = new FlagModel();
|
|
@@ -24,29 +24,39 @@ export class MultiSelect<T = any> extends ValidatableModel<ReadonlyArray<T>> imp
|
|
|
24
24
|
...selected: number[]
|
|
25
25
|
) {
|
|
26
26
|
super();
|
|
27
|
-
makeObservable(this
|
|
27
|
+
makeObservable<MultiSelect<T>, '_indexes'>(this, {
|
|
28
|
+
'_indexes': observable,
|
|
29
|
+
selectedIndexes: computed,
|
|
30
|
+
values: computed,
|
|
31
|
+
selectedItems: computed,
|
|
32
|
+
selectedValues: computed,
|
|
33
|
+
isDefault: computed,
|
|
34
|
+
selectItems: action,
|
|
35
|
+
selectValues: action,
|
|
36
|
+
setIndexSelected: action,
|
|
37
|
+
});
|
|
28
38
|
this._initial = selected;
|
|
29
39
|
this.setInitialIndexes();
|
|
30
40
|
}
|
|
31
41
|
|
|
32
|
-
@computed
|
|
42
|
+
// @computed
|
|
33
43
|
get selectedIndexes(): ReadonlyArray<number> { return Array.from(this._indexes); }
|
|
34
44
|
|
|
35
45
|
get items(): ReadonlyArray<T> { return this._items; }
|
|
36
46
|
|
|
37
47
|
get flags() { return this._flags.value; }
|
|
38
48
|
|
|
39
|
-
@computed
|
|
49
|
+
// @computed
|
|
40
50
|
get values(): ReadonlyArray<string> {
|
|
41
51
|
return this._items.map(i => this._accessor(i));
|
|
42
52
|
}
|
|
43
53
|
|
|
44
|
-
@computed
|
|
54
|
+
// @computed
|
|
45
55
|
get selectedItems(): ReadonlyArray<T> {
|
|
46
56
|
return this.selectedIndexes.map(i => this._items[i]);
|
|
47
57
|
}
|
|
48
58
|
|
|
49
|
-
@computed
|
|
59
|
+
// @computed
|
|
50
60
|
get selectedValues(): ReadonlyArray<string> {
|
|
51
61
|
const values = this.values;
|
|
52
62
|
return this.selectedIndexes.map(i => values[i]);
|
|
@@ -62,7 +72,7 @@ export class MultiSelect<T = any> extends ValidatableModel<ReadonlyArray<T>> imp
|
|
|
62
72
|
get selectedCount() { return this._indexes.size; }
|
|
63
73
|
get isEmpty() { return this.selectedCount === 0; }
|
|
64
74
|
|
|
65
|
-
@computed
|
|
75
|
+
// @computed
|
|
66
76
|
get isDefault() { return arraysCompareDistinct(this.selectedIndexes, this._initial)?.diff === 0; }
|
|
67
77
|
|
|
68
78
|
protected get valueToValidate() { return this.selectedItems; }
|
|
@@ -77,7 +87,7 @@ export class MultiSelect<T = any> extends ValidatableModel<ReadonlyArray<T>> imp
|
|
|
77
87
|
selectItem = (item: T) => this.setItemSelected(item, true);
|
|
78
88
|
deSelectItem = (item: T) => this.setItemSelected(item, false);
|
|
79
89
|
|
|
80
|
-
@action
|
|
90
|
+
// @action
|
|
81
91
|
selectItems = (items: readonly T[]) => {
|
|
82
92
|
items.forEach(this.selectItem);
|
|
83
93
|
};
|
|
@@ -92,12 +102,12 @@ export class MultiSelect<T = any> extends ValidatableModel<ReadonlyArray<T>> imp
|
|
|
92
102
|
selectValue = (value: string) => this.setValueSelected(value, true);
|
|
93
103
|
deSelectValue = (value: string) => this.setValueSelected(value, false);
|
|
94
104
|
|
|
95
|
-
@action
|
|
105
|
+
// @action
|
|
96
106
|
selectValues = (values: readonly string[]) => {
|
|
97
107
|
values.forEach(this.selectValue);
|
|
98
108
|
};
|
|
99
109
|
|
|
100
|
-
@action
|
|
110
|
+
// @action
|
|
101
111
|
setIndexSelected = (index: number, selected: boolean) => {
|
|
102
112
|
if (this._indexesLocked) {
|
|
103
113
|
return;
|
|
@@ -8,13 +8,19 @@ export interface INumberModel extends IResetableModel {
|
|
|
8
8
|
|
|
9
9
|
export class NumberModel implements INumberModel, IValueModel<number> {
|
|
10
10
|
|
|
11
|
-
@observable
|
|
11
|
+
// @observable
|
|
12
12
|
private _value: number = 0;
|
|
13
13
|
|
|
14
14
|
private _initial: number = 0;
|
|
15
15
|
|
|
16
16
|
constructor(initial: number = 0) {
|
|
17
|
-
makeObservable(this
|
|
17
|
+
makeObservable<NumberModel, '_value'>(this, {
|
|
18
|
+
_value: observable,
|
|
19
|
+
setValue: action,
|
|
20
|
+
reset: action,
|
|
21
|
+
increment: action,
|
|
22
|
+
decrement: action,
|
|
23
|
+
});
|
|
18
24
|
this._initial = initial;
|
|
19
25
|
this._value = this._initial;
|
|
20
26
|
}
|
|
@@ -22,22 +28,22 @@ export class NumberModel implements INumberModel, IValueModel<number> {
|
|
|
22
28
|
get value() { return this._value; }
|
|
23
29
|
set value(v: number) { this.setValue(v); }
|
|
24
30
|
|
|
25
|
-
@action
|
|
31
|
+
// @action
|
|
26
32
|
public readonly setValue = (v: number) => {
|
|
27
33
|
this._value = v;
|
|
28
34
|
};
|
|
29
35
|
|
|
30
36
|
get isDefault() { return this._value === this._initial; }
|
|
31
37
|
|
|
32
|
-
@action
|
|
38
|
+
// @action
|
|
33
39
|
reset = () => {
|
|
34
40
|
this._value = this._initial;
|
|
35
41
|
};
|
|
36
42
|
|
|
37
|
-
@action
|
|
43
|
+
// @action
|
|
38
44
|
increment = (d = 1) => this.value += d;
|
|
39
45
|
|
|
40
|
-
@action
|
|
46
|
+
// @action
|
|
41
47
|
decrement = (d = 1) => this.value -= d;
|
|
42
48
|
}
|
|
43
49
|
|
|
@@ -7,7 +7,7 @@ import { withLabel } from './wrappers';
|
|
|
7
7
|
import { IResetableModel } from 'viewModels';
|
|
8
8
|
|
|
9
9
|
export class Select<T = any> extends ValidatableModel<T> implements IValueModel<string>, IResetableModel {
|
|
10
|
-
@observable
|
|
10
|
+
// @observable
|
|
11
11
|
private _index: number = undefined;
|
|
12
12
|
|
|
13
13
|
public readonly opened = new FlagModel();
|
|
@@ -22,7 +22,11 @@ export class Select<T = any> extends ValidatableModel<T> implements IValueModel<
|
|
|
22
22
|
initialIndex: number = 0,
|
|
23
23
|
) {
|
|
24
24
|
super();
|
|
25
|
-
makeObservable(this
|
|
25
|
+
makeObservable<Select<T>, '_index'>(this, {
|
|
26
|
+
'_index': observable,
|
|
27
|
+
values: computed,
|
|
28
|
+
setIndex: action,
|
|
29
|
+
});
|
|
26
30
|
|
|
27
31
|
this._initialIndex = initialIndex;
|
|
28
32
|
this._index = initialIndex;
|
|
@@ -30,7 +34,7 @@ export class Select<T = any> extends ValidatableModel<T> implements IValueModel<
|
|
|
30
34
|
|
|
31
35
|
protected get valueToValidate() { return this.selectedItem; }
|
|
32
36
|
|
|
33
|
-
@computed
|
|
37
|
+
// @computed
|
|
34
38
|
get values(): readonly string[] {
|
|
35
39
|
return this._items.map(i => this._accessor(i));
|
|
36
40
|
}
|
|
@@ -78,7 +82,7 @@ export class Select<T = any> extends ValidatableModel<T> implements IValueModel<
|
|
|
78
82
|
this.setIndex(val);
|
|
79
83
|
}
|
|
80
84
|
|
|
81
|
-
@action
|
|
85
|
+
// @action
|
|
82
86
|
public setIndex = (val: number) => {
|
|
83
87
|
if (this._indexLocked) {
|
|
84
88
|
return;
|
|
@@ -40,10 +40,10 @@ export class Text {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export class TextInputVM extends ValidatableModel<string> implements IValueModel<string>, IResetableModel {
|
|
43
|
-
@observable
|
|
43
|
+
// @observable
|
|
44
44
|
private _value = '';
|
|
45
45
|
|
|
46
|
-
@observable
|
|
46
|
+
// @observable
|
|
47
47
|
private _focused = false;
|
|
48
48
|
|
|
49
49
|
private _name: string = null;
|
|
@@ -53,7 +53,12 @@ export class TextInputVM extends ValidatableModel<string> implements IValueModel
|
|
|
53
53
|
|
|
54
54
|
constructor(config?: TextInputConfig) {
|
|
55
55
|
super();
|
|
56
|
-
makeObservable(this
|
|
56
|
+
makeObservable<TextInputVM, '_value' | '_focused'>(this, {
|
|
57
|
+
_value: observable,
|
|
58
|
+
_focused: observable,
|
|
59
|
+
setValue: action,
|
|
60
|
+
setFocused: action,
|
|
61
|
+
});
|
|
57
62
|
config = config || {};
|
|
58
63
|
|
|
59
64
|
const delay = config.async ? 100 : null;
|
|
@@ -71,7 +76,7 @@ export class TextInputVM extends ValidatableModel<string> implements IValueModel
|
|
|
71
76
|
this.setValue(val);
|
|
72
77
|
}
|
|
73
78
|
|
|
74
|
-
@action
|
|
79
|
+
// @action
|
|
75
80
|
public readonly setValue = (value: string) => {
|
|
76
81
|
if (!this._valueObserving) {
|
|
77
82
|
this._value = value;
|
|
@@ -96,7 +101,7 @@ export class TextInputVM extends ValidatableModel<string> implements IValueModel
|
|
|
96
101
|
this.setFocused(val);
|
|
97
102
|
}
|
|
98
103
|
|
|
99
|
-
@action
|
|
104
|
+
// @action
|
|
100
105
|
public readonly setFocused = (value = true) => {
|
|
101
106
|
this._focused = value;
|
|
102
107
|
if (!value) {
|
|
@@ -17,14 +17,17 @@ export abstract class ValidatableModel<T = string> {
|
|
|
17
17
|
private _validator: ValueValidator<Readonly<T>, any> = null;
|
|
18
18
|
private _strings: ValidationErrorsStrings<any> = null;
|
|
19
19
|
|
|
20
|
-
@observable
|
|
20
|
+
// @observable
|
|
21
21
|
private _error: string = null;
|
|
22
22
|
|
|
23
23
|
private _validationError: ValidationError = null;
|
|
24
24
|
protected _validateOnChange = false;
|
|
25
25
|
|
|
26
26
|
constructor() {
|
|
27
|
-
makeObservable(this
|
|
27
|
+
makeObservable<ValidatableModel<T>, '_error'>(this, {
|
|
28
|
+
'_error': observable,
|
|
29
|
+
reset: action,
|
|
30
|
+
});
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
protected abstract get valueToValidate(): Readonly<T>;
|
|
@@ -82,7 +85,7 @@ export abstract class ValidatableModel<T = string> {
|
|
|
82
85
|
return !valid;
|
|
83
86
|
}
|
|
84
87
|
|
|
85
|
-
@action
|
|
88
|
+
// @action
|
|
86
89
|
reset() {
|
|
87
90
|
this._validationError = null;
|
|
88
91
|
this._error = null;
|
|
@@ -0,0 +1,88 @@
|
|
|
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', () => {
|
|
55
|
+
|
|
56
|
+
it('works', async () => {
|
|
57
|
+
|
|
58
|
+
const m = new LoadingModel();
|
|
59
|
+
expect(m.value).toBe(0);
|
|
60
|
+
expect(m.isLoading).toBeFalsy();
|
|
61
|
+
|
|
62
|
+
const worker = async () => {
|
|
63
|
+
await setTimeoutAsync(100);
|
|
64
|
+
return 100;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const promise = m.useLoading(worker);
|
|
68
|
+
expect(m.isLoading).toBeTruthy();
|
|
69
|
+
|
|
70
|
+
await promise;
|
|
71
|
+
|
|
72
|
+
expect(m.isLoading).toBeFalsy();
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('Others', () => {
|
|
77
|
+
it('has no mobx errors', async () => {
|
|
78
|
+
|
|
79
|
+
await expect((async () => {
|
|
80
|
+
return new SelectString([]);
|
|
81
|
+
})()).resolves.not.toThrow();
|
|
82
|
+
|
|
83
|
+
await expect((async () => {
|
|
84
|
+
return new TextInputVM();
|
|
85
|
+
})()).resolves.not.toThrow();
|
|
86
|
+
|
|
87
|
+
});
|
|
88
|
+
});
|
package/yarn.lock
CHANGED
|
@@ -2764,9 +2764,9 @@ mkdirp@^0.5.3:
|
|
|
2764
2764
|
minimist "^1.2.5"
|
|
2765
2765
|
|
|
2766
2766
|
mobx@^6:
|
|
2767
|
-
version "6.
|
|
2768
|
-
resolved "https://registry.yarnpkg.com/mobx/-/mobx-6.
|
|
2769
|
-
integrity sha512-
|
|
2767
|
+
version "6.5.0"
|
|
2768
|
+
resolved "https://registry.yarnpkg.com/mobx/-/mobx-6.5.0.tgz#dc2d028b1882737f6e813fc92454381e438b7ad3"
|
|
2769
|
+
integrity sha512-pHZ/cySF00FVENDWIDzJyoObFahK6Eg4d0papqm6d7yMkxWTZ/S/csqJX1A3PsYy4t5k3z2QnlwuCfMW5lSEwA==
|
|
2770
2770
|
|
|
2771
2771
|
ms@2.1.2:
|
|
2772
2772
|
version "2.1.2"
|