javascript - Does immutable work with react to improve performance?
学习ing2017-07-05 10:38:52
0
3
842
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
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')
}
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 attributes
const obj = {a: 1, b: 2, c: 3}
Normal way:
immutable:
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