4 ms·
Svelte seems promising. I think it's a natural evolution from what I think is an over focus on FP and purity in React, to a more natural and intuitive DX withou
by erokar 7y ago
Svelte seems promising. I think it's a natural evolution from what I think is an over focus on FP and purity in React, to a more natural and intuitive DX without significant drawbacks.
Svelte does have an irritating wart IMO, citing their tutorial:
Because Svelte's reactivity is triggered by assignments, using array
methods like push and splice won't automatically cause updates.
So for reference types that are mutated in place you need to do something like:
numbers.push(numbers.length + 1);
numbers = numbers;
Or:
numbers = [...numbers, numbers.length + 1];
This looks like a leaky abstraction to me since it forces the developer to work according to the implementation details. Don't know how easy it would be to fix this.
- desdiv 7y agoI'm a huge fan of persistent data structures such as those implemented by immutable.js. The "normal" way that I would update an immutable.js List is just: numbers = numbers.push(numbers.length + 1); Maybe it's just a coincidence, but Svelte seems awfully congruent with the pure FP way of doing things.
- mb7733 7y agoTo 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.