JSFiddle - React, Tailwind, and code Playground

by ramnathv

HTML

<script src="//npmcdn.com/[email protected]/lib/mobx.umd.js"></script>

Babel + JSX

const { observable, computed, extendObservable, autorun, createTransformer } = mobx;


var state = "";
// custom serialization of store to save state
const serializeState = createTransformer(state => ({
  x: state.x.toJSON(),
  y: state.y
}))
class Store {
  @observable x = [{x: 1}, {x: 2}]
  @observable y = "Hello"
  constructor(){
    autorun(() => {
      state = serializeState(this)
      console.log(JSON.stringify(state))
    })
  }
}



const store = new Store()
store.x.push({x: 6})
store.x[0] = {x: 3}
store.y = "New"