@homebound/form-state 2.26.0 → 2.26.1

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/config.d.ts CHANGED
@@ -38,7 +38,7 @@ export type ValueFieldConfig<V> = {
38
38
  computed?: boolean;
39
39
  /** Marks a field as being initially read-only, i.e. `field.readOnly = true/false` can change this default. */
40
40
  readOnly?: boolean;
41
- /** Marks an array field to be order agnostic when determining changed/dirty states */
41
+ /** Marks an array field to be order agnostic when determining changed/dirty states, defaults true. */
42
42
  strictOrder?: false;
43
43
  };
44
44
  /** Field configuration for list values, i.e. `U` is `Book` in a form with `books: Book[]`. */
@@ -60,7 +60,7 @@ export type ListFieldConfig<U> = {
60
60
  * default behavior.
61
61
  */
62
62
  update?: "exhaustive" | "incremental";
63
- /** Set to not consider the order of the list when evaluating changed/dirty states. */
63
+ /** Set to not consider the order of the list when evaluating changed/dirty states, defaults true. */
64
64
  strictOrder?: false;
65
65
  };
66
66
  export type ObjectFieldConfig<U> = {
@@ -50,7 +50,8 @@ function newListFieldState(parentCopy, parentInstance, parentState, key, rules,
50
50
  key: key,
51
51
  // Our fundamental state of wrapped Us
52
52
  get value() {
53
- return _tick.value > 0 && _childTick.value > 0 ? parentInstance[key] : (0, utils_1.fail)();
53
+ var _a;
54
+ return _tick.value > 0 && _childTick.value > 0 ? ((_a = parentInstance[key]) !== null && _a !== void 0 ? _a : []) : (0, utils_1.fail)();
54
55
  },
55
56
  _focused: false,
56
57
  _readOnly: false,
@@ -336,6 +336,22 @@ describe("useFormState", () => {
336
336
  // Then we auto save again
337
337
  expect(autoSave).toBeCalledTimes(2);
338
338
  });
339
+ it("returns empty lists even when inputs are undefined", async () => {
340
+ const autoSave = jest.fn();
341
+ // Given a component
342
+ function TestComponent() {
343
+ // And there is no initial data (i.e. we're creating the author)
344
+ const form = (0, useFormState_1.useFormState)({
345
+ config: authorWithBooksConfig,
346
+ init: { input: undefined, map: (d) => d },
347
+ autoSave,
348
+ });
349
+ return (0, jsx_runtime_1.jsx)("div", { "data-testid": "len", children: form.books.value.length });
350
+ }
351
+ // Then we can still read it as empty
352
+ const r = await (0, rtl_utils_1.render)((0, jsx_runtime_1.jsx)(TestComponent, {}));
353
+ expect(r.len).toHaveTextContent("0");
354
+ });
339
355
  it("does not infinite loop when calling set inside of auto-save", async () => {
340
356
  // Given a component
341
357
  let autoSaves = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/form-state",
3
- "version": "2.26.0",
3
+ "version": "2.26.1",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",