@zajno/common 1.3.9 → 1.3.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 +56 -41
- package/coverage/coverage-final.json +2 -1
- package/coverage/lcov-report/index.html +26 -26
- 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 +1 -1
- package/coverage/lcov-report/src/async/index.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/enumHelper.ts.html +1 -1
- package/coverage/lcov-report/src/event.ts.html +1 -1
- package/coverage/lcov-report/src/fields/index.html +15 -15
- package/coverage/lcov-report/src/fields/update.ts.html +69 -12
- package/coverage/lcov-report/src/functions.ts.html +122 -0
- package/coverage/lcov-report/src/index.html +24 -9
- package/coverage/lcov-report/src/lazy.light.ts.html +1 -1
- package/coverage/lcov-report/src/logger/batch.ts.html +1 -1
- package/coverage/lcov-report/src/logger/console.ts.html +1 -1
- package/coverage/lcov-report/src/logger/index.html +1 -1
- package/coverage/lcov-report/src/logger/index.ts.html +1 -1
- package/coverage/lcov-report/src/logger/named.ts.html +1 -1
- package/coverage/lcov-report/src/logger/proxy.ts.html +1 -1
- package/coverage/lcov-report/src/math/arrays.ts.html +1 -1
- package/coverage/lcov-report/src/math/calc.ts.html +1 -1
- package/coverage/lcov-report/src/math/distribution.ts.html +1 -1
- package/coverage/lcov-report/src/math/index.html +1 -1
- package/coverage/lcov-report/src/math/index.ts.html +1 -1
- package/coverage/lcov-report/src/transitionObserver.ts.html +1 -1
- package/coverage/lcov-report/src/types.ts.html +14 -2
- package/coverage/lcov-report/src/validation/ValidationErrors.ts.html +1 -1
- package/coverage/lcov-report/src/validation/creditCard.ts.html +1 -1
- package/coverage/lcov-report/src/validation/helpers.ts.html +1 -1
- package/coverage/lcov-report/src/validation/index.html +1 -1
- package/coverage/lcov-report/src/validation/index.ts.html +1 -1
- package/coverage/lcov-report/src/validation/types.ts.html +1 -1
- package/coverage/lcov-report/src/validation/validators.ts.html +1 -1
- package/coverage/lcov-report/src/validation/wrappers.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/FlagModel.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/MultiSelectModel.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/NumberModel.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/SelectModel.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/Validatable.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/index.html +1 -1
- package/coverage/lcov-report/src/viewModels/wrappers.ts.html +1 -1
- package/coverage/lcov.info +150 -97
- package/lib/fields/update.d.ts +8 -2
- package/lib/fields/update.d.ts.map +1 -1
- package/lib/fields/update.js +13 -1
- package/lib/fields/update.js.map +1 -1
- package/lib/functions.d.ts +1 -2
- package/lib/functions.d.ts.map +1 -1
- package/lib/functions.js.map +1 -1
- package/lib/types.d.ts +3 -0
- package/lib/types.d.ts.map +1 -1
- package/package.json +5 -3
- package/src/fields/update.ts +22 -3
- package/src/functions.ts +1 -3
- package/src/types.ts +4 -0
- package/tsconfig.json +6 -4
- package/yarn-error.log +3709 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../src/fields/update.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AC,QAAQ,CAAC,CAAC,CAAQ,GAC7C,OAAO,CAcT;AAKD,oBAAY,kBAAkB,CAAC,CAAC,IAAI;IAChC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5B,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IAClD,KAAK,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;CAC/B,CAAC;AAEF,oBAAY,gBAAgB,CAAC,CAAC,IAAI;IAC9B,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;IAC5B,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;IAC9B,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;CAC9C,CAAC;AAEF,wBAAgB,WAAW,CAAC,CAAC,EACzB,MAAM,EAAE,CAAC,EAAE,GAAG,IAAI,EAClB,MAAM,EAAE,CAAC,EAAE,EACX,OAAO,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAChC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,CAAC,EAAE,CAAA;CAAE,CAwDlC"}
|
package/lib/fields/update.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateArray = exports.updateFieldExtended = exports.updateField = void 0;
|
|
4
|
+
const functions_1 = require("../functions");
|
|
4
5
|
function updateField(target, source, diff, key, hasChanged = null) {
|
|
5
6
|
return updateFieldExtended(target, source, diff, t => t[key], (t, v) => t[key] = v, hasChanged);
|
|
6
7
|
}
|
|
@@ -19,6 +20,7 @@ exports.updateFieldExtended = updateFieldExtended;
|
|
|
19
20
|
const DefaultComparator = (v1, v2) => v1 === v2;
|
|
20
21
|
const DefaultUpdater = (v1, v2) => Object.assign(v1, v2);
|
|
21
22
|
function updateArray(target, source, options) {
|
|
23
|
+
var _a, _b, _c;
|
|
22
24
|
if (!source) {
|
|
23
25
|
return { changed: 0, result: target };
|
|
24
26
|
}
|
|
@@ -28,11 +30,16 @@ function updateArray(target, source, options) {
|
|
|
28
30
|
: [];
|
|
29
31
|
const comparator = (options === null || options === void 0 ? void 0 : options.comparator) || DefaultComparator;
|
|
30
32
|
const updater = (options === null || options === void 0 ? void 0 : options.updater) || DefaultUpdater;
|
|
33
|
+
const onDeleted = (_a = options === null || options === void 0 ? void 0 : options.hooks) === null || _a === void 0 ? void 0 : _a.onDeleted;
|
|
34
|
+
const onUpdate = (_b = options === null || options === void 0 ? void 0 : options.hooks) === null || _b === void 0 ? void 0 : _b.onUpdated;
|
|
35
|
+
const onAdded = (_c = options === null || options === void 0 ? void 0 : options.hooks) === null || _c === void 0 ? void 0 : _c.onAdded;
|
|
31
36
|
// remove all missing elements
|
|
32
37
|
if (!(options === null || options === void 0 ? void 0 : options.additive)) {
|
|
33
38
|
for (let i = 0; i < result.length; ++i) {
|
|
34
39
|
if (source.find(item => comparator(item, result[i])) == null) {
|
|
35
|
-
|
|
40
|
+
// DELETE
|
|
41
|
+
const removed = result.splice(i, 1);
|
|
42
|
+
functions_1.safeCall(onDeleted, removed[0]);
|
|
36
43
|
++changed;
|
|
37
44
|
--i;
|
|
38
45
|
}
|
|
@@ -44,10 +51,15 @@ function updateArray(target, source, options) {
|
|
|
44
51
|
const existingItem = result[existingIndex];
|
|
45
52
|
if (existingIndex < 0) {
|
|
46
53
|
result.push(i);
|
|
54
|
+
functions_1.safeCall(onAdded, i);
|
|
47
55
|
++changed;
|
|
48
56
|
}
|
|
49
57
|
else if (typeof existingItem === 'object') {
|
|
58
|
+
const before = onUpdate != null ? { ...existingItem } : undefined;
|
|
50
59
|
result[existingIndex] = updater(existingItem, i);
|
|
60
|
+
if (onUpdate != null) {
|
|
61
|
+
onUpdate(before, result[existingIndex]);
|
|
62
|
+
}
|
|
51
63
|
}
|
|
52
64
|
});
|
|
53
65
|
const sorter = options === null || options === void 0 ? void 0 : options.sorter;
|
package/lib/fields/update.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../src/fields/update.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../src/fields/update.ts"],"names":[],"mappings":";;;AAAA,4CAAwC;AAWxC,SAAgB,WAAW,CAAI,MAAS,EAAE,MAAkB,EAAE,IAAgB,EAAE,GAAY,EAAE,aAAwC,IAAI;IACtI,OAAO,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,CAAC;AACpG,CAAC;AAFD,kCAEC;AAED,SAAgB,mBAAmB,CAC/B,MAAS,EACT,MAAkB,EAClB,IAAgB,EAChB,GAAqB,EACrB,GAAqB,EACrB,aAAwC,IAAI;IAG5C,UAAU,GAAG,UAAU,IAAI,CAAC,CAAC,EAAK,EAAE,EAAK,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAErE,IAAI,OAAO,GAAG,IAAI,CAAC;IAEnB,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,SAAS,IAAI,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;QACzD,OAAO,GAAG,IAAI,CAAC;QACf,GAA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AAC,CAAC;YACjD,IAAI,QAAQ,IAAI,IAAI,EAAE;gBAClB,QAAQ,CAAC,MAAO,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;aAC5C;SACJ;IACL,CAAC,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAC;IAC/B,IAAI,MAAM,KAAK,IAAI,EAAE;QACjB,MAAM,CAAC,IAAI,CAAC,MAAM,IAAI,SAAS,CAAC,CAAC;KACpC;IAED,OAAO;QACH,MAAM;QACN,OAAO;KACV,CAAC;AACN,CAAC;AA5DD,kCA4DC"}
|
package/lib/functions.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ declare type PropertiesOf<T> = Exclude<{
|
|
|
4
4
|
export declare type RemoveFunctionFields<T> = {
|
|
5
5
|
readonly [P in PropertiesOf<T>]: T[P];
|
|
6
6
|
};
|
|
7
|
-
export declare function safeCall<T extends (...args: any) => any>(cb: T, ...args: Parameters<T>): ReturnType<T
|
|
8
|
-
export declare type SortingFunction<T> = (i1: T, i2: T) => number;
|
|
7
|
+
export declare function safeCall<T extends (...args: any) => any>(cb: T | undefined, ...args: Parameters<T>): ReturnType<T> | void;
|
|
9
8
|
export {};
|
|
10
9
|
//# sourceMappingURL=functions.d.ts.map
|
package/lib/functions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"AACA,aAAK,YAAY,CAAC,CAAC,IAAI,OAAO,CAAC;KAC1B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GAAG,KAAK,GAAG,CAAC;CACpD,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;AAEvB,oBAAY,oBAAoB,CAAC,CAAC,IAAI;IAClC,QAAQ,EAAE,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACxC,CAAC;AAEF,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"AACA,aAAK,YAAY,CAAC,CAAC,IAAI,OAAO,CAAC;KAC1B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GAAG,KAAK,GAAG,CAAC;CACpD,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;AAEvB,oBAAY,oBAAoB,CAAC,CAAC,IAAI;IAClC,QAAQ,EAAE,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACxC,CAAC;AAEF,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,SAAS,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAIzH"}
|
package/lib/functions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":";;;AASA,SAAgB,QAAQ,CAAkC,
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":";;;AASA,SAAgB,QAAQ,CAAkC,EAAiB,EAAE,GAAG,IAAmB;IAC/F,IAAI,EAAE,EAAE;QACJ,OAAO,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;KAC/B;AACL,CAAC;AAJD,4BAIC"}
|
package/lib/types.d.ts
CHANGED
|
@@ -11,4 +11,7 @@ export declare type Comparator<T, C = boolean> = (v1: T, v2: T) => C;
|
|
|
11
11
|
export declare namespace Comparator {
|
|
12
12
|
const Default: Comparator<any>;
|
|
13
13
|
}
|
|
14
|
+
export declare type TypedKeys<T extends Object, K> = {
|
|
15
|
+
[P in keyof T]: T[P] extends K ? P : never;
|
|
16
|
+
}[keyof T];
|
|
14
17
|
//# sourceMappingURL=types.d.ts.map
|
package/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,oBAAY,YAAY,CAAC,CAAC,IAAI;IAC1B,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC9C,CAAC;AAEF,oBAAY,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;AAE7C,yBAAiB,MAAM,CAAC;IACpB,SAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAQhD;CACJ;AAED,oBAAY,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC;AACjD,oBAAY,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;AAE7D,yBAAiB,UAAU,CAAC;IACjB,MAAM,OAAO,EAAE,UAAU,CAAC,GAAG,CAAqB,CAAC;CAC7D"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,oBAAY,YAAY,CAAC,CAAC,IAAI;IAC1B,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC9C,CAAC;AAEF,oBAAY,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;AAE7C,yBAAiB,MAAM,CAAC;IACpB,SAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAQhD;CACJ;AAED,oBAAY,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC;AACjD,oBAAY,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;AAE7D,yBAAiB,UAAU,CAAC;IACjB,MAAM,OAAO,EAAE,UAAU,CAAC,GAAG,CAAqB,CAAC;CAC7D;AAED,oBAAY,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,IAAI;KACxC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK;CAC7C,CAAC,MAAM,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zajno/common",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.13",
|
|
4
4
|
"description": "Zajno's re-usable utilities for JS/TS projects",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"homepage": "https://github.com/Zajno/common-utils#readme",
|
|
15
15
|
"scripts": {
|
|
16
|
-
"build": "
|
|
16
|
+
"build": "rimraf ./lib && tsc",
|
|
17
17
|
"build:w": "yarn build --watch",
|
|
18
18
|
"publish:local": "yalc push --replace --update",
|
|
19
19
|
"prepare": "yarn build && yarn lint && yarn test",
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
"lint": "eslint \"src/**/*.ts?(x)\"",
|
|
22
22
|
"test": "yarn jest --clearCache && yarn jest"
|
|
23
23
|
},
|
|
24
|
-
"dependencies": {
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"rimraf": "^3"
|
|
26
|
+
},
|
|
25
27
|
"devDependencies": {
|
|
26
28
|
"@types/faker": "^5.5.9",
|
|
27
29
|
"@types/jest": "^27.0.2",
|
package/src/fields/update.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { safeCall } from '../functions';
|
|
1
2
|
import { Comparator } from '../types';
|
|
2
3
|
|
|
3
4
|
export namespace Fields {
|
|
@@ -8,7 +9,7 @@ export namespace Fields {
|
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
|
|
11
|
-
export function updateField<T>(target: T, source: Partial<T>, diff: Partial<T>, key: keyof T, hasChanged: Fields.Comparer<T> = null): boolean {
|
|
12
|
+
export function updateField<T>(target: T, source: Partial<T>, diff: Partial<T>, key: keyof T, hasChanged: null | Fields.Comparer<T> = null): boolean {
|
|
12
13
|
return updateFieldExtended(target, source, diff, t => t[key], (t, v) => t[key] = v, hasChanged);
|
|
13
14
|
}
|
|
14
15
|
|
|
@@ -18,7 +19,7 @@ export function updateFieldExtended<T>(
|
|
|
18
19
|
diff: Partial<T>,
|
|
19
20
|
get: Fields.Getter<T>,
|
|
20
21
|
set: Fields.Setter<T>,
|
|
21
|
-
hasChanged: Fields.Comparer<T> = null,
|
|
22
|
+
hasChanged: null | Fields.Comparer<T> = null,
|
|
22
23
|
): boolean {
|
|
23
24
|
|
|
24
25
|
hasChanged = hasChanged || ((v1: T, v2: T) => (get(v1) !== get(v2)));
|
|
@@ -44,6 +45,13 @@ export type UpdateArrayOptions<T> = {
|
|
|
44
45
|
comparator?: Comparator<T>,
|
|
45
46
|
updater?: Fields.Updater<T>,
|
|
46
47
|
sorter?: Comparator<T, number> | null | undefined,
|
|
48
|
+
hooks?: UpdateArrayHooks<T>,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type UpdateArrayHooks<T> = {
|
|
52
|
+
onAdded?: (item: T) => void,
|
|
53
|
+
onDeleted?: (item: T) => void,
|
|
54
|
+
onUpdated?: (previous: T, next: T) => void,
|
|
47
55
|
};
|
|
48
56
|
|
|
49
57
|
export function updateArray<T>(
|
|
@@ -62,12 +70,18 @@ export function updateArray<T>(
|
|
|
62
70
|
|
|
63
71
|
const comparator = options?.comparator || DefaultComparator;
|
|
64
72
|
const updater = options?.updater || DefaultUpdater;
|
|
73
|
+
const onDeleted = options?.hooks?.onDeleted;
|
|
74
|
+
const onUpdate = options?.hooks?.onUpdated;
|
|
75
|
+
const onAdded = options?.hooks?.onAdded;
|
|
65
76
|
|
|
66
77
|
// remove all missing elements
|
|
67
78
|
if (!options?.additive) {
|
|
68
79
|
for (let i = 0; i < result.length; ++i) {
|
|
69
80
|
if (source.find(item => comparator(item, result[i])) == null) {
|
|
70
|
-
|
|
81
|
+
// DELETE
|
|
82
|
+
const removed = result.splice(i, 1);
|
|
83
|
+
safeCall(onDeleted, removed[0]);
|
|
84
|
+
|
|
71
85
|
++changed;
|
|
72
86
|
--i;
|
|
73
87
|
}
|
|
@@ -80,9 +94,14 @@ export function updateArray<T>(
|
|
|
80
94
|
const existingItem = result[existingIndex];
|
|
81
95
|
if (existingIndex < 0) {
|
|
82
96
|
result.push(i);
|
|
97
|
+
safeCall(onAdded, i);
|
|
83
98
|
++changed;
|
|
84
99
|
} else if (typeof existingItem === 'object') {
|
|
100
|
+
const before = onUpdate != null ? { ...existingItem } : undefined;
|
|
85
101
|
result[existingIndex] = updater(existingItem, i);
|
|
102
|
+
if (onUpdate != null) {
|
|
103
|
+
onUpdate(before!, result[existingIndex]);
|
|
104
|
+
}
|
|
86
105
|
}
|
|
87
106
|
});
|
|
88
107
|
|
package/src/functions.ts
CHANGED
|
@@ -7,10 +7,8 @@ export type RemoveFunctionFields<T> = {
|
|
|
7
7
|
readonly [P in PropertiesOf<T>]: T[P];
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
export function safeCall<T extends (...args: any) => any>(cb: T, ...args: Parameters<T>): ReturnType<T> {
|
|
10
|
+
export function safeCall<T extends (...args: any) => any>(cb: T | undefined, ...args: Parameters<T>): ReturnType<T> | void {
|
|
11
11
|
if (cb) {
|
|
12
12
|
return cb.apply(null, args);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
export type SortingFunction<T> = (i1: T, i2: T) => number;
|
package/src/types.ts
CHANGED
|
@@ -24,3 +24,7 @@ export type Comparator<T, C = boolean> = (v1: T, v2: T) => C;
|
|
|
24
24
|
export namespace Comparator {
|
|
25
25
|
export const Default: Comparator<any> = (a, b) => a === b;
|
|
26
26
|
}
|
|
27
|
+
|
|
28
|
+
export type TypedKeys<T extends Object, K> = {
|
|
29
|
+
[P in keyof T]: T[P] extends K ? P : never
|
|
30
|
+
}[keyof T];
|
package/tsconfig.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
+
"strict": false,
|
|
4
|
+
"noUnusedLocals": true,
|
|
5
|
+
"strictBindCallApply": true,
|
|
3
6
|
"outDir": "./lib",
|
|
4
|
-
"emitDecoratorMetadata": true,
|
|
5
7
|
"experimentalDecorators": true,
|
|
6
|
-
"
|
|
8
|
+
"emitDecoratorMetadata": true,
|
|
9
|
+
"allowSyntheticDefaultImports": true,
|
|
7
10
|
"skipLibCheck": true,
|
|
8
11
|
"sourceMap": true,
|
|
9
|
-
"allowSyntheticDefaultImports": true,
|
|
10
12
|
"esModuleInterop": true,
|
|
11
13
|
"target": "ES2019",
|
|
12
14
|
"module": "CommonJS",
|
|
@@ -18,7 +20,7 @@
|
|
|
18
20
|
"importHelpers": true,
|
|
19
21
|
"baseUrl": "src",
|
|
20
22
|
"paths": {
|
|
21
|
-
}
|
|
23
|
+
},
|
|
22
24
|
},
|
|
23
25
|
"include": [
|
|
24
26
|
"./src"
|