@homebound/form-state 2.26.11 → 2.26.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/dist/fields/listField.js +12 -9
- package/dist/formState.test.js +21 -0
- package/package.json +1 -1
package/dist/fields/listField.js
CHANGED
|
@@ -223,17 +223,20 @@ parentInstance, parentState, key, rules, listConfig, config, strictOrder, maybeA
|
|
|
223
223
|
// Once matched, we don't this to be an addedRow anymore
|
|
224
224
|
addedRows.delete(currentItem);
|
|
225
225
|
}
|
|
226
|
-
else if (childState.dirty
|
|
227
|
-
//
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
226
|
+
else if (!childState.dirty && !addedRows.has(currentItem)) {
|
|
227
|
+
// Local is not dirty/added, and it's not upstream, so let it get removed
|
|
228
|
+
}
|
|
229
|
+
else if (hasOpKey && currentItem.op === "delete") {
|
|
230
|
+
// We were locally marked as deleted, and not finding a match is the server acking that we're gone
|
|
231
|
+
}
|
|
232
|
+
else if (currentItems.length === incomingItems.length &&
|
|
233
|
+
!!idKey &&
|
|
234
|
+
currentItem[idKey] === undefined) {
|
|
235
|
+
// Assume our newly-assigned id is coming back
|
|
234
236
|
}
|
|
235
237
|
else {
|
|
236
|
-
//
|
|
238
|
+
// If no incoming, but we're dirty (see above) and not deleted (see above), keep the WIP change
|
|
239
|
+
mergedItems.push(currentItem);
|
|
237
240
|
}
|
|
238
241
|
}
|
|
239
242
|
// Then, add any incoming items that don't exist in current
|
package/dist/formState.test.js
CHANGED
|
@@ -258,6 +258,27 @@ describe("formState", () => {
|
|
|
258
258
|
// And we're not dirty
|
|
259
259
|
expect(state.books.dirty).toBe(false);
|
|
260
260
|
});
|
|
261
|
+
it("list value can refresh and merge children that were added", () => {
|
|
262
|
+
// Given a list field that is currently populated with 1 child
|
|
263
|
+
const a1 = { id: "a:1", books: [{ id: "b:1", title: "b1" }] };
|
|
264
|
+
const state = createAuthorInputState(a1);
|
|
265
|
+
// When we add a new book
|
|
266
|
+
state.books.add({ title: "b2" });
|
|
267
|
+
// When we refresh it with both books, and the 2nd book now has its id assigned
|
|
268
|
+
state.set({
|
|
269
|
+
books: [
|
|
270
|
+
{ id: "b:1", title: "b1" },
|
|
271
|
+
{ id: "b:2", title: "b2" },
|
|
272
|
+
],
|
|
273
|
+
}, { refreshing: true });
|
|
274
|
+
// Then wes till have two books
|
|
275
|
+
expect(state.books.value).toEqual([
|
|
276
|
+
{ id: "b:1", title: "b1" },
|
|
277
|
+
{ id: "b:2", title: "b2" },
|
|
278
|
+
]);
|
|
279
|
+
// And we're not dirty
|
|
280
|
+
expect(state.books.dirty).toBe(false);
|
|
281
|
+
});
|
|
261
282
|
it("list value can observe changes", () => {
|
|
262
283
|
const b1 = { title: "t1" };
|
|
263
284
|
const a1 = { firstName: "a1", books: [b1] };
|