Skip to content

Commit b70739a

Browse files
committed
Add perf optimizations to Injector
1 parent 0d5c79a commit b70739a

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Injector.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Component, PropTypes } from 'react';
22
import mapValues from 'lodash/object/mapValues';
3+
import shallowEqual from './utils/shallowEqual';
34

45
export default class Injector extends Component {
56
static contextTypes = {
@@ -17,6 +18,15 @@ export default class Injector extends Component {
1718
actions: {}
1819
};
1920

21+
shouldComponentUpdate(nextProps, nextState) {
22+
return this.hasChanged(this.state.atom, nextState.atom) ||
23+
!shallowEqual(this.props.actions, nextProps.actions);
24+
}
25+
26+
hasChanged(atom, prevAtom) {
27+
return atom !== prevAtom;
28+
}
29+
2030
constructor(props, context) {
2131
super(props, context);
2232

src/addons/inject.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import Injector from '../Injector';
33
import getDisplayName from '../utils/getDisplayName';
4+
import shallowEqualScalar from '../utils/shallowEqualScalar';
45

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

17+
shouldComponentUpdate(nextProps) {
18+
return !shallowEqualScalar(this.props, nextProps);
19+
}
20+
1621
constructor() {
1722
this.renderChild = this.renderChild.bind(this);
1823
}

0 commit comments

Comments
 (0)