Settings

Theme

Show HN: MobX-Style Observables in Svelte

github.com

8 points by kewp 5 years ago · 4 comments

Reader

gedy 5 years ago

I love Mobx with React and also Svelte, but Svelte already has reactive and derived values? https://svelte.dev/tutorial/reactive-statements

Not clear what this solves or improves upon.

  • kewpOP 5 years ago

    Reactivity, yes - works the same as MobX's autorun. But not derived values. You can ensure something gets updated by wrapping it in $:

    ``` $: value = $x + 2 ```

    but you can do that somewhere else as well

    ``` $: { let y = 20 $value += y } ```

    Makes it insanely hard to track where changes come from. You can't say "this value is _only_ updated by these changes".

    You can do this with derived stores, though. But each store must be it's own, separate value - with MobX's observable you have a central object representing your entire state, each of which is made automatically reactive, and putting in a derived store is just prepending with -get-. It's much cleaner.

pier25 5 years ago

What's the point of this when Svelte already provides reactive primitives?

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection