javascript - Does immutable work with react to improve performance?
学习ing
学习ing 2017-07-05 10:38:52
0
3
822

Wouldn’t it be enough to simply compare it with PureComponent?
I think it is rare that the state reference changes but the actual value does not change

学习ing
学习ing

reply all(3)
过去多啦不再A梦

I think the advantage of immutable is that it is immutable and the value will not be accidentally changed elsewhere. It can also be compared quickly without the need to check layer by layer.

学霸

I think immutable does have benefits. Immutability and comparison of two objects can improve performance to a certain extent. But this is more suitable for complex data structures and frequent data operations.
For general scenarios, it only increases the complexity and file size. For example, get the object attributesconst obj = {a: 1, b: 2, c: 3}

Normal way:

const {a, b, c} = obj;

immutable:

const a = obj.get('a');
const b = obj.get('b');
const c = obj.get('c');

And if it is a complex scenario, we will use redux, because the data processing of redux itself is immutable, so immutable is not applicable.

给我你的怀抱

Strictly speaking, converting immutable data will also cause performance losses.
The API is very convenient for comparison and modification of very deep data

reducer.js

[actions.UPDATE_PROJECT_LIST_AFTER_DELETE]: (state, { data }) => {
  let index = data.index
  return state.updateIn(['dataList',index,'status'], () => 'Deleted')
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!