From f1153fe2b2bf7da1376061682533db25bfacc948 Mon Sep 17 00:00:00 2001 From: nighca Date: Sat, 7 Dec 2019 21:48:30 +0800 Subject: [PATCH 1/2] fix bug when onChange with same value --- src/fieldState.spec.ts | 16 ++++++++++++++++ src/fieldState.ts | 4 +++- 2 files changed, 19 insertions(+), 1 deletion(-) 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) + } } /** From 9fc27e426f742fa153f039a3b65b8042353f5579 Mon Sep 17 00:00:00 2001 From: nighca Date: Sat, 7 Dec 2019 21:53:32 +0800 Subject: [PATCH 2/2] v1.0.6 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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",