Search code examples
statesveltemobx

Different between svelte global store and mobx store


import {writable, derived} from 'svelte/store'

What is exact different between svelte store and mobx state management library?


Solution

  • There are many differences between the two libraries, but mobx is definitely a lot more sophisticated (and complicated!). This doesn't mean that mobx should be used as a replacement for svelte/store as svelte's store library is tightly integrated with svelte, for example:

    import { someStore } from "$lib/file"; 
    
    // you can get the value of stores reactively in .svelte files with $
    $: number = $someStore * 5
    

    Conceptually, however, there are many similarities:

    • "Computed" values in mobx are similar to svelte derived
    • Svelte's "writable" is comparable to mobx's classes fields
    • (As far as I know) there is no readable in mobx and it's recommended to use external side effects