import * as mst from 'mobx-state-tree'; import * as _ from "lodash"; import * as THREE from "three"; const Todo = mst.types.model("Todo", { title: mst.types.maybe(mst.types.string), done: false }, { toggle() { this.done = !this.done }, setTitile(title: string) { this.title = title; } }) type iTodo = typeof Todo.Type const Store = mst.types.model("Store", { todos: mst.types.array(Todo) }, { add(todo: iTodo | Object) { this.todos.push(todo) } } ) // create an instance from a snapshot const store = Store.create( { todos: [{ title: "ggg" }] } ) let oldStore = mst.getSnapshot(store) store.todos[0].setTitile("hello1") mst.applySnapshot(store, oldStore); let paths = []; mst.onPatch(store, p => { let path; path = p; paths.push(path); }, true) store.todos[0].setTitile("hh"); store.todos[0].setTitile("123"); store.todos[0].setTitile("456"); store.todos[0].setTitile("hhh"); store.todos[0].setTitile("ggg"); console.log(paths); mst.revertPatch(store, _.last(paths)) console.log('_.last(paths): ', _.last(paths)); console.log(mst.getSnapshot(store)); console.log(paths);