jazz-tools 0.9.10 → 0.9.12
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/.turbo/turbo-build.log +2 -2
- package/CHANGELOG.md +15 -0
- package/package.json +2 -2
- package/src/tests/schemaUnion.test.ts +25 -7
package/.turbo/turbo-build.log
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
> jazz-tools@0.9.
|
2
|
+
> jazz-tools@0.9.12 build /home/runner/work/jazz/jazz/packages/jazz-tools
|
3
3
|
> tsup
|
4
4
|
|
5
5
|
[34mCLI[39m Building entry: {"index.web":"src/index.web.ts","index.native":"src/index.native.ts","testing":"src/testing.ts"}
|
@@ -17,4 +17,4 @@
|
|
17
17
|
[32mESM[39m [1mdist/index.native.js.map [22m[32m283.00 B[39m
|
18
18
|
[32mESM[39m [1mdist/testing.js.map [22m[32m4.89 KB[39m
|
19
19
|
[32mESM[39m [1mdist/chunk-ICWP2U63.js.map [22m[32m235.54 KB[39m
|
20
|
-
[32mESM[39m ⚡️ Build success in
|
20
|
+
[32mESM[39m ⚡️ Build success in 84ms
|
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# jazz-tools
|
2
2
|
|
3
|
+
## 0.9.12
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- Updated dependencies [15d4b2a]
|
8
|
+
- cojson@0.9.12
|
9
|
+
|
10
|
+
## 0.9.11
|
11
|
+
|
12
|
+
### Patch Changes
|
13
|
+
|
14
|
+
- Updated dependencies [efbf3d8]
|
15
|
+
- Updated dependencies [5863bad]
|
16
|
+
- cojson@0.9.11
|
17
|
+
|
3
18
|
## 0.9.10
|
4
19
|
|
5
20
|
### Patch Changes
|
package/package.json
CHANGED
@@ -13,11 +13,29 @@ class BaseWidget extends CoMap {
|
|
13
13
|
type = co.string;
|
14
14
|
}
|
15
15
|
|
16
|
-
class
|
16
|
+
class RedButtonWidget extends BaseWidget {
|
17
17
|
type = co.literal("button");
|
18
|
+
color = co.literal("red");
|
18
19
|
label = co.string;
|
19
20
|
}
|
20
21
|
|
22
|
+
class BlueButtonWidget extends BaseWidget {
|
23
|
+
type = co.literal("button");
|
24
|
+
color = co.literal("blue");
|
25
|
+
label = co.string;
|
26
|
+
}
|
27
|
+
|
28
|
+
const ButtonWidget = SchemaUnion.Of<BaseWidget>((raw) => {
|
29
|
+
switch (raw.get("color")) {
|
30
|
+
case "red":
|
31
|
+
return RedButtonWidget;
|
32
|
+
case "blue":
|
33
|
+
return BlueButtonWidget;
|
34
|
+
default:
|
35
|
+
throw new Error(`Unknown button color: ${raw.get("color")}`);
|
36
|
+
}
|
37
|
+
});
|
38
|
+
|
21
39
|
class SliderWidget extends BaseWidget {
|
22
40
|
type = co.literal("slider");
|
23
41
|
min = co.number;
|
@@ -57,8 +75,8 @@ describe("SchemaUnion", () => {
|
|
57
75
|
});
|
58
76
|
|
59
77
|
it("should instantiate the correct subclass based on schema and provided data", async () => {
|
60
|
-
const buttonWidget =
|
61
|
-
{ type: "button", label: "Submit" },
|
78
|
+
const buttonWidget = RedButtonWidget.create(
|
79
|
+
{ type: "button", color: "red", label: "Submit" },
|
62
80
|
{ owner: me },
|
63
81
|
);
|
64
82
|
const sliderWidget = SliderWidget.create(
|
@@ -89,14 +107,14 @@ describe("SchemaUnion", () => {
|
|
89
107
|
{},
|
90
108
|
);
|
91
109
|
|
92
|
-
expect(loadedButtonWidget).toBeInstanceOf(
|
110
|
+
expect(loadedButtonWidget).toBeInstanceOf(RedButtonWidget);
|
93
111
|
expect(loadedSliderWidget).toBeInstanceOf(SliderWidget);
|
94
112
|
expect(loadedCheckboxWidget).toBeInstanceOf(CheckboxWidget);
|
95
113
|
});
|
96
114
|
|
97
115
|
it("should integrate with subscribeToCoValue correctly", async () => {
|
98
|
-
const buttonWidget =
|
99
|
-
{ type: "button", label: "Submit" },
|
116
|
+
const buttonWidget = BlueButtonWidget.create(
|
117
|
+
{ type: "button", color: "blue", label: "Submit" },
|
100
118
|
{ owner: me },
|
101
119
|
);
|
102
120
|
let currentValue = "Submit";
|
@@ -106,7 +124,7 @@ describe("SchemaUnion", () => {
|
|
106
124
|
me,
|
107
125
|
{},
|
108
126
|
(value: BaseWidget) => {
|
109
|
-
if (value instanceof
|
127
|
+
if (value instanceof BlueButtonWidget) {
|
110
128
|
expect(value.label).toBe(currentValue);
|
111
129
|
} else {
|
112
130
|
throw new Error("Unexpected widget type");
|