@homebound/form-state 2.12.0 → 2.13.0

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.
@@ -52,8 +52,8 @@ function FormStateApp() {
52
52
  jsx_runtime_1.jsx("td", { children: formState.valid.toString() }, void 0),
53
53
  jsx_runtime_1.jsx("td", { children: formState.dirty.toString() }, void 0)] }, void 0) }, void 0)] }), void 0),
54
54
  jsx_runtime_1.jsxs("div", { children: [jsx_runtime_1.jsx("button", Object.assign({ "data-testid": "touch", onClick: () => (formState.touched = !formState.touched) }, { children: "touch" }), void 0),
55
- jsx_runtime_1.jsx("button", Object.assign({ "data-testid": "reset", onClick: () => formState.reset() }, { children: "reset" }), void 0),
56
- jsx_runtime_1.jsx("button", Object.assign({ "data-testid": "save", onClick: () => formState.save() }, { children: "save" }), void 0),
55
+ jsx_runtime_1.jsx("button", Object.assign({ "data-testid": "revertChanges", onClick: () => formState.revertChanges() }, { children: "revert" }), void 0),
56
+ jsx_runtime_1.jsx("button", Object.assign({ "data-testid": "commitChanges", onClick: () => formState.commitChanges() }, { children: "commit" }), void 0),
57
57
  jsx_runtime_1.jsx("button", Object.assign({ "data-testid": "set", onClick: () => formState.set({ firstName: "a2" }) }, { children: "set" }), void 0)] }, void 0)] }, void 0)] }), void 0) }), void 0));
58
58
  } }, void 0));
59
59
  }
@@ -12,7 +12,7 @@ describe("FormStateApp", () => {
12
12
  expect(r.firstName_dirty()).toHaveTextContent("true");
13
13
  react_1.fireEvent.blur(r.firstName());
14
14
  expect(r.firstName_touched()).toHaveTextContent("true");
15
- rtl_utils_1.click(r.save);
15
+ rtl_utils_1.click(r.commitChanges);
16
16
  expect(r.firstName_dirty()).toHaveTextContent("false");
17
17
  expect(r.firstName_touched()).toHaveTextContent("false");
18
18
  });
@@ -20,7 +20,7 @@ describe("FormStateApp", () => {
20
20
  const r = await rtl_utils_1.render(jsx_runtime_1.jsx(FormStateApp_1.FormStateApp, {}, void 0));
21
21
  expect(r.firstName_original()).toHaveTextContent("a1");
22
22
  rtl_utils_1.click(r.set);
23
- rtl_utils_1.click(r.save);
23
+ rtl_utils_1.click(r.commitChanges);
24
24
  expect(r.firstName_original()).toHaveTextContent("a2");
25
25
  });
26
26
  });
@@ -184,16 +184,14 @@ function newListFieldState(parentInstance, parentState, key, rules, listConfig,
184
184
  _tick.value++;
185
185
  maybeAutoSave();
186
186
  },
187
- reset() {
187
+ revertChanges() {
188
188
  if (originalCopy) {
189
189
  this.set(originalCopy, { resetting: true });
190
- this.rows.forEach((r) => r.reset());
190
+ this.rows.forEach((r) => r.revertChanges());
191
191
  }
192
192
  },
193
- save() {
194
- this.rows.forEach((r) => {
195
- r.save();
196
- });
193
+ commitChanges() {
194
+ this.rows.forEach((r) => r.commitChanges());
197
195
  originalCopy = [...(parentInstance[key] || [])];
198
196
  _tick.value++;
199
197
  },
@@ -132,12 +132,12 @@ function newObjectState(config, parentState, parentListState, instance, key, may
132
132
  });
133
133
  },
134
134
  // Resets all fields back to their original values
