Skip to content

Commit fe92a23

Browse files
committed
fix: allow setting null and undefined values with curried version of setValue
1 parent f358366 commit fe92a23

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
## ngrx-forms Changelog
22

3+
<a name="3.0.4"></a>
4+
### 3.0.4
5+
6+
#### Bugfixes
7+
8+
* allow setting `null` and `undefined` values with curried version of `setValue`, thanks @chrissena for reporting this bug, closes [#116](https://github.com/MrWolfZ/ngrx-forms/issues/116)
9+
310
<a name="3.0.3"></a>
411
### 3.0.3
512

src/state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ export type FormState<T> = InferredFormState<InferenceWrapper<T>>;
560560
* This function determines if a value is a form state.
561561
*/
562562
export function isFormState<TValue = any>(state: any): state is FormState<TValue> {
563-
return state.hasOwnProperty('id') && state.hasOwnProperty('value') && state.hasOwnProperty('errors');
563+
return !!state && state.hasOwnProperty('id') && state.hasOwnProperty('value') && state.hasOwnProperty('errors');
564564
}
565565

566566
/**

src/update-function/set-value.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,25 @@ describe(setValue.name, () => {
5252

5353
expect(resultState).not.toEqual(INITIAL_STATE);
5454
});
55+
56+
it('should support setting null value curried', () => {
57+
const resultState = setValue<string | null>(null)(INITIAL_STATE.controls.inner);
58+
expect(resultState).not.toBe(INITIAL_STATE.controls.inner);
59+
});
60+
61+
it('should support setting null value uncurried', () => {
62+
const resultState = setValue<string | null>(INITIAL_STATE.controls.inner, null);
63+
expect(resultState).not.toBe(INITIAL_STATE.controls.inner);
64+
});
65+
66+
it('should support setting undefined value curried', () => {
67+
const resultState = setValue<string | undefined>(undefined)(INITIAL_STATE.controls.inner);
68+
expect(resultState).not.toBe(INITIAL_STATE.controls.inner);
69+
});
70+
71+
it('should support setting undefined value uncurried', () => {
72+
const resultState = setValue<string | undefined>(INITIAL_STATE.controls.inner, undefined);
73+
expect(resultState).not.toBe(INITIAL_STATE.controls.inner);
74+
});
75+
5576
});

0 commit comments

Comments
 (0)