@zajno/common 1.3.5 → 1.3.6
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 +46 -3
- package/coverage/coverage-final.json +1 -0
- package/coverage/lcov-report/index.html +24 -9
- 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 +111 -0
- package/coverage/lcov-report/src/{viewModels/SelectViewModel.ts.html → fields/update.ts.html} +118 -178
- package/coverage/lcov-report/src/index.html +1 -1
- 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 +1 -1
- 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-report/update.ts.html +374 -0
- package/coverage/lcov.info +118 -0
- package/lib/fields/update.d.ts +17 -6
- package/lib/fields/update.d.ts.map +1 -1
- package/lib/fields/update.js +29 -13
- package/lib/fields/update.js.map +1 -1
- package/lib/ident.d.ts +6 -0
- package/lib/ident.d.ts.map +1 -0
- package/lib/ident.js +3 -0
- package/lib/ident.js.map +1 -0
- package/package.json +1 -1
- package/src/fields/__tests__/fields.update.test.ts +73 -0
- package/src/fields/update.ts +54 -20
- package/src/ident.ts +8 -0
- package/coverage/lcov-report/src/viewModels/LabeledFlagModel.ts.html +0 -146
- package/coverage/lcov-report/transitionObserver.ts.html +0 -572
- package/yarn-error.log +0 -3709
package/coverage/lcov.info
CHANGED
|
@@ -1340,6 +1340,124 @@ BRF:53
|
|
|
1340
1340
|
BRH:51
|
|
1341
1341
|
end_of_record
|
|
1342
1342
|
TN:
|
|
1343
|
+
SF:src/fields/update.ts
|
|
1344
|
+
FN:11,updateField
|
|
1345
|
+
FN:12,(anonymous_1)
|
|
1346
|
+
FN:12,(anonymous_2)
|
|
1347
|
+
FN:15,updateFieldExtended
|
|
1348
|
+
FN:24,(anonymous_4)
|
|
1349
|
+
FN:38,(anonymous_5)
|
|
1350
|
+
FN:39,(anonymous_6)
|
|
1351
|
+
FN:49,updateArray
|
|
1352
|
+
FN:69,(anonymous_8)
|
|
1353
|
+
FN:78,(anonymous_9)
|
|
1354
|
+
FN:79,(anonymous_10)
|
|
1355
|
+
FNF:11
|
|
1356
|
+
FNH:5
|
|
1357
|
+
FNDA:0,updateField
|
|
1358
|
+
FNDA:0,(anonymous_1)
|
|
1359
|
+
FNDA:0,(anonymous_2)
|
|
1360
|
+
FNDA:0,updateFieldExtended
|
|
1361
|
+
FNDA:0,(anonymous_4)
|
|
1362
|
+
FNDA:38,(anonymous_5)
|
|
1363
|
+
FNDA:0,(anonymous_6)
|
|
1364
|
+
FNDA:6,updateArray
|
|
1365
|
+
FNDA:31,(anonymous_8)
|
|
1366
|
+
FNDA:12,(anonymous_9)
|
|
1367
|
+
FNDA:15,(anonymous_10)
|
|
1368
|
+
DA:11,1
|
|
1369
|
+
DA:12,0
|
|
1370
|
+
DA:15,1
|
|
1371
|
+
DA:24,0
|
|
1372
|
+
DA:26,0
|
|
1373
|
+
DA:28,0
|
|
1374
|
+
DA:29,0
|
|
1375
|
+
DA:30,0
|
|
1376
|
+
DA:31,0
|
|
1377
|
+
DA:34,0
|
|
1378
|
+
DA:38,38
|
|
1379
|
+
DA:39,1
|
|
1380
|
+
DA:49,1
|
|
1381
|
+
DA:54,6
|
|
1382
|
+
DA:55,1
|
|
1383
|
+
DA:58,5
|
|
1384
|
+
DA:59,5
|
|
1385
|
+
DA:63,5
|
|
1386
|
+
DA:64,5
|
|
1387
|
+
DA:67,5
|
|
1388
|
+
DA:68,5
|
|
1389
|
+
DA:69,31
|
|
1390
|
+
DA:70,10
|
|
1391
|
+
DA:71,10
|
|
1392
|
+
DA:72,10
|
|
1393
|
+
DA:78,5
|
|
1394
|
+
DA:79,15
|
|
1395
|
+
DA:80,12
|
|
1396
|
+
DA:81,12
|
|
1397
|
+
DA:82,7
|
|
1398
|
+
DA:83,7
|
|
1399
|
+
DA:84,5
|
|
1400
|
+
DA:85,1
|
|
1401
|
+
DA:89,5
|
|
1402
|
+
DA:90,5
|
|
1403
|
+
DA:91,4
|
|
1404
|
+
DA:94,5
|
|
1405
|
+
LF:37
|
|
1406
|
+
LH:29
|
|
1407
|
+
BRDA:11,0,0,0
|
|
1408
|
+
BRDA:21,1,0,0
|
|
1409
|
+
BRDA:24,2,0,0
|
|
1410
|
+
BRDA:24,2,1,0
|
|
1411
|
+
BRDA:28,3,0,0
|
|
1412
|
+
BRDA:28,3,1,0
|
|
1413
|
+
BRDA:28,4,0,0
|
|
1414
|
+
BRDA:28,4,1,0
|
|
1415
|
+
BRDA:54,5,0,1
|
|
1416
|
+
BRDA:54,5,1,5
|
|
1417
|
+
BRDA:60,6,0,5
|
|
1418
|
+
BRDA:60,6,1,0
|
|
1419
|
+
BRDA:60,7,0,2
|
|
1420
|
+
BRDA:60,7,1,3
|
|
1421
|
+
BRDA:60,8,0,2
|
|
1422
|
+
BRDA:60,8,1,3
|
|
1423
|
+
BRDA:60,9,0,5
|
|
1424
|
+
BRDA:60,9,1,5
|
|
1425
|
+
BRDA:63,10,0,5
|
|
1426
|
+
BRDA:63,10,1,4
|
|
1427
|
+
BRDA:63,11,0,2
|
|
1428
|
+
BRDA:63,11,1,3
|
|
1429
|
+
BRDA:63,12,0,5
|
|
1430
|
+
BRDA:63,12,1,5
|
|
1431
|
+
BRDA:64,13,0,5
|
|
1432
|
+
BRDA:64,13,1,4
|
|
1433
|
+
BRDA:64,14,0,2
|
|
1434
|
+
BRDA:64,14,1,3
|
|
1435
|
+
BRDA:64,15,0,5
|
|
1436
|
+
BRDA:64,15,1,5
|
|
1437
|
+
BRDA:67,16,0,5
|
|
1438
|
+
BRDA:67,16,1,0
|
|
1439
|
+
BRDA:67,17,0,2
|
|
1440
|
+
BRDA:67,17,1,3
|
|
1441
|
+
BRDA:67,18,0,5
|
|
1442
|
+
BRDA:67,18,1,5
|
|
1443
|
+
BRDA:69,19,0,10
|
|
1444
|
+
BRDA:69,19,1,5
|
|
1445
|
+
BRDA:81,20,0,7
|
|
1446
|
+
BRDA:81,20,1,5
|
|
1447
|
+
BRDA:84,21,0,1
|
|
1448
|
+
BRDA:84,21,1,4
|
|
1449
|
+
BRDA:89,22,0,2
|
|
1450
|
+
BRDA:89,22,1,3
|
|
1451
|
+
BRDA:89,23,0,5
|
|
1452
|
+
BRDA:89,23,1,5
|
|
1453
|
+
BRDA:90,24,0,4
|
|
1454
|
+
BRDA:90,24,1,1
|
|
1455
|
+
BRDA:91,25,0,4
|
|
1456
|
+
BRDA:91,25,1,3
|
|
1457
|
+
BRF:50
|
|
1458
|
+
BRH:40
|
|
1459
|
+
end_of_record
|
|
1460
|
+
TN:
|
|
1343
1461
|
SF:src/logger/batch.ts
|
|
1344
1462
|
FN:3,batchLoggers
|
|
1345
1463
|
FN:5,(anonymous_1)
|
package/lib/fields/update.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
export declare
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { Comparator } from '../types';
|
|
2
|
+
export declare namespace Fields {
|
|
3
|
+
type Getter<T> = (obj: Partial<T>) => T[keyof T];
|
|
4
|
+
type Setter<T> = (obj: Partial<T>, val: T[keyof T]) => void;
|
|
5
|
+
type Comparer<T> = (source: Partial<T>, target: Partial<T>) => boolean;
|
|
6
|
+
type Updater<T> = (target: T, source: T) => T;
|
|
7
|
+
}
|
|
8
|
+
export declare function updateField<T>(target: T, source: Partial<T>, diff: Partial<T>, key: keyof T, hasChanged?: Fields.Comparer<T>): boolean;
|
|
9
|
+
export declare function updateFieldExtended<T>(target: T, source: Partial<T>, diff: Partial<T>, get: Fields.Getter<T>, set: Fields.Setter<T>, hasChanged?: Fields.Comparer<T>): boolean;
|
|
10
|
+
export declare type UpdateArrayOptions<T> = {
|
|
11
|
+
additive?: boolean;
|
|
12
|
+
clone?: boolean;
|
|
13
|
+
comparator?: Comparator<T>;
|
|
14
|
+
updater?: Fields.Updater<T>;
|
|
15
|
+
sorter?: Comparator<T, number> | null | undefined;
|
|
16
|
+
};
|
|
17
|
+
export declare function updateArray<T>(target: T[] | null, source: T[], options?: UpdateArrayOptions<T>): {
|
|
7
18
|
changed: number;
|
|
8
19
|
result: T[];
|
|
9
20
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../src/fields/update.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../src/fields/update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,yBAAiB,MAAM,CAAC;IACpB,KAAY,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IACxD,KAAY,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,IAAI,CAAC;IACnE,KAAY,QAAQ,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC;IAC9E,KAAY,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC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16,28 +16,44 @@ function updateFieldExtended(target, source, diff, get, set, hasChanged = null)
|
|
|
16
16
|
return changed;
|
|
17
17
|
}
|
|
18
18
|
exports.updateFieldExtended = updateFieldExtended;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const DefaultComparator = (v1, v2) => v1 === v2;
|
|
20
|
+
const DefaultUpdater = (v1, v2) => Object.assign(v1, v2);
|
|
21
|
+
function updateArray(target, source, options) {
|
|
22
|
+
if (!source) {
|
|
23
|
+
return { changed: 0, result: target };
|
|
22
24
|
}
|
|
23
25
|
let changed = 0;
|
|
24
|
-
const result =
|
|
26
|
+
const result = Array.isArray(target)
|
|
27
|
+
? ((options === null || options === void 0 ? void 0 : options.clone) ? target.slice() : target)
|
|
28
|
+
: [];
|
|
29
|
+
const comparator = (options === null || options === void 0 ? void 0 : options.comparator) || DefaultComparator;
|
|
30
|
+
const updater = (options === null || options === void 0 ? void 0 : options.updater) || DefaultUpdater;
|
|
25
31
|
// remove all missing elements
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
if (!(options === null || options === void 0 ? void 0 : options.additive)) {
|
|
33
|
+
for (let i = 0; i < result.length; ++i) {
|
|
34
|
+
if (source.find(item => comparator(item, result[i])) == null) {
|
|
35
|
+
result.splice(i, 1);
|
|
36
|
+
++changed;
|
|
37
|
+
--i;
|
|
38
|
+
}
|
|
31
39
|
}
|
|
32
40
|
}
|
|
33
|
-
// add all new elements
|
|
34
|
-
|
|
35
|
-
|
|
41
|
+
// add all new elements and update existing
|
|
42
|
+
source.forEach(i => {
|
|
43
|
+
const existingIndex = result.findIndex(item => comparator(i, item));
|
|
44
|
+
const existingItem = result[existingIndex];
|
|
45
|
+
if (existingIndex < 0) {
|
|
36
46
|
result.push(i);
|
|
37
47
|
++changed;
|
|
38
48
|
}
|
|
49
|
+
else if (typeof existingItem === 'object') {
|
|
50
|
+
result[existingIndex] = updater(existingItem, i);
|
|
51
|
+
}
|
|
39
52
|
});
|
|
40
|
-
|
|
53
|
+
const sorter = options === null || options === void 0 ? void 0 : options.sorter;
|
|
54
|
+
if (sorter !== null) {
|
|
55
|
+
result.sort(sorter || undefined);
|
|
56
|
+
}
|
|
41
57
|
return {
|
|
42
58
|
result,
|
|
43
59
|
changed,
|
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":";;;AAUA,SAAgB,WAAW,CAAI,MAAS,EAAE,MAAkB,EAAE,IAAgB,EAAE,GAAY,EAAE,aAAiC,IAAI;IAC/H,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,aAAiC,IAAI;IAGrC,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,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QACvB,GAAG,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jC,eAAe,KAAK,CAAC"}
|
package/lib/ident.js
ADDED
package/lib/ident.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ident.js","sourceRoot":"","sources":["../src/ident.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { updateArray } from '../update';
|
|
2
|
+
|
|
3
|
+
describe('fields/update', () => {
|
|
4
|
+
it('empty input', () => {
|
|
5
|
+
expect(updateArray(null, null)).toStrictEqual({ changed: 0, result: null });
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it('updates primitives | numbers', () => {
|
|
9
|
+
const target = [1, 5, 3];
|
|
10
|
+
const source = [4, 3, 2];
|
|
11
|
+
|
|
12
|
+
const results1 = updateArray(target, source, { clone: true });
|
|
13
|
+
expect(results1.changed).toBe(4);
|
|
14
|
+
expect(results1.result).toStrictEqual([2, 3, 4]);
|
|
15
|
+
|
|
16
|
+
const results2 = updateArray(target, source, { sorter: null });
|
|
17
|
+
expect(results2.changed).toBe(4);
|
|
18
|
+
expect(results2.result).toStrictEqual([3, 4, 2]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('updates primitives | strings', () => {
|
|
22
|
+
const target = ['a', 'b', 'c'];
|
|
23
|
+
const source = ['b', 'c', 'd'];
|
|
24
|
+
|
|
25
|
+
const results = updateArray(target, source);
|
|
26
|
+
|
|
27
|
+
expect(results.changed).toBe(2);
|
|
28
|
+
expect(results.result).toStrictEqual(source);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('updates objects', () => {
|
|
32
|
+
it('no options', () => {
|
|
33
|
+
const res = updateArray([
|
|
34
|
+
{ id: 1, v: 'a' },
|
|
35
|
+
{ id: 5, v: 'e' },
|
|
36
|
+
{ id: 3, v: 'c' },
|
|
37
|
+
], [
|
|
38
|
+
{ id: 2, v: 'b' },
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
expect(res.changed).toBe(4);
|
|
42
|
+
expect(res.result).toStrictEqual([
|
|
43
|
+
{ id: 2, v: 'b' },
|
|
44
|
+
]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// eslint-disable-next-line jest/expect-expect
|
|
48
|
+
it('full options', () => {
|
|
49
|
+
const res = updateArray([
|
|
50
|
+
{ id: 1, v: 'a' },
|
|
51
|
+
{ id: 5, v: 'e' },
|
|
52
|
+
{ id: 3, v: 'c' },
|
|
53
|
+
], [
|
|
54
|
+
{ id: 2, v: 'b' },
|
|
55
|
+
{ id: 1, v: '1K' },
|
|
56
|
+
], {
|
|
57
|
+
clone: true,
|
|
58
|
+
comparator: (v1, v2) => v1.id === v2.id,
|
|
59
|
+
updater: (t, s) => {
|
|
60
|
+
t.v = s.v + '_' + t.id;
|
|
61
|
+
return t;
|
|
62
|
+
},
|
|
63
|
+
sorter: (v1, v2) => v1.id - v2.id,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
expect(res.changed).toBe(3);
|
|
67
|
+
expect(res.result).toStrictEqual([
|
|
68
|
+
{ id: 1, v: '1K_1' },
|
|
69
|
+
{ id: 2, v: 'b' },
|
|
70
|
+
]);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
package/src/fields/update.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import { Comparator } from '../types';
|
|
2
|
+
|
|
3
|
+
export namespace Fields {
|
|
4
|
+
export type Getter<T> = (obj: Partial<T>) => T[keyof T];
|
|
5
|
+
export type Setter<T> = (obj: Partial<T>, val: T[keyof T]) => void;
|
|
6
|
+
export type Comparer<T> = (source: Partial<T>, target: Partial<T>) => boolean;
|
|
7
|
+
export type Updater<T> = (target: T, source: T) => T;
|
|
8
|
+
}
|
|
1
9
|
|
|
2
|
-
export type Getter<T> = (obj: Partial<T>) => T[keyof T];
|
|
3
|
-
export type Setter<T> = (obj: Partial<T>, val: T[keyof T]) => void;
|
|
4
|
-
export type Comparer<T> = (source: Partial<T>, target: Partial<T>) => boolean;
|
|
5
10
|
|
|
6
|
-
export function updateField<T>(target: T, source: Partial<T>, diff: Partial<T>, key: keyof T, hasChanged: Comparer<T> = null): boolean {
|
|
11
|
+
export function updateField<T>(target: T, source: Partial<T>, diff: Partial<T>, key: keyof T, hasChanged: Fields.Comparer<T> = null): boolean {
|
|
7
12
|
return updateFieldExtended(target, source, diff, t => t[key], (t, v) => t[key] = v, hasChanged);
|
|
8
13
|
}
|
|
9
14
|
|
|
@@ -11,9 +16,9 @@ export function updateFieldExtended<T>(
|
|
|
11
16
|
target: T,
|
|
12
17
|
source: Partial<T>,
|
|
13
18
|
diff: Partial<T>,
|
|
14
|
-
get: Getter<T>,
|
|
15
|
-
set: Setter<T>,
|
|
16
|
-
hasChanged: Comparer<T> = null,
|
|
19
|
+
get: Fields.Getter<T>,
|
|
20
|
+
set: Fields.Setter<T>,
|
|
21
|
+
hasChanged: Fields.Comparer<T> = null,
|
|
17
22
|
): boolean {
|
|
18
23
|
|
|
19
24
|
hasChanged = hasChanged || ((v1: T, v2: T) => (get(v1) !== get(v2)));
|
|
@@ -30,32 +35,61 @@ export function updateFieldExtended<T>(
|
|
|
30
35
|
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
const DefaultComparator: Comparator<any> = (v1, v2) => v1 === v2;
|
|
39
|
+
const DefaultUpdater: Fields.Updater<any> = (v1, v2) => Object.assign(v1, v2);
|
|
40
|
+
|
|
41
|
+
export type UpdateArrayOptions<T> = {
|
|
42
|
+
additive?: boolean,
|
|
43
|
+
clone?: boolean,
|
|
44
|
+
comparator?: Comparator<T>,
|
|
45
|
+
updater?: Fields.Updater<T>,
|
|
46
|
+
sorter?: Comparator<T, number> | null | undefined,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export function updateArray<T>(
|
|
50
|
+
target: T[] | null,
|
|
51
|
+
source: T[],
|
|
52
|
+
options?: UpdateArrayOptions<T>,
|
|
53
|
+
): { changed: number, result: T[] } {
|
|
54
|
+
if (!source) {
|
|
55
|
+
return { changed: 0, result: target };
|
|
36
56
|
}
|
|
37
57
|
|
|
38
58
|
let changed = 0;
|
|
39
|
-
const result =
|
|
59
|
+
const result = Array.isArray(target)
|
|
60
|
+
? (options?.clone ? target.slice() : target)
|
|
61
|
+
: [];
|
|
62
|
+
|
|
63
|
+
const comparator = options?.comparator || DefaultComparator;
|
|
64
|
+
const updater = options?.updater || DefaultUpdater;
|
|
40
65
|
|
|
41
66
|
// remove all missing elements
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
67
|
+
if (!options?.additive) {
|
|
68
|
+
for (let i = 0; i < result.length; ++i) {
|
|
69
|
+
if (source.find(item => comparator(item, result[i])) == null) {
|
|
70
|
+
result.splice(i, 1);
|
|
71
|
+
++changed;
|
|
72
|
+
--i;
|
|
73
|
+
}
|
|
47
74
|
}
|
|
48
75
|
}
|
|
49
76
|
|
|
50
|
-
// add all new elements
|
|
51
|
-
|
|
52
|
-
|
|
77
|
+
// add all new elements and update existing
|
|
78
|
+
source.forEach(i => {
|
|
79
|
+
const existingIndex = result.findIndex(item => comparator(i, item));
|
|
80
|
+
const existingItem = result[existingIndex];
|
|
81
|
+
if (existingIndex < 0) {
|
|
53
82
|
result.push(i);
|
|
54
83
|
++changed;
|
|
84
|
+
} else if (typeof existingItem === 'object') {
|
|
85
|
+
result[existingIndex] = updater(existingItem, i);
|
|
55
86
|
}
|
|
56
87
|
});
|
|
57
88
|
|
|
58
|
-
|
|
89
|
+
const sorter = options?.sorter;
|
|
90
|
+
if (sorter !== null) {
|
|
91
|
+
result.sort(sorter || undefined);
|
|
92
|
+
}
|
|
59
93
|
|
|
60
94
|
return {
|
|
61
95
|
result,
|
package/src/ident.ts
ADDED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
<!doctype html>
|
|
3
|
-
<html lang="en">
|
|
4
|
-
|
|
5
|
-
<head>
|
|
6
|
-
<title>Code coverage report for src/viewModels/LabeledFlagModel.ts</title>
|
|
7
|
-
<meta charset="utf-8" />
|
|
8
|
-
<link rel="stylesheet" href="../../prettify.css" />
|
|
9
|
-
<link rel="stylesheet" href="../../base.css" />
|
|
10
|
-
<link rel="shortcut icon" type="image/x-icon" href="../../favicon.png" />
|
|
11
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
12
|
-
<style type='text/css'>
|
|
13
|
-
.coverage-summary .sorter {
|
|
14
|
-
background-image: url(../../sort-arrow-sprite.png);
|
|
15
|
-
}
|
|
16
|
-
</style>
|
|
17
|
-
</head>
|
|
18
|
-
|
|
19
|
-
<body>
|
|
20
|
-
<div class='wrapper'>
|
|
21
|
-
<div class='pad1'>
|
|
22
|
-
<h1><a href="../../index.html">All files</a> / <a href="index.html">src/viewModels</a> LabeledFlagModel.ts</h1>
|
|
23
|
-
<div class='clearfix'>
|
|
24
|
-
|
|
25
|
-
<div class='fl pad1y space-right2'>
|
|
26
|
-
<span class="strong">100% </span>
|
|
27
|
-
<span class="quiet">Statements</span>
|
|
28
|
-
<span class='fraction'>5/5</span>
|
|
29
|
-
</div>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
<div class='fl pad1y space-right2'>
|
|
33
|
-
<span class="strong">100% </span>
|
|
34
|
-
<span class="quiet">Branches</span>
|
|
35
|
-
<span class='fraction'>0/0</span>
|
|
36
|
-
</div>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
<div class='fl pad1y space-right2'>
|
|
40
|
-
<span class="strong">100% </span>
|
|
41
|
-
<span class="quiet">Functions</span>
|
|
42
|
-
<span class='fraction'>2/2</span>
|
|
43
|
-
</div>
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
<div class='fl pad1y space-right2'>
|
|
47
|
-
<span class="strong">100% </span>
|
|
48
|
-
<span class="quiet">Lines</span>
|
|
49
|
-
<span class='fraction'>5/5</span>
|
|
50
|
-
</div>
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
</div>
|
|
54
|
-
<p class="quiet">
|
|
55
|
-
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
|
|
56
|
-
</p>
|
|
57
|
-
</div>
|
|
58
|
-
<div class='status-line high'></div>
|
|
59
|
-
<pre><table class="coverage">
|
|
60
|
-
<tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
|
|
61
|
-
<a name='L2'></a><a href='#L2'>2</a>
|
|
62
|
-
<a name='L3'></a><a href='#L3'>3</a>
|
|
63
|
-
<a name='L4'></a><a href='#L4'>4</a>
|
|
64
|
-
<a name='L5'></a><a href='#L5'>5</a>
|
|
65
|
-
<a name='L6'></a><a href='#L6'>6</a>
|
|
66
|
-
<a name='L7'></a><a href='#L7'>7</a>
|
|
67
|
-
<a name='L8'></a><a href='#L8'>8</a>
|
|
68
|
-
<a name='L9'></a><a href='#L9'>9</a>
|
|
69
|
-
<a name='L10'></a><a href='#L10'>10</a>
|
|
70
|
-
<a name='L11'></a><a href='#L11'>11</a>
|
|
71
|
-
<a name='L12'></a><a href='#L12'>12</a>
|
|
72
|
-
<a name='L13'></a><a href='#L13'>13</a>
|
|
73
|
-
<a name='L14'></a><a href='#L14'>14</a>
|
|
74
|
-
<a name='L15'></a><a href='#L15'>15</a>
|
|
75
|
-
<a name='L16'></a><a href='#L16'>16</a>
|
|
76
|
-
<a name='L17'></a><a href='#L17'>17</a>
|
|
77
|
-
<a name='L18'></a><a href='#L18'>18</a>
|
|
78
|
-
<a name='L19'></a><a href='#L19'>19</a>
|
|
79
|
-
<a name='L20'></a><a href='#L20'>20</a>
|
|
80
|
-
<a name='L21'></a><a href='#L21'>21</a>
|
|
81
|
-
<a name='L22'></a><a href='#L22'>22</a>
|
|
82
|
-
<a name='L23'></a><a href='#L23'>23</a></td><td class="line-coverage quiet"><span class="cline-any cline-yes">1x</span>
|
|
83
|
-
<span class="cline-any cline-neutral"> </span>
|
|
84
|
-
<span class="cline-any cline-neutral"> </span>
|
|
85
|
-
<span class="cline-any cline-neutral"> </span>
|
|
86
|
-
<span class="cline-any cline-neutral"> </span>
|
|
87
|
-
<span class="cline-any cline-neutral"> </span>
|
|
88
|
-
<span class="cline-any cline-neutral"> </span>
|
|
89
|
-
<span class="cline-any cline-neutral"> </span>
|
|
90
|
-
<span class="cline-any cline-neutral"> </span>
|
|
91
|
-
<span class="cline-any cline-neutral"> </span>
|
|
92
|
-
<span class="cline-any cline-yes">1x</span>
|
|
93
|
-
<span class="cline-any cline-neutral"> </span>
|
|
94
|
-
<span class="cline-any cline-neutral"> </span>
|
|
95
|
-
<span class="cline-any cline-neutral"> </span>
|
|
96
|
-
<span class="cline-any cline-yes">3x</span>
|
|
97
|
-
<span class="cline-any cline-yes">3x</span>
|
|
98
|
-
<span class="cline-any cline-neutral"> </span>
|
|
99
|
-
<span class="cline-any cline-neutral"> </span>
|
|
100
|
-
<span class="cline-any cline-neutral"> </span>
|
|
101
|
-
<span class="cline-any cline-yes">9x</span>
|
|
102
|
-
<span class="cline-any cline-neutral"> </span>
|
|
103
|
-
<span class="cline-any cline-neutral"> </span>
|
|
104
|
-
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">import { FlagModel, IFlagModel, IFlagModelReadonly } from './FlagModel';
|
|
105
|
-
|
|
106
|
-
export interface ILabeledFlagModelReadonly<T = string> extends IFlagModelReadonly {
|
|
107
|
-
readonly label: T;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export interface ILabeledFlagModel<T = string> extends IFlagModel {
|
|
111
|
-
readonly label: T;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export class LabeledFlagModel<T = string> extends FlagModel implements ILabeledFlagModelReadonly<T>, ILabeledFlagModel<T> {
|
|
115
|
-
private _label: T;
|
|
116
|
-
|
|
117
|
-
constructor(label: T) {
|
|
118
|
-
super();
|
|
119
|
-
this._label = label;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
get label() {
|
|
123
|
-
return this._label;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
</pre></td></tr></table></pre>
|
|
127
|
-
|
|
128
|
-
<div class='push'></div><!-- for sticky footer -->
|
|
129
|
-
</div><!-- /wrapper -->
|
|
130
|
-
<div class='footer quiet pad2 space-top1 center small'>
|
|
131
|
-
Code coverage generated by
|
|
132
|
-
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
|
133
|
-
at Fri Nov 19 2021 19:36:26 GMT+0000 (Coordinated Universal Time)
|
|
134
|
-
</div>
|
|
135
|
-
</div>
|
|
136
|
-
<script src="../../prettify.js"></script>
|
|
137
|
-
<script>
|
|
138
|
-
window.onload = function () {
|
|
139
|
-
prettyPrint();
|
|
140
|
-
};
|
|
141
|
-
</script>
|
|
142
|
-
<script src="../../sorter.js"></script>
|
|
143
|
-
<script src="../../block-navigation.js"></script>
|
|
144
|
-
</body>
|
|
145
|
-
</html>
|
|
146
|
-
|