Skip to content

Commit

Permalink
eager init of _renderCallbacks to avoid checks on it (#1113)
Browse files Browse the repository at this point in the history
  • Loading branch information
valotas authored and marvinhagemeister committed May 28, 2018
1 parent 78ce6cd commit feb96b5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export function Component(props, context) {
* @type {object}
*/
this.state = this.state || {};

this._renderCallbacks = [];
}


Expand Down Expand Up @@ -61,7 +63,7 @@ extend(Component.prototype, {
let s = this.state;
if (!this.prevState) this.prevState = extend({}, s);
extend(s, typeof state==='function' ? state(s, this.props) : state);
if (callback) (this._renderCallbacks = (this._renderCallbacks || [])).push(callback);
if (callback) this._renderCallbacks.push(callback);
enqueueRender(this);
},

Expand All @@ -73,7 +75,7 @@ extend(Component.prototype, {
* @private
*/
forceUpdate(callback) {
if (callback) (this._renderCallbacks = (this._renderCallbacks || [])).push(callback);
if (callback) this._renderCallbacks.push(callback);
renderComponent(this, FORCE_RENDER);
},

Expand Down
4 changes: 1 addition & 3 deletions src/vdom/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ export function renderComponent(component, opts, mountAll, isChild) {
if (options.afterUpdate) options.afterUpdate(component);
}

if (component._renderCallbacks!=null) {
while (component._renderCallbacks.length) component._renderCallbacks.pop().call(component);
}
while (component._renderCallbacks.length) component._renderCallbacks.pop().call(component);

if (!diffLevel && !isChild) flushMounts();
}
Expand Down

0 comments on commit feb96b5

Please sign in to comment.