@homebound/form-state 2.26.7 → 2.26.8

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.
@@ -1,4 +1,4 @@
1
1
  export interface FragmentField<V> {
2
2
  value: V;
3
3
  }
4
- export declare function newFragmentField<T, K extends keyof T>(parentInstance: T, key: K): FragmentField<T[K]>;
4
+ export declare function newFragmentField<T extends object, K extends keyof T & string>(parentInstance: T, key: K): FragmentField<T[K]>;
@@ -12,7 +12,33 @@ function newFragmentField(parentInstance, key) {
12
12
  let value = parentInstance[key];
13
13
  delete parentInstance[key];
14
14
  const obj = {
15
+ key,
16
+ _isIdKey: false,
17
+ _isDeleteKey: false,
18
+ _isReadOnlyKey: false,
19
+ touched: false,
20
+ valid: true,
21
+ readOnly: true,
22
+ required: false,
23
+ loading: false,
24
+ dirty: false,
25
+ focused: false,
26
+ originalValue: undefined,
27
+ changedValue: undefined,
28
+ errors: [],
29
+ rules: [],
30
+ isNewEntity: false,
31
+ focus: () => { },
32
+ blur: () => { },
33
+ maybeAutoSave: () => { },
34
+ commitChanges: () => { },
35
+ revertChanges: () => { },
15
36
  get value() {
37
+ // Watch for our parentInstance changing
38
+ if (key in parentInstance) {
39
+ value = parentInstance[key];
40
+ delete parentInstance[key];
41
+ }
16
42
  _tick.value > 0 || (0, utils_1.fail)();
17
43
  return value;
18
44
  },
@@ -20,6 +46,12 @@ function newFragmentField(parentInstance, key) {
20
46
  value = v;
21
47
  _tick.value++;
22
48
  },
49
+ set() {
50
+ throw new Error("FragmentField is read-only");
51
+ },
52
+ adapt() {
53
+ throw new Error("FragmentField is read-only");
54
+ },
23
55
  };
24
56
  return (0, mobx_1.makeAutoObservable)(obj, { value: false });
25
57
  }
@@ -129,7 +129,10 @@ function newObjectState(config, parentState, parentInstance, parentListState, in
129
129
  this._loading = loading;
130
130
  },
131
131
  get valid() {
132
- return getFields(this).every((f) => f.valid);
132
+ return getFields(this).every((f) => {
133
+ console.log(`Looking at ${f.key} valid=${f.valid}`);
134
+ return f.valid;
135
+ });
133
136
  },
134
137
  get errors() {
135
138
  return getFields(this).flatMap((f) => f.errors.map((e) => `${f.key}: ${e}`));
@@ -1671,6 +1671,10 @@ describe("formState", () => {
1671
1671
  }
1672
1672
  `);
1673
1673
  });
1674
+ it("are always considered valid", () => {
1675
+ const a = (0, objectField_1.createObjectState)({ data: { type: "fragment" } }, { data: (0, objectField_1.fragment)({ foo: "1" }) });
1676
+ expect(a.valid).toBe(true);
1677
+ });
1674
1678
  });
1675
1679
  it("sets id key correctly", () => {
1676
1680
  // Given an author
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/form-state",
3
- "version": "2.26.7",
3
+ "version": "2.26.8",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",