From d2d9b218643a36e75c5485ce00379ad197f9a9a0 Mon Sep 17 00:00:00 2001 From: Martin V Date: Sat, 8 May 2021 21:34:18 +0200 Subject: [PATCH] v2.3.2 (#130) * Remove shallow compare, only rely on date prop * Fix prettier * Bump version number --- package.json | 2 +- src/Countdown.test.tsx | 22 +++++++++++----------- src/Countdown.tsx | 25 ++++--------------------- 3 files changed, 16 insertions(+), 33 deletions(-) diff --git a/package.json b/package.json index 2c73ede..b18caae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-countdown", - "version": "2.3.1", + "version": "2.3.2", "description": "A customizable countdown component for React.", "main": "./dist/index.js", "module": "./dist/index.es.js", diff --git a/src/Countdown.test.tsx b/src/Countdown.test.tsx index 3dca132..f76d23f 100644 --- a/src/Countdown.test.tsx +++ b/src/Countdown.test.tsx @@ -178,7 +178,7 @@ describe('', () => { expect(api.isCompleted()).toBe(true); }); - it('should only re-set time delta state when props have changed', () => { + it('should only reset time delta state when date prop is changing', () => { const root = document.createElement('div'); wrapper = mount(, { attachTo: root }); const obj = wrapper.instance(); @@ -192,22 +192,22 @@ describe('', () => { expect(obj.setTimeDeltaState).toHaveBeenCalledTimes(1); wrapper.setProps(mergeProps({ intervalDelay: 999 })); - expect(obj.setTimeDeltaState).toHaveBeenCalledTimes(2); + expect(obj.setTimeDeltaState).toHaveBeenCalledTimes(1); wrapper.setProps(mergeProps({ date: 500 })); - expect(obj.setTimeDeltaState).toHaveBeenCalledTimes(2); - - wrapper.setProps(mergeProps({ precision: NaN })); - expect(obj.setTimeDeltaState).toHaveBeenCalledTimes(3); - - wrapper.setProps(mergeProps({ precision: NaN })); - expect(obj.setTimeDeltaState).toHaveBeenCalledTimes(3); + expect(obj.setTimeDeltaState).toHaveBeenCalledTimes(1); wrapper.setProps(mergeProps({ precision: 3 })); - expect(obj.setTimeDeltaState).toHaveBeenCalledTimes(4); + expect(obj.setTimeDeltaState).toHaveBeenCalledTimes(1); wrapper.setProps(mergeProps({ date: 750 })); - expect(obj.setTimeDeltaState).toHaveBeenCalledTimes(5); + expect(obj.setTimeDeltaState).toHaveBeenCalledTimes(2); + + wrapper.setProps(mergeProps({ children:
})); + expect(obj.setTimeDeltaState).toHaveBeenCalledTimes(2); + + wrapper.setProps(mergeProps({ date: 1000 })); + expect(obj.setTimeDeltaState).toHaveBeenCalledTimes(3); }); it('should not (try to) set state after component unmount', () => { diff --git a/src/Countdown.tsx b/src/Countdown.tsx index 08845d7..cdf8b2d 100644 --- a/src/Countdown.tsx +++ b/src/Countdown.tsx @@ -144,12 +144,10 @@ export default class Countdown extends React.Component { - const valueA = objA[keyA]; - const valueB = objB[keyA]; - return ( - !objB.hasOwnProperty(keyA) || - !(valueA === valueB || (valueA !== valueA && valueB !== valueB)) // NaN !== NaN - ); - }) - ); - } - handleOnComplete = (timeDelta: CountdownTimeDelta): void => { if (this.props.onComplete) this.props.onComplete(timeDelta); };