jazz-tools 0.8.15 → 0.8.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. package/CHANGELOG.md +283 -269
  2. package/dist/native/coValues/account.js +3 -6
  3. package/dist/native/coValues/account.js.map +1 -1
  4. package/dist/native/coValues/coList.js +3 -7
  5. package/dist/native/coValues/coList.js.map +1 -1
  6. package/dist/native/coValues/coMap.js +8 -14
  7. package/dist/native/coValues/coMap.js.map +1 -1
  8. package/dist/native/coValues/coStream.js +7 -12
  9. package/dist/native/coValues/coStream.js.map +1 -1
  10. package/dist/native/coValues/deepLoading.js +6 -3
  11. package/dist/native/coValues/deepLoading.js.map +1 -1
  12. package/dist/native/coValues/extensions/imageDef.js.map +1 -1
  13. package/dist/native/coValues/group.js +3 -6
  14. package/dist/native/coValues/group.js.map +1 -1
  15. package/dist/native/coValues/interfaces.js +4 -3
  16. package/dist/native/coValues/interfaces.js.map +1 -1
  17. package/dist/native/exports.js +3 -9
  18. package/dist/native/exports.js.map +1 -1
  19. package/dist/native/implementation/createContext.js +1 -2
  20. package/dist/native/implementation/createContext.js.map +1 -1
  21. package/dist/native/implementation/devtoolsFormatters.js +5 -25
  22. package/dist/native/implementation/devtoolsFormatters.js.map +1 -1
  23. package/dist/native/implementation/refs.js +1 -2
  24. package/dist/native/implementation/refs.js.map +1 -1
  25. package/dist/native/implementation/schema.js +1 -1
  26. package/dist/native/implementation/schema.js.map +1 -1
  27. package/dist/native/implementation/subscriptionScope.js +2 -4
  28. package/dist/native/implementation/subscriptionScope.js.map +1 -1
  29. package/dist/native/index.native.js +1 -1
  30. package/dist/native/index.native.js.map +1 -1
  31. package/dist/native/lib/cache.js.map +1 -1
  32. package/dist/native/lib/cache.test.js +1 -1
  33. package/dist/native/lib/cache.test.js.map +1 -1
  34. package/dist/web/coValues/account.js +3 -6
  35. package/dist/web/coValues/account.js.map +1 -1
  36. package/dist/web/coValues/coList.js +3 -7
  37. package/dist/web/coValues/coList.js.map +1 -1
  38. package/dist/web/coValues/coMap.js +8 -14
  39. package/dist/web/coValues/coMap.js.map +1 -1
  40. package/dist/web/coValues/coStream.js +7 -12
  41. package/dist/web/coValues/coStream.js.map +1 -1
  42. package/dist/web/coValues/deepLoading.js +6 -3
  43. package/dist/web/coValues/deepLoading.js.map +1 -1
  44. package/dist/web/coValues/extensions/imageDef.js.map +1 -1
  45. package/dist/web/coValues/group.js +3 -6
  46. package/dist/web/coValues/group.js.map +1 -1
  47. package/dist/web/coValues/interfaces.js +4 -3
  48. package/dist/web/coValues/interfaces.js.map +1 -1
  49. package/dist/web/exports.js +3 -9
  50. package/dist/web/exports.js.map +1 -1
  51. package/dist/web/implementation/createContext.js +1 -2
  52. package/dist/web/implementation/createContext.js.map +1 -1
  53. package/dist/web/implementation/devtoolsFormatters.js +5 -25
  54. package/dist/web/implementation/devtoolsFormatters.js.map +1 -1
  55. package/dist/web/implementation/refs.js +1 -2
  56. package/dist/web/implementation/refs.js.map +1 -1
  57. package/dist/web/implementation/schema.js +1 -1
  58. package/dist/web/implementation/schema.js.map +1 -1
  59. package/dist/web/implementation/subscriptionScope.js +2 -4
  60. package/dist/web/implementation/subscriptionScope.js.map +1 -1
  61. package/dist/web/lib/cache.js.map +1 -1
  62. package/dist/web/lib/cache.test.js +1 -1
  63. package/dist/web/lib/cache.test.js.map +1 -1
  64. package/package.json +5 -9
  65. package/src/coValues/account.ts +330 -339
  66. package/src/coValues/coList.ts +474 -495
  67. package/src/coValues/coMap.ts +584 -604
  68. package/src/coValues/coStream.ts +624 -650
  69. package/src/coValues/deepLoading.ts +184 -200
  70. package/src/coValues/extensions/imageDef.ts +44 -44
  71. package/src/coValues/group.ts +196 -210
  72. package/src/coValues/interfaces.ts +197 -199
  73. package/src/exports.ts +38 -26
  74. package/src/implementation/createContext.ts +206 -213
  75. package/src/implementation/devtoolsFormatters.ts +80 -100
  76. package/src/implementation/refs.ts +127 -139
  77. package/src/implementation/schema.ts +124 -128
  78. package/src/implementation/subscriptionScope.ts +111 -121
  79. package/src/index.native.ts +3 -3
  80. package/src/lib/cache.test.ts +48 -48
  81. package/src/lib/cache.ts +9 -9
  82. package/src/tests/coList.test.ts +264 -283
  83. package/src/tests/coMap.test.ts +741 -761
  84. package/src/tests/coStream.test.ts +405 -438
  85. package/src/tests/deepLoading.test.ts +251 -256
  86. package/src/tests/groupsAndAccounts.test.ts +70 -74
  87. package/src/tests/schema.test.ts +198 -198
  88. package/src/tests/subscribe.test.ts +312 -299
  89. package/tsconfig.json +2 -4
  90. package/tsconfig.native.json +4 -10
  91. package/tsconfig.web.json +4 -10
  92. package/.eslintrc.cjs +0 -24
  93. package/.prettierrc.js +0 -9
@@ -1,307 +1,288 @@
1
- import { expect, describe, test } from "vitest";
2
1
  import { connectedPeers } from "cojson/src/streamUtils.ts";
2
+ import { describe, expect, test } from "vitest";
3
3
  import {
4
- Account,
5
- CoList,
6
- WasmCrypto,
7
- co,
8
- cojsonInternals,
9
- createJazzContext,
10
- isControlledAccount,
11
- fixedCredentialsAuth,
4
+ Account,
5
+ CoList,
6
+ WasmCrypto,
7
+ co,
8
+ cojsonInternals,
9
+ createJazzContext,
10
+ fixedCredentialsAuth,
11
+ isControlledAccount,
12
12
  } from "../index.web.js";
13
13
  import { randomSessionProvider } from "../internal.js";
14
14
 
15
15
  const Crypto = await WasmCrypto.create();
16
16
 
17
17
  describe("Simple CoList operations", async () => {
18
- const me = await Account.create({
19
- creationProps: { name: "Hermes Puggington" },
20
- crypto: Crypto,
18
+ const me = await Account.create({
19
+ creationProps: { name: "Hermes Puggington" },
20
+ crypto: Crypto,
21
+ });
22
+
23
+ class TestList extends CoList.Of(co.string) {}
24
+
25
+ const list = TestList.create(["bread", "butter", "onion"], { owner: me });
26
+
27
+ test("Construction", () => {
28
+ expect(list[0]).toBe("bread");
29
+ expect(list[1]).toBe("butter");
30
+ expect(list[2]).toBe("onion");
31
+ expect(list._raw.asArray()).toEqual(["bread", "butter", "onion"]);
32
+ expect(list.length).toBe(3);
33
+ expect(list.map((item) => item.toUpperCase())).toEqual([
34
+ "BREAD",
35
+ "BUTTER",
36
+ "ONION",
37
+ ]);
38
+ });
39
+
40
+ describe("Mutation", () => {
41
+ test("assignment", () => {
42
+ const list = TestList.create(["bread", "butter", "onion"], {
43
+ owner: me,
44
+ });
45
+ list[1] = "margarine";
46
+ expect(list._raw.asArray()).toEqual(["bread", "margarine", "onion"]);
47
+ expect(list[1]).toBe("margarine");
48
+ });
49
+
50
+ test("push", () => {
51
+ const list = TestList.create(["bread", "butter", "onion"], {
52
+ owner: me,
53
+ });
54
+ list.push("cheese");
55
+ expect(list[3]).toBe("cheese");
56
+ expect(list._raw.asArray()).toEqual([
57
+ "bread",
58
+ "butter",
59
+ "onion",
60
+ "cheese",
61
+ ]);
62
+ });
63
+
64
+ test("unshift", () => {
65
+ const list = TestList.create(["bread", "butter", "onion"], {
66
+ owner: me,
67
+ });
68
+ list.unshift("lettuce");
69
+ expect(list[0]).toBe("lettuce");
70
+ expect(list._raw.asArray()).toEqual([
71
+ "lettuce",
72
+ "bread",
73
+ "butter",
74
+ "onion",
75
+ ]);
76
+ });
77
+
78
+ test("pop", () => {
79
+ const list = TestList.create(["bread", "butter", "onion"], {
80
+ owner: me,
81
+ });
82
+ expect(list.pop()).toBe("onion");
83
+ expect(list.length).toBe(2);
84
+ expect(list._raw.asArray()).toEqual(["bread", "butter"]);
21
85
  });
22
86
 
23
- class TestList extends CoList.Of(co.string) {}
24
-
25
- const list = TestList.create(["bread", "butter", "onion"], { owner: me });
26
-
27
- test("Construction", () => {
28
- expect(list[0]).toBe("bread");
29
- expect(list[1]).toBe("butter");
30
- expect(list[2]).toBe("onion");
31
- expect(list._raw.asArray()).toEqual(["bread", "butter", "onion"]);
32
- expect(list.length).toBe(3);
33
- expect(list.map((item) => item.toUpperCase())).toEqual([
34
- "BREAD",
35
- "BUTTER",
36
- "ONION",
37
- ]);
87
+ test("shift", () => {
88
+ const list = TestList.create(["bread", "butter", "onion"], {
89
+ owner: me,
90
+ });
91
+ expect(list.shift()).toBe("bread");
92
+ expect(list.length).toBe(2);
93
+ expect(list._raw.asArray()).toEqual(["butter", "onion"]);
38
94
  });
39
95
 
40
- describe("Mutation", () => {
41
- test("assignment", () => {
42
- const list = TestList.create(["bread", "butter", "onion"], {
43
- owner: me,
44
- });
45
- list[1] = "margarine";
46
- expect(list._raw.asArray()).toEqual([
47
- "bread",
48
- "margarine",
49
- "onion",
50
- ]);
51
- expect(list[1]).toBe("margarine");
52
- });
53
-
54
- test("push", () => {
55
- const list = TestList.create(["bread", "butter", "onion"], {
56
- owner: me,
57
- });
58
- list.push("cheese");
59
- expect(list[3]).toBe("cheese");
60
- expect(list._raw.asArray()).toEqual([
61
- "bread",
62
- "butter",
63
- "onion",
64
- "cheese",
65
- ]);
66
- });
67
-
68
- test("unshift", () => {
69
- const list = TestList.create(["bread", "butter", "onion"], {
70
- owner: me,
71
- });
72
- list.unshift("lettuce");
73
- expect(list[0]).toBe("lettuce");
74
- expect(list._raw.asArray()).toEqual([
75
- "lettuce",
76
- "bread",
77
- "butter",
78
- "onion",
79
- ]);
80
- });
81
-
82
- test("pop", () => {
83
- const list = TestList.create(["bread", "butter", "onion"], {
84
- owner: me,
85
- });
86
- expect(list.pop()).toBe("onion");
87
- expect(list.length).toBe(2);
88
- expect(list._raw.asArray()).toEqual(["bread", "butter"]);
89
- });
90
-
91
- test("shift", () => {
92
- const list = TestList.create(["bread", "butter", "onion"], {
93
- owner: me,
94
- });
95
- expect(list.shift()).toBe("bread");
96
- expect(list.length).toBe(2);
97
- expect(list._raw.asArray()).toEqual(["butter", "onion"]);
98
- });
99
-
100
- test("splice", () => {
101
- const list = TestList.create(["bread", "butter", "onion"], {
102
- owner: me,
103
- });
104
- list.splice(1, 1, "salt", "pepper");
105
- expect(list.length).toBe(4);
106
- expect(list._raw.asArray()).toEqual([
107
- "bread",
108
- "salt",
109
- "pepper",
110
- "onion",
111
- ]);
112
- });
96
+ test("splice", () => {
97
+ const list = TestList.create(["bread", "butter", "onion"], {
98
+ owner: me,
99
+ });
100
+ list.splice(1, 1, "salt", "pepper");
101
+ expect(list.length).toBe(4);
102
+ expect(list._raw.asArray()).toEqual(["bread", "salt", "pepper", "onion"]);
113
103
  });
104
+ });
114
105
  });
115
106
 
116
107
  describe("CoList resolution", async () => {
117
- class TwiceNestedList extends CoList.Of(co.string) {
118
- joined() {
119
- return this.join(",");
120
- }
108
+ class TwiceNestedList extends CoList.Of(co.string) {
109
+ joined() {
110
+ return this.join(",");
111
+ }
112
+ }
113
+
114
+ class NestedList extends CoList.Of(co.ref(TwiceNestedList)) {}
115
+
116
+ class TestList extends CoList.Of(co.ref(NestedList)) {}
117
+
118
+ const initNodeAndList = async () => {
119
+ const me = await Account.create({
120
+ creationProps: { name: "Hermes Puggington" },
121
+ crypto: Crypto,
122
+ });
123
+
124
+ const list = TestList.create(
125
+ [
126
+ NestedList.create([TwiceNestedList.create(["a", "b"], { owner: me })], {
127
+ owner: me,
128
+ }),
129
+ NestedList.create([TwiceNestedList.create(["c", "d"], { owner: me })], {
130
+ owner: me,
131
+ }),
132
+ ],
133
+ { owner: me },
134
+ );
135
+
136
+ return { me, list };
137
+ };
138
+
139
+ test("Construction", async () => {
140
+ const { list } = await initNodeAndList();
141
+
142
+ expect(list[0]?.[0]?.[0]).toBe("a");
143
+ expect(list[0]?.[0]?.joined()).toBe("a,b");
144
+ expect(list[0]?.[0]?.id).toBeDefined();
145
+ expect(list[1]?.[0]?.[0]).toBe("c");
146
+ });
147
+
148
+ test("Loading and availability", async () => {
149
+ const { me, list } = await initNodeAndList();
150
+
151
+ const [initialAsPeer, secondPeer] = connectedPeers("initial", "second", {
152
+ peer1role: "server",
153
+ peer2role: "client",
154
+ });
155
+ if (!isControlledAccount(me)) {
156
+ throw "me is not a controlled account";
121
157
  }
158
+ me._raw.core.node.syncManager.addPeer(secondPeer);
159
+ const { account: meOnSecondPeer } = await createJazzContext({
160
+ auth: fixedCredentialsAuth({
161
+ accountID: me.id,
162
+ secret: me._raw.agentSecret,
163
+ }),
164
+ sessionProvider: randomSessionProvider,
165
+ peersToLoadFrom: [initialAsPeer],
166
+ crypto: Crypto,
167
+ });
122
168
 
123
- class NestedList extends CoList.Of(co.ref(TwiceNestedList)) {}
124
-
125
- class TestList extends CoList.Of(co.ref(NestedList)) {}
126
-
127
- const initNodeAndList = async () => {
128
- const me = await Account.create({
129
- creationProps: { name: "Hermes Puggington" },
130
- crypto: Crypto,
131
- });
132
-
133
- const list = TestList.create(
134
- [
135
- NestedList.create(
136
- [TwiceNestedList.create(["a", "b"], { owner: me })],
137
- { owner: me },
138
- ),
139
- NestedList.create(
140
- [TwiceNestedList.create(["c", "d"], { owner: me })],
141
- { owner: me },
142
- ),
143
- ],
144
- { owner: me },
145
- );
146
-
147
- return { me, list };
148
- };
149
-
150
- test("Construction", async () => {
151
- const { list } = await initNodeAndList();
152
-
153
- expect(list[0]?.[0]?.[0]).toBe("a");
154
- expect(list[0]?.[0]?.joined()).toBe("a,b");
155
- expect(list[0]?.[0]?.id).toBeDefined();
156
- expect(list[1]?.[0]?.[0]).toBe("c");
169
+ const loadedList = await TestList.load(list.id, meOnSecondPeer, []);
170
+
171
+ expect(loadedList?.[0]).toBe(null);
172
+ expect(loadedList?._refs[0]?.id).toEqual(list[0]!.id);
173
+
174
+ const loadedNestedList = await NestedList.load(
175
+ list[0]!.id,
176
+ meOnSecondPeer,
177
+ [],
178
+ );
179
+
180
+ expect(loadedList?.[0]).toBeDefined();
181
+ expect(loadedList?.[0]?.[0]).toBe(null);
182
+ expect(loadedList?.[0]?._refs[0]?.id).toEqual(list[0]![0]!.id);
183
+ // TODO: this should be ref equal
184
+ // expect(loadedList?._refs[0]?.value).toEqual(loadedNestedList);
185
+ expect(loadedList?._refs[0]?.value?.toJSON()).toEqual(
186
+ loadedNestedList?.toJSON(),
187
+ );
188
+
189
+ const loadedTwiceNestedList = await TwiceNestedList.load(
190
+ list[0]![0]!.id,
191
+ meOnSecondPeer,
192
+ [],
193
+ );
194
+
195
+ expect(loadedList?.[0]?.[0]).toBeDefined();
196
+ expect(loadedList?.[0]?.[0]?.[0]).toBe("a");
197
+ expect(loadedList?.[0]?.[0]?.joined()).toBe("a,b");
198
+ expect(loadedList?.[0]?._refs[0]?.id).toEqual(list[0]?.[0]?.id);
199
+ // TODO: this should be ref equal
200
+ // expect(loadedList?.[0]?._refs[0]?.value).toEqual(loadedTwiceNestedList);
201
+ expect(loadedList?.[0]?._refs[0]?.value?.toJSON()).toEqual(
202
+ loadedTwiceNestedList?.toJSON(),
203
+ );
204
+
205
+ const otherNestedList = NestedList.create(
206
+ [TwiceNestedList.create(["e", "f"], { owner: meOnSecondPeer })],
207
+ { owner: meOnSecondPeer },
208
+ );
209
+
210
+ loadedList![0] = otherNestedList;
211
+ // TODO: this should be ref equal
212
+ // expect(loadedList?.[0]).toEqual(otherNestedList);
213
+ expect(loadedList?._refs[0]?.value?.toJSON()).toEqual(
214
+ otherNestedList.toJSON(),
215
+ );
216
+ expect(loadedList?._refs[0]?.id).toEqual(otherNestedList.id);
217
+ });
218
+
219
+ test("Subscription & auto-resolution", async () => {
220
+ const { me, list } = await initNodeAndList();
221
+
222
+ const [initialAsPeer, secondPeer] = connectedPeers("initial", "second", {
223
+ peer1role: "server",
224
+ peer2role: "client",
225
+ });
226
+ if (!isControlledAccount(me)) {
227
+ throw "me is not a controlled account";
228
+ }
229
+ me._raw.core.node.syncManager.addPeer(secondPeer);
230
+ const { account: meOnSecondPeer } = await createJazzContext({
231
+ auth: fixedCredentialsAuth({
232
+ accountID: me.id,
233
+ secret: me._raw.agentSecret,
234
+ }),
235
+ sessionProvider: randomSessionProvider,
236
+ peersToLoadFrom: [initialAsPeer],
237
+ crypto: Crypto,
157
238
  });
158
239
 
159
- test("Loading and availability", async () => {
160
- const { me, list } = await initNodeAndList();
161
-
162
- const [initialAsPeer, secondPeer] = connectedPeers(
163
- "initial",
164
- "second",
165
- {
166
- peer1role: "server",
167
- peer2role: "client",
168
- },
169
- );
170
- if (!isControlledAccount(me)) {
171
- throw "me is not a controlled account";
172
- }
173
- me._raw.core.node.syncManager.addPeer(secondPeer);
174
- const { account: meOnSecondPeer } = await createJazzContext({
175
- auth: fixedCredentialsAuth({
176
- accountID: me.id,
177
- secret: me._raw.agentSecret,
178
- }),
179
- sessionProvider: randomSessionProvider,
180
- peersToLoadFrom: [initialAsPeer],
181
- crypto: Crypto,
182
- });
183
-
184
- const loadedList = await TestList.load(list.id, meOnSecondPeer, []);
185
-
186
- expect(loadedList?.[0]).toBe(null);
187
- expect(loadedList?._refs[0]?.id).toEqual(list[0]!.id);
188
-
189
- const loadedNestedList = await NestedList.load(
190
- list[0]!.id,
191
- meOnSecondPeer,
192
- [],
193
- );
194
-
195
- expect(loadedList?.[0]).toBeDefined();
196
- expect(loadedList?.[0]?.[0]).toBe(null);
197
- expect(loadedList?.[0]?._refs[0]?.id).toEqual(list[0]![0]!.id);
198
- // TODO: this should be ref equal
199
- // expect(loadedList?._refs[0]?.value).toEqual(loadedNestedList);
200
- expect(loadedList?._refs[0]?.value?.toJSON()).toEqual(
201
- loadedNestedList?.toJSON(),
202
- );
203
-
204
- const loadedTwiceNestedList = await TwiceNestedList.load(
205
- list[0]![0]!.id,
206
- meOnSecondPeer,
207
- [],
208
- );
209
-
210
- expect(loadedList?.[0]?.[0]).toBeDefined();
211
- expect(loadedList?.[0]?.[0]?.[0]).toBe("a");
212
- expect(loadedList?.[0]?.[0]?.joined()).toBe("a,b");
213
- expect(loadedList?.[0]?._refs[0]?.id).toEqual(list[0]?.[0]?.id);
214
- // TODO: this should be ref equal
215
- // expect(loadedList?.[0]?._refs[0]?.value).toEqual(loadedTwiceNestedList);
216
- expect(loadedList?.[0]?._refs[0]?.value?.toJSON()).toEqual(
217
- loadedTwiceNestedList?.toJSON(),
218
- );
219
-
220
- const otherNestedList = NestedList.create(
221
- [TwiceNestedList.create(["e", "f"], { owner: meOnSecondPeer })],
222
- { owner: meOnSecondPeer },
223
- );
224
-
225
- loadedList![0] = otherNestedList;
226
- // TODO: this should be ref equal
227
- // expect(loadedList?.[0]).toEqual(otherNestedList);
228
- expect(loadedList?._refs[0]?.value?.toJSON()).toEqual(
229
- otherNestedList.toJSON(),
230
- );
231
- expect(loadedList?._refs[0]?.id).toEqual(otherNestedList.id);
240
+ const queue = new cojsonInternals.Channel();
241
+
242
+ TestList.subscribe(list.id, meOnSecondPeer, [], (subscribedList) => {
243
+ console.log(
244
+ "subscribedList?.[0]?.[0]?.[0]",
245
+ subscribedList?.[0]?.[0]?.[0],
246
+ );
247
+ void queue.push(subscribedList);
232
248
  });
233
249
 
234
- test("Subscription & auto-resolution", async () => {
235
- const { me, list } = await initNodeAndList();
236
-
237
- const [initialAsPeer, secondPeer] = connectedPeers(
238
- "initial",
239
- "second",
240
- {
241
- peer1role: "server",
242
- peer2role: "client",
243
- },
244
- );
245
- if (!isControlledAccount(me)) {
246
- throw "me is not a controlled account";
247
- }
248
- me._raw.core.node.syncManager.addPeer(secondPeer);
249
- const { account: meOnSecondPeer } = await createJazzContext({
250
- auth: fixedCredentialsAuth({
251
- accountID: me.id,
252
- secret: me._raw.agentSecret,
253
- }),
254
- sessionProvider: randomSessionProvider,
255
- peersToLoadFrom: [initialAsPeer],
256
- crypto: Crypto,
257
- });
258
-
259
- const queue = new cojsonInternals.Channel();
260
-
261
- TestList.subscribe(list.id, meOnSecondPeer, [], (subscribedList) => {
262
- console.log(
263
- "subscribedList?.[0]?.[0]?.[0]",
264
- subscribedList?.[0]?.[0]?.[0],
265
- );
266
- void queue.push(subscribedList);
267
- });
268
-
269
- const update1 = (await queue.next()).value;
270
- expect(update1?.[0]).toBe(null);
271
-
272
- const update2 = (await queue.next()).value;
273
- expect(update2?.[0]).toBeDefined();
274
- expect(update2?.[0]?.[0]).toBe(null);
275
-
276
- const update3 = (await queue.next()).value;
277
- expect(update3?.[0]?.[0]).toBeDefined();
278
- expect(update3?.[0]?.[0]?.[0]).toBe("a");
279
- expect(update3?.[0]?.[0]?.joined()).toBe("a,b");
280
-
281
- update3[0]![0]![0] = "x";
282
-
283
- const update4 = (await queue.next()).value;
284
- expect(update4?.[0]?.[0]?.[0]).toBe("x");
285
-
286
- // When assigning a new nested value, we get an update
287
-
288
- const newTwiceNestedList = TwiceNestedList.create(["y", "z"], {
289
- owner: meOnSecondPeer,
290
- });
291
-
292
- const newNestedList = NestedList.create([newTwiceNestedList], {
293
- owner: meOnSecondPeer,
294
- });
295
-
296
- update4[0] = newNestedList;
297
-
298
- const update5 = (await queue.next()).value;
299
- expect(update5?.[0]?.[0]?.[0]).toBe("y");
300
- expect(update5?.[0]?.[0]?.joined()).toBe("y,z");
301
-
302
- // we get updates when the new nested value changes
303
- newTwiceNestedList[0] = "w";
304
- const update6 = (await queue.next()).value;
305
- expect(update6?.[0]?.[0]?.[0]).toBe("w");
250
+ const update1 = (await queue.next()).value;
251
+ expect(update1?.[0]).toBe(null);
252
+
253
+ const update2 = (await queue.next()).value;
254
+ expect(update2?.[0]).toBeDefined();
255
+ expect(update2?.[0]?.[0]).toBe(null);
256
+
257
+ const update3 = (await queue.next()).value;
258
+ expect(update3?.[0]?.[0]).toBeDefined();
259
+ expect(update3?.[0]?.[0]?.[0]).toBe("a");
260
+ expect(update3?.[0]?.[0]?.joined()).toBe("a,b");
261
+
262
+ update3[0]![0]![0] = "x";
263
+
264
+ const update4 = (await queue.next()).value;
265
+ expect(update4?.[0]?.[0]?.[0]).toBe("x");
266
+
267
+ // When assigning a new nested value, we get an update
268
+
269
+ const newTwiceNestedList = TwiceNestedList.create(["y", "z"], {
270
+ owner: meOnSecondPeer,
271
+ });
272
+
273
+ const newNestedList = NestedList.create([newTwiceNestedList], {
274
+ owner: meOnSecondPeer,
306
275
  });
276
+
277
+ update4[0] = newNestedList;
278
+
279
+ const update5 = (await queue.next()).value;
280
+ expect(update5?.[0]?.[0]?.[0]).toBe("y");
281
+ expect(update5?.[0]?.[0]?.joined()).toBe("y,z");
282
+
283
+ // we get updates when the new nested value changes
284
+ newTwiceNestedList[0] = "w";
285
+ const update6 = (await queue.next()).value;
286
+ expect(update6?.[0]?.[0]?.[0]).toBe("w");
287
+ });
307
288
  });