【发布时间】:2016-07-06 01:06:06
【问题描述】:
将Immutable 与 React(以及可选的 Redux)一起使用有哪些优势?在 Redux 中,我可以简单地在我的 reducer 中使用 rest this 返回一个新状态:
const initialState = {
activeTrackId: '',
state: 'stopped',
};
export default function (state = initialState, action) {
switch (action.type) {
case actions.PROCESS_TRACK_ACTION:
return {
...state,
activeTrackId: action.state !== 'stopped' ? action.track._id : '',
state: action.state,
};
// ...
我发现它有用的唯一场景是:
shouldComponentUpdate(nextProps) {
const oldProps = Immutable.fromJS(this.props);
const newProps = Immutable.fromJS(nextProps);
return !Immutable.is(oldProps, newProps);
}
据我所知,这甚至可能是在滥用它。
也许有人可以告诉我在 React 和 Redux 的上下文中使用 Immutable 的优势?
【问题讨论】:
标签: reactjs redux immutable.js