Skip to content

Commit

Permalink
Add perf optimizations to Injector
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Jun 6, 2015
1 parent 0d5c79a commit b70739a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Injector.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, PropTypes } from 'react';
import mapValues from 'lodash/object/mapValues';
import shallowEqual from './utils/shallowEqual';

export default class Injector extends Component {
static contextTypes = {
Expand All @@ -17,6 +18,15 @@ export default class Injector extends Component {
actions: {}
};

shouldComponentUpdate(nextProps, nextState) {
return this.hasChanged(this.state.atom, nextState.atom) ||
!shallowEqual(this.props.actions, nextProps.actions);
}

hasChanged(atom, prevAtom) {
return atom !== prevAtom;
}

constructor(props, context) {
super(props, context);

Expand Down
5 changes: 5 additions & 0 deletions src/addons/inject.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import Injector from '../Injector';
import getDisplayName from '../utils/getDisplayName';
import shallowEqualScalar from '../utils/shallowEqualScalar';

function mergeAll({ props, state, actions }) {
return { ...props, ...state, ...actions };
Expand All @@ -13,6 +14,10 @@ export default function inject(
return DecoratedComponent => class InjectorDecorator {
static displayName = `Injector(${getDisplayName(DecoratedComponent)})`;

shouldComponentUpdate(nextProps) {
return !shallowEqualScalar(this.props, nextProps);
}

constructor() {
this.renderChild = this.renderChild.bind(this);
}
Expand Down

0 comments on commit b70739a

Please sign in to comment.