diff --git a/package-lock.json b/package-lock.json index 751a2be..87d3c50 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "formstate-x", - "version": "1.0.5", + "version": "1.0.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 09e30db..1593982 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "formstate-x", - "version": "1.0.5", + "version": "1.0.6", "description": "Extended alternative for formstate", "repository": { "type": "git", diff --git a/src/fieldState.spec.ts b/src/fieldState.spec.ts index efa00bc..98a7ab9 100644 --- a/src/fieldState.spec.ts +++ b/src/fieldState.spec.ts @@ -158,6 +158,22 @@ describe('FieldState validation', () => { state.dispose() }) + it('should work well with onChange of same value', async () => { + const state = createFieldState(1).validators( + () => null + ) + await state.validate() + expect(state.validated).toBe(true) + expect(state.validating).toBe(false) + expect(state.hasError).toBe(false) + + state.onChange(1) + await delay() + expect(state.validated).toBe(true) + expect(state.validating).toBe(false) + expect(state.hasError).toBe(false) + }) + it('should work well with validate()', async () => { const state = createFieldState('').validators(val => !val && 'empty') state.validate() diff --git a/src/fieldState.ts b/src/fieldState.ts index d778d87..d234dc3 100644 --- a/src/fieldState.ts +++ b/src/fieldState.ts @@ -117,7 +117,9 @@ export default class FieldState extends Disposable implements Composible * Set `_value` on change event. */ @action onChange(value: TValue) { - this.setValue(value) + if (value !== this._value) { + this.setValue(value) + } } /**