cx 23.4.1 → 23.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 +2 -7
- package/dist/manifest.js +464 -464
- package/package.json +1 -1
- package/src/data/Binding.js +2 -12
- package/src/data/Binding.spec.js +48 -38
- package/src/data/createAccessorModelProxy.spec.tsx +6 -0
- package/src/widgets/form/Validator.d.ts +5 -3
package/package.json
CHANGED
package/src/data/Binding.js
CHANGED
|
@@ -7,18 +7,8 @@ export class Binding {
|
|
|
7
7
|
constructor(path) {
|
|
8
8
|
this.path = path;
|
|
9
9
|
this.parts = path.split(".");
|
|
10
|
-
let body = "return
|
|
11
|
-
let
|
|
12
|
-
|
|
13
|
-
for (let i = 0; i < this.parts.length; i++) {
|
|
14
|
-
if (this.parts[i][0] >= "0" && this.parts[i][0] <= "9") selector += "[" + this.parts[i] + "]";
|
|
15
|
-
else selector += "." + this.parts[i];
|
|
16
|
-
|
|
17
|
-
if (i + 1 < this.parts.length) body += " && " + selector;
|
|
18
|
-
else body += " ? " + selector + " : undefined";
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
body += ")";
|
|
10
|
+
let body = "return x";
|
|
11
|
+
for (let i = 0; i < this.parts.length; i++) body += '?.["' + this.parts[i] + '"]';
|
|
22
12
|
this.value = new Function("x", body);
|
|
23
13
|
}
|
|
24
14
|
|
package/src/data/Binding.spec.js
CHANGED
|
@@ -1,49 +1,59 @@
|
|
|
1
|
-
import {Binding} from
|
|
2
|
-
import assert from
|
|
3
|
-
|
|
4
|
-
describe(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
});
|
|
12
|
-
});
|
|
1
|
+
import { Binding } from "./Binding";
|
|
2
|
+
import assert from "assert";
|
|
3
|
+
|
|
4
|
+
describe("Binding", function () {
|
|
5
|
+
describe("#get()", function () {
|
|
6
|
+
it("should get value if value is defined", function () {
|
|
7
|
+
var state = { person: { name: "Joe" } };
|
|
8
|
+
var b = Binding.get("person.name");
|
|
9
|
+
assert.equal(b.value(state), "Joe");
|
|
10
|
+
});
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
it("allows non-standard property identifiers", function () {
|
|
13
|
+
var state = { person: { "@schema": "Person" } };
|
|
14
|
+
var b = Binding.get("person.@schema");
|
|
15
|
+
assert.equal(b.value(state), "Person");
|
|
16
|
+
});
|
|
17
|
+
});
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
describe("#set()", function () {
|
|
20
|
+
it("produces new objects along the binding path", function () {
|
|
21
|
+
var state = { person: { name: "Joe" } };
|
|
22
|
+
var b = Binding.get("person.name");
|
|
23
|
+
var ns = b.set(state, "Jack");
|
|
24
|
+
assert.equal(ns.person.name, "Jack");
|
|
25
|
+
assert.notEqual(state, ns);
|
|
26
|
+
assert.notEqual(state.person, ns.person);
|
|
27
|
+
assert.notEqual(state.person.name, ns.person.name);
|
|
28
|
+
});
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
30
|
+
it("returns same state object if value does not change", function () {
|
|
31
|
+
var state = { person: { name: "Joe" } };
|
|
32
|
+
var b = Binding.get("person.name");
|
|
33
|
+
var ns = b.set(state, "Joe");
|
|
34
|
+
assert.equal(state, ns);
|
|
35
|
+
});
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
it("allows non-standard property identifiers", function () {
|
|
38
|
+
var state = { person: { "@schema": "Person" } };
|
|
39
|
+
var b = Binding.get("person.@schema");
|
|
40
|
+
var ns = b.set(state, "Test");
|
|
41
|
+
assert.equal(ns.person["@schema"], "Test");
|
|
42
|
+
});
|
|
43
|
+
});
|
|
35
44
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var
|
|
45
|
+
describe(".delete()", function () {
|
|
46
|
+
it("correctly removes pointed properties", function () {
|
|
47
|
+
var state = { person: { name: "Joe" } };
|
|
48
|
+
var b = Binding.get("person.name");
|
|
39
49
|
var ns = b.delete(state);
|
|
40
|
-
assert(
|
|
41
|
-
assert(!(
|
|
50
|
+
assert("person" in ns);
|
|
51
|
+
assert(!("name" in ns.person));
|
|
42
52
|
});
|
|
43
53
|
|
|
44
|
-
it(
|
|
45
|
-
var state = {person: {name:
|
|
46
|
-
var b = Binding.get(
|
|
54
|
+
it("does not change state if property is non-existent", function () {
|
|
55
|
+
var state = { person: { name: "Joe" } };
|
|
56
|
+
var b = Binding.get("person.name2");
|
|
47
57
|
var ns = b.delete(state);
|
|
48
58
|
assert(ns == state);
|
|
49
59
|
});
|
|
@@ -7,6 +7,7 @@ interface Model {
|
|
|
7
7
|
city: string;
|
|
8
8
|
streetNumber: number;
|
|
9
9
|
};
|
|
10
|
+
"@crazy": string;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
describe("createAccessorModelProxy", () => {
|
|
@@ -35,4 +36,9 @@ describe("createAccessorModelProxy", () => {
|
|
|
35
36
|
assert.strictEqual(streetNumber.nameOf(), "streetNumber");
|
|
36
37
|
assert.strictEqual(city.nameOf(), "city");
|
|
37
38
|
});
|
|
39
|
+
|
|
40
|
+
it("allows non-standard property identifiers ", () => {
|
|
41
|
+
let model = createAccessorModelProxy<Model>();
|
|
42
|
+
assert.strictEqual(model["@crazy"].nameOf(), "@crazy");
|
|
43
|
+
});
|
|
38
44
|
});
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import * as Cx from
|
|
2
|
-
import { FieldProps } from
|
|
1
|
+
import * as Cx from "../../core";
|
|
2
|
+
import { FieldProps } from "./Field";
|
|
3
3
|
|
|
4
|
-
interface ValidatorProps extends FieldProps {
|
|
4
|
+
interface ValidatorProps extends FieldProps {
|
|
5
|
+
value: Cx.StructuredProp;
|
|
6
|
+
}
|
|
5
7
|
|
|
6
8
|
export class Validator extends Cx.Widget<ValidatorProps> {}
|