cx 22.4.1 → 22.4.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/dist/data.js +29 -9
- package/dist/manifest.js +335 -335
- package/package.json +1 -1
- package/src/core.d.ts +2 -0
- package/src/data/comparer.spec.js +28 -28
- package/src/data/createAccessorModelProxy.js +29 -7
- package/src/data/createAccessorModelProxy.spec.tsx +16 -2
- package/src/ui/Controller.d.ts +38 -1
package/package.json
CHANGED
package/src/core.d.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import {sorter} from
|
|
2
|
-
import assert from
|
|
1
|
+
import { sorter } from "./comparer";
|
|
2
|
+
import assert from "assert";
|
|
3
3
|
|
|
4
|
-
describe(
|
|
5
|
-
describe(
|
|
6
|
-
it(
|
|
4
|
+
describe("comparer", function () {
|
|
5
|
+
describe("sorter", function () {
|
|
6
|
+
it("orders by numeric values ASC", function () {
|
|
7
7
|
let records = [
|
|
8
|
-
{value: 3, id: 1},
|
|
9
|
-
{value: -1, id: 2},
|
|
10
|
-
{value: 2, id: 3},
|
|
11
|
-
{value: null, id: 4},
|
|
12
|
-
{value: null, id: 5},
|
|
8
|
+
{ value: 3, id: 1 },
|
|
9
|
+
{ value: -1, id: 2 },
|
|
10
|
+
{ value: 2, id: 3 },
|
|
11
|
+
{ value: null, id: 4 },
|
|
12
|
+
{ value: null, id: 5 },
|
|
13
13
|
];
|
|
14
14
|
|
|
15
|
-
let sort = sorter([{value: {bind:
|
|
15
|
+
let sort = sorter([{ value: { bind: "value" }, direction: "ASC" }]);
|
|
16
16
|
|
|
17
17
|
let sorted = sort(records);
|
|
18
18
|
|
|
19
|
-
assert.equal(sorted[0].value,
|
|
20
|
-
assert.equal(sorted[1].value,
|
|
21
|
-
assert.equal(sorted[2].value,
|
|
22
|
-
assert.equal(sorted[3].value,
|
|
23
|
-
assert.equal(sorted[4].value,
|
|
19
|
+
assert.equal(sorted[0].value, -1);
|
|
20
|
+
assert.equal(sorted[1].value, 2);
|
|
21
|
+
assert.equal(sorted[2].value, 3);
|
|
22
|
+
assert.equal(sorted[3].value, null);
|
|
23
|
+
assert.equal(sorted[4].value, null);
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
it(
|
|
26
|
+
it("orders by numeric values DESC", function () {
|
|
27
27
|
let records = [
|
|
28
|
-
{value: 3, id: 1},
|
|
29
|
-
{value: 1, id: 2},
|
|
30
|
-
{value: -2, id: 3},
|
|
31
|
-
{value: null, id: 4},
|
|
32
|
-
{value: null, id: 5},
|
|
28
|
+
{ value: 3, id: 1 },
|
|
29
|
+
{ value: 1, id: 2 },
|
|
30
|
+
{ value: -2, id: 3 },
|
|
31
|
+
{ value: null, id: 4 },
|
|
32
|
+
{ value: null, id: 5 },
|
|
33
33
|
];
|
|
34
34
|
|
|
35
|
-
let sort = sorter([{value: {bind:
|
|
35
|
+
let sort = sorter([{ value: { bind: "value" }, direction: "DESC" }]);
|
|
36
36
|
|
|
37
37
|
let sorted = sort(records);
|
|
38
38
|
|
|
@@ -43,14 +43,14 @@ describe('comparer', function() {
|
|
|
43
43
|
assert.equal(sorted[4].value, null);
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
it(
|
|
46
|
+
it("supports field", function () {
|
|
47
47
|
let records = [
|
|
48
|
-
{value: 3, id: 1},
|
|
49
|
-
{value: 1, id: 2},
|
|
50
|
-
{value: 2, id: 3}
|
|
48
|
+
{ value: 3, id: 1 },
|
|
49
|
+
{ value: 1, id: 2 },
|
|
50
|
+
{ value: 2, id: 3 },
|
|
51
51
|
];
|
|
52
52
|
|
|
53
|
-
let sort = sorter([{field:
|
|
53
|
+
let sort = sorter([{ field: "value", direction: "ASC" }]);
|
|
54
54
|
let sorted = sort(records);
|
|
55
55
|
assert.equal(sorted[0].value, 1);
|
|
56
56
|
assert.equal(sorted[1].value, 2);
|
|
@@ -1,21 +1,43 @@
|
|
|
1
|
+
const emptyFn = () => {};
|
|
2
|
+
|
|
1
3
|
export function createAccessorModelProxy(chain = "") {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
let lastOp = null;
|
|
5
|
+
let lastName = null;
|
|
6
|
+
|
|
7
|
+
const proxy = new Proxy(emptyFn, {
|
|
8
|
+
get: (_, name) => {
|
|
9
|
+
if (typeof name !== "string") return proxy;
|
|
10
|
+
|
|
11
|
+
switch (name) {
|
|
12
|
+
case "isAccessorChain":
|
|
13
|
+
return true;
|
|
14
|
+
|
|
15
|
+
case "toString":
|
|
16
|
+
case "valueOf":
|
|
17
|
+
case "nameOf":
|
|
18
|
+
lastOp = name;
|
|
19
|
+
return proxy;
|
|
20
|
+
}
|
|
7
21
|
|
|
8
22
|
let newChain = chain;
|
|
9
23
|
if (newChain.length > 0) newChain += ".";
|
|
10
24
|
newChain += name;
|
|
25
|
+
lastName = name;
|
|
11
26
|
return createAccessorModelProxy(newChain);
|
|
12
27
|
},
|
|
13
28
|
|
|
14
29
|
apply() {
|
|
15
|
-
|
|
30
|
+
switch (lastOp) {
|
|
31
|
+
case "nameOf":
|
|
32
|
+
if (lastName != null) return lastName;
|
|
33
|
+
const lastDotIndex = chain.lastIndexOf(".");
|
|
34
|
+
return lastDotIndex > 0 ? chain.substring(lastDotIndex + 1) : chain;
|
|
35
|
+
|
|
36
|
+
default:
|
|
37
|
+
return chain;
|
|
38
|
+
}
|
|
16
39
|
},
|
|
17
40
|
});
|
|
18
|
-
proxy.isAccessorChain = true;
|
|
19
41
|
return proxy;
|
|
20
42
|
}
|
|
21
43
|
|
|
@@ -5,19 +5,33 @@ interface Model {
|
|
|
5
5
|
firstName: string;
|
|
6
6
|
address: {
|
|
7
7
|
city: string;
|
|
8
|
+
streetNumber: number;
|
|
8
9
|
};
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
describe("createAccessorModelProxy", () => {
|
|
12
13
|
it("generates correct paths", () => {
|
|
13
|
-
|
|
14
|
+
let model = createAccessorModelProxy<Model>();
|
|
14
15
|
assert.strictEqual(model.firstName.toString(), "firstName");
|
|
15
16
|
assert.strictEqual(model.address.toString(), "address");
|
|
16
17
|
assert.strictEqual(model.address.city.toString(), "address.city");
|
|
17
18
|
});
|
|
18
19
|
|
|
19
20
|
it("can be used in string templates", () => {
|
|
20
|
-
|
|
21
|
+
let model = createAccessorModelProxy<Model>();
|
|
21
22
|
assert.strictEqual("address.city", `${model.address.city}`);
|
|
23
|
+
assert.strictEqual("address.city", "" + model.address.city);
|
|
24
|
+
assert.strictEqual("address.city.suffix", model.address.city + ".suffix");
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("nameOf returns name of the last prop ", () => {
|
|
28
|
+
let model = createAccessorModelProxy<Model>();
|
|
29
|
+
assert.strictEqual(model.firstName.nameOf(), "firstName");
|
|
30
|
+
assert.strictEqual(model.address.nameOf(), "address");
|
|
31
|
+
assert.strictEqual(model.address.city.nameOf(), "city");
|
|
32
|
+
|
|
33
|
+
let { streetNumber, city } = model.address;
|
|
34
|
+
assert.strictEqual(streetNumber.nameOf(), "streetNumber");
|
|
35
|
+
assert.strictEqual(city.nameOf(), "city");
|
|
22
36
|
});
|
|
23
37
|
});
|
package/src/ui/Controller.d.ts
CHANGED
|
@@ -18,6 +18,26 @@ export class Controller<D = any> {
|
|
|
18
18
|
store: View<D>;
|
|
19
19
|
widget: any;
|
|
20
20
|
|
|
21
|
+
addTrigger<V1>(name: string, args: [Cx.AccessorChain<V1>], callback: (v1: V1) => void, autoRun?: boolean): void;
|
|
22
|
+
addTrigger<V1, V2>(
|
|
23
|
+
name: string,
|
|
24
|
+
args: [Cx.AccessorChain<V1>, Cx.AccessorChain<V2>],
|
|
25
|
+
callback: (v1: V1, v2: V2) => void,
|
|
26
|
+
autoRun?: boolean
|
|
27
|
+
): void;
|
|
28
|
+
addTrigger<V1, V2, V3>(
|
|
29
|
+
name: string,
|
|
30
|
+
args: [Cx.AccessorChain<V1>, Cx.AccessorChain<V2>, Cx.AccessorChain<V3>],
|
|
31
|
+
callback: (v1: V1, v2: V2, v3: V3) => void,
|
|
32
|
+
autoRun?: boolean
|
|
33
|
+
): void;
|
|
34
|
+
addTrigger<V1, V2, V3, V4>(
|
|
35
|
+
name: string,
|
|
36
|
+
args: [Cx.AccessorChain<V1>, Cx.AccessorChain<V2>, Cx.AccessorChain<V3>, Cx.AccessorChain<V4>],
|
|
37
|
+
callback: (v1: V1, v2: V2, v3: V3, v4: V4) => void,
|
|
38
|
+
autoRun?: boolean
|
|
39
|
+
): void;
|
|
40
|
+
|
|
21
41
|
addTrigger(
|
|
22
42
|
name: string,
|
|
23
43
|
args: (string | Cx.AccessorChain<any>)[],
|
|
@@ -25,7 +45,24 @@ export class Controller<D = any> {
|
|
|
25
45
|
autoRun?: boolean
|
|
26
46
|
): void;
|
|
27
47
|
|
|
28
|
-
addComputable(
|
|
48
|
+
addComputable<V1, R>(path: Cx.AccessorChain<R>, args: [Cx.AccessorChain<V1>], callback: (v1: V1) => R): void;
|
|
49
|
+
addComputable<V1, V2, R>(
|
|
50
|
+
path: Cx.AccessorChain<R>,
|
|
51
|
+
args: [Cx.AccessorChain<V1>, Cx.AccessorChain<V2>],
|
|
52
|
+
callback: (v1: V1, v2: V2) => R
|
|
53
|
+
): void;
|
|
54
|
+
addComputable<V1, V2, V3, R>(
|
|
55
|
+
path: Cx.AccessorChain<R>,
|
|
56
|
+
args: [Cx.AccessorChain<V1>, Cx.AccessorChain<V2>, Cx.AccessorChain<V3>],
|
|
57
|
+
callback: (v1: V1, v2: V2, v3: V3) => R
|
|
58
|
+
): void;
|
|
59
|
+
addComputable<V1, V2, V3, V4, R>(
|
|
60
|
+
path: Cx.AccessorChain<R>,
|
|
61
|
+
args: [Cx.AccessorChain<V1>, Cx.AccessorChain<V2>, Cx.AccessorChain<V3>, Cx.AccessorChain<V4>],
|
|
62
|
+
callback: (v1: V1, v2: V2, v3: V3, v4: V4) => R
|
|
63
|
+
): void;
|
|
64
|
+
|
|
65
|
+
addComputable(path: string, args: (string | Cx.AccessorChain<any>)[], callback: (...args) => any): void;
|
|
29
66
|
|
|
30
67
|
removeTrigger(name: string): void;
|
|
31
68
|
|