Skip to content

Commit

Permalink
v0.6.0: + immutableComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
RubaXa committed Jun 17, 2016
1 parent 928ec5b commit 2e39552
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-octavius",
"version": "0.5.0",
"version": "0.6.0",
"private": true,
"description": "Боль и унижение!",
"main": "index.js",
Expand Down
2 changes: 2 additions & 0 deletions src/components/LettersItem.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import classNames from 'classnames';
import React, {Component} from 'react';
import immutableComponent from '../decorators/immutableComponent';

import Avatar from './Avatar';
import Button from './Button';
Expand All @@ -26,6 +27,7 @@ function letterTime(time) {
}
}

@immutableComponent(['model', 'selected'])
export default class LettersItem extends Component {
render() {
const {model, selected, onToggleSelect} = this.props;
Expand Down
18 changes: 18 additions & 0 deletions src/decorators/immutableComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React, {Component} from 'react';
import shallowEqual from 'react-redux/lib/utils/shallowEqual';

export default function immutableComponent(propKeys) {
return (DecoratedComponent) => class ImmutableComponentDecorator extends Component {
shouldComponentUpdate(nextProps) {
if (propKeys) {
return propKeys.some(name => this.props[name] !== nextProps[name]);
} else {
return !shallowEqual(this.props, nextProps);
}
}

render() {
return <DecoratedComponent {...this.props} />;
}
};
};
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import {Provider } from 'react-redux';
import ReactDOM from 'react-dom';
import React from 'react';

// DevPerf
import ReactFeatureFlags from 'react/lib/ReactFeatureFlags';
ReactFeatureFlags.logTopLevelRenders = true;

import App from './components/App';
import configure from './store';

Expand Down

0 comments on commit 2e39552

Please sign in to comment.