135
- reset() {
136
- getFields(this).forEach((f) => f.reset());
135
+ revertChanges() {
136
+ getFields(this).forEach((f) => f.revertChanges());
137
137
  },
138
138
  // Saves all current values into _originalValue
139
- save() {
140
- getFields(this).forEach((f) => f.save());
139
+ commitChanges() {
140
+ getFields(this).forEach((f) => f.commitChanges());
141
141
  },
142
142
  // Create a result that is only populated with changed keys
143
143
  get changedValue() {
@@ -33,9 +33,9 @@ export interface FieldState<T, V> {
33
33
  maybeAutoSave(): void;
34
34
  set(value: V, opts?: SetOpts): void;
35
35
  /** Reverts back to the original value and resets dirty/touched. */
36
- reset(): void;
36
+ revertChanges(): void;
37
37
  /** Accepts the current changed value (if any) as the original and resets dirty/touched. */
38
- save(): void;
38
+ commitChanges(): void;
39
39
  }
40
40
  /** Public options for our `set` command. */
41
41
  export interface SetOpts {
@@ -118,13 +118,13 @@ function newValueFieldState(parentInstance, parentState, key, rules, isIdKey, is
118
118
  this.maybeAutoSave();
119
119
  }
120
120
  },
121
- reset() {
121
+ revertChanges() {
122
122
  if (!computed) {
123
123
  this.set(this.originalValue, { resetting: true });
124
124
  }
125
125
  this.touched = false;
126
126
  },
127
- save() {
127
+ commitChanges() {
128
128
  if (is_plain_object_1.isPlainObject(this.originalValue)) {
129
129
  this.originalValue = mobx_1.toJS(this.value);
130
130
  }
@@ -452,7 +452,7 @@ describe("formState", () => {
452
452
  a1.set({ firstName: "first" });
453
453
  expect(maybeAutoSave).toBeCalledTimes(1);
454
454
  // When we reset
455
- a1.reset();
455
+ a1.revertChanges();
456
456
  // We don't call blur again
457
457
  expect(maybeAutoSave).toBeCalledTimes(1);
458
458
  });
@@ -541,7 +541,7 @@ describe("formState", () => {
541
541
  a1.books.add({ title: "b3" });
542
542
  expect(a1.books.touched).toEqual(true);
543
543
  expect(a1.dirty).toBeTruthy();
544
- a1.reset();
544
+ a1.revertChanges();
545
545
  expect(a1.firstName.value).toBe("a1");
546
546
  expect(a1.firstName.touched).toBeFalsy();
547
547
  expect(a1.lastName.value).toBe("aL1");
@@ -577,7 +577,7 @@ describe("formState", () => {
577
577
  // And the "readOnly=true" operation has "beat" the reset operation
578
578
  a1.readOnly = true;
579
579
  // When we reset
580
- a1.reset();
580
+ a1.revertChanges();
581
581
  // Then it still works
582
582
  expect(a1.firstName.value).toBe("a1");
583
583
  expect(a1.firstName.touched).toBeFalsy();
@@ -607,15 +607,15 @@ describe("formState", () => {
607
607
  a1.books.rows[1].set({ title: "bb3" });
608
608
  // verify ValueFieldState is dirty, then save, then no longer dirty.
609
609
  expect(a1.firstName.dirty).toBeTruthy();
610
- a1.firstName.save();
610
+ a1.firstName.commitChanges();
611
611
  expect(a1.firstName.dirty).toBeFalsy();
612
612
  // verify ListFieldState is dirty, then save, then no longer dirty.
613
613
  expect(a1.books.dirty).toBeTruthy();
614
- a1.books.save();
614
+ a1.books.commitChanges();
615
615
  expect(a1.books.dirty).toBeFalsy();
616
616
  // Verify the remaining form is still dirty
617
617
  expect(a1.dirty).toBeTruthy();
618
- a1.save();
618
+ a1.commitChanges();
619
619
  // Verify after save the whole form is no longer dirty.
620
620
  expect(a1.dirty).toBeFalsy();
621
621
  });
@@ -839,7 +839,7 @@ describe("formState", () => {
839
839
  expect(a.books.rows[1].readOnly).toBeFalsy();
840
840
  expect(a.books.rows[1].title.readOnly).toBeFalsy();
841
841
  // And reset does not blow up
842
- a.reset();
842
+ a.revertChanges();
843
843
  });
844
844
  it("can set nested values when original null", () => {
845
845
  const a = createAuthorWithAddressInputState({ address: null });
@@ -894,7 +894,7 @@ describe("formState", () => {
894
894
  expect(formState.fullName.value).toEqual("first last");
895
895
  formState.firstName.value = "change";
896
896
  expect(formState.fullName.value).toEqual("change last");
897
- formState.reset();
897
+ formState.revertChanges();
898
898
  expect(formState.firstName.value).toEqual("first");
899
899
  });
900
900
  it("can set computeds that have setters", () => {
@@ -907,7 +907,7 @@ describe("formState", () => {
907
907
  expect(formState.firstName.value).toEqual("Bob");
908
908
  formState.fullName.set("Fred Smith");
909
909
  expect(formState.firstName.value).toEqual("Fred");
910
- formState.reset();
910
+ formState.revertChanges();
911
911
  expect(formState.firstName.value).toEqual("first");
912
912
  });
913
913
  it("can mark fields as read only", () => {
@@ -920,7 +920,7 @@ describe("formState", () => {
920
920
  expect(formState.fullName.readOnly).toEqual(true);
921
921
  formState.firstName.value = "change";
922
922
  expect(formState.fullName.value).toEqual("change last");
923
- formState.reset();
923
+ formState.revertChanges();
924
924
  expect(formState.firstName.value).toEqual("first");
925
925
  });
926
926
  it("lets rules validate against other fields", () => {
@@ -1300,7 +1300,7 @@ describe("formState", () => {
1300
1300
  // Then the list state is dirty
1301
1301
  expect(a1.books.dirty).toBeTruthy();
1302
1302
  // When saving the form state
1303
- a1.save();
1303
+ a1.commitChanges();
1304
1304
  // Then the list is no longer dirty
1305
1305
  expect(a1.books.dirty).toBeFalsy();
1306
1306
  // When adding a new book
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/form-state",
3
- "version": "2.12.0",
3
+ "version": "2.13.0",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",