From 84acb58573aece47e68c5b0b6e0560e72d8be650 Mon Sep 17 00:00:00 2001 From: Mashy Date: Mon, 28 Oct 2019 19:01:22 +1000 Subject: [PATCH] move construct calls into componentDidUpdate, change shouldCompUpdate --- client/src/components/construct.jsx | 40 ++++++++++++----------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/client/src/components/construct.jsx b/client/src/components/construct.jsx index 3c2df336..19e9fd20 100644 --- a/client/src/components/construct.jsx +++ b/client/src/components/construct.jsx @@ -61,42 +61,36 @@ class ConstructAvatar extends Component { this.resetAnimations(); } - shouldComponentUpdate(newProps) { - const { animSource, animTarget, animText, construct } = newProps; - - if (construct !== this.props.construct) { - return true; - } - - if (animText && animText !== this.props.animText && animText.constructId === construct.id) { + componentDidUpdate(prevProps) { + const { animSource, animTarget, animText, construct } = this.props; + // a different text object and text construct + if (animText && animText !== prevProps.animText && animText.constructId === construct.id) { return wiggle(construct.id, this.idle); } - if (animSource === this.props.animSource && animTarget === this.props.animTarget) { - // console.warn(construct.name, 'thinks its same props') - return false; - } - - // something has changed - // what do? - - // this is the source - if (animSource && animSource.constructId === construct.id) { - // console.warn(construct.name, 'should update') + // different source object and source construct + if (animSource && animSource !== prevProps.animSource && animSource.constructId === construct.id) { return sourceCast(animSource.constructId, animSource.direction, this.idle); } - - // this is the target - if (animTarget && animTarget.constructId.includes(construct.id)) { - // console.warn(construct.name, 'should update') + // different target object and target construct + if (animTarget && animTarget !== prevProps.animTarget && animTarget.constructId.includes(construct.id)) { switch (animTarget.skill) { case 'Banish': return banish(construct.id, this.idle); case 'Invert': return invert(construct.id, this.idle); default: return null; } } + return true; + } + + shouldComponentUpdate(newProps) { + const { animSource, animTarget, animText, construct } = newProps; + if (animSource !== this.props.animSource) return true; + if (animTarget !== this.props.animTarget) return true; + if (animText !== this.props.animText) return true; + if (construct !== this.props.construct) return true; return false; } }