3 ms·
To be fair, React has the same "wart". React is not guaranteed to work properly if you do: numbers = this.state.numbers; numbers.push(numbers.length + 1);
by mb7733 7y ago
To be fair, React has the same "wart". React is not guaranteed to work properly if you do:
numbers = this.state.numbers;
numbers.push(numbers.length + 1);
this.setState({ numbers: numbers });
React docs here: https://reactjs.org/tutorial/tutorial.html#why-immutability-is-important https://reactjs.org/tutorial/tutorial.html#why-immutability-...
Similar docs for redux: https://redux.js.org/recipes/structuring-reducers/immutable-update-patterns https://redux.js.org/recipes/structuring-reducers/immutable-...
There's no good way around it without doing deep equality checks everywhere which is not reasonable.
- erokar 7y agoSince Svelte is a compiler I was thinking they could wrap the exported variables in an observable of some sort and make any method call on the reference variable trigger a value update behind the scenes. I have now idea how costly/complex that would be though. Also, maybe it's a conscious choice and they want to make any data update explicit with reassignment.