How to use mst-middlewares - 2 common examples

To help you get started, we’ve selected a few mst-middlewares examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mobxjs / mobx-state-tree / packages / mst-example-todomvc / src / index.js View on Github external
function createTodoStore(snapshot) {
    // clean up snapshot listener
    if (snapshotListener) snapshotListener()
    // kill old store to prevent accidental use and run clean up hooks
    if (store) destroy(store)

    // create new one
    store = TodoStore.create(snapshot)

    // connect devtools
    connectReduxDevtools(require("remotedev"), store)
    // connect local storage
    snapshotListener = onSnapshot(store, snapshot =>
        localStorage.setItem(localStorageKey, JSON.stringify(snapshot))

    return store


The MST package ships with some prebuilt middlewares, which serves mainly as examples on how to write your own middleware. The source of each middleware can be found in this github directory, you are encouraged to read them!

Latest version published 4 months ago

Package Health Score

84 / 100
Full package analysis

Popular mst-middlewares functions