From a2f2070966e53df836dc1244bf958b263822b7da Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 30 Aug 2017 21:44:10 +0100 Subject: [PATCH] Put setSate in the promise constructor Avoids local variables. Also typo in comment. --- src/components/structures/TimelinePanel.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/components/structures/TimelinePanel.js b/src/components/structures/TimelinePanel.js index 1ef09e0719..862c3f46d0 100644 --- a/src/components/structures/TimelinePanel.js +++ b/src/components/structures/TimelinePanel.js @@ -345,19 +345,15 @@ var TimelinePanel = React.createClass({ } // Don't resolve until the setState has completed: we need to let - // the component update before we consider the pagination commpleted, + // the component update before we consider the pagination completed, // otherwise we'll end up paginating in all the history the js-sdk // has in memory because we never gave the component a chance to scroll // itself into the right place - let resolveSetStatePromise; - const setStatePromise = new Promise(function(resolve) { - resolveSetStatePromise = resolve; + return new Promise((resolve) => { + this.setState(newState, () => { + resolve(r); + }); }); - this.setState(newState, () => { - resolveSetStatePromise(r); - }); - - return setStatePromise; }); },