Example #1
0
File: store.js Project: AMCorvi/mob
export function initStore (isServer, snapshot = null) {
  if (isServer) {
    store = Store.create({ lastUpdate: Date.now() })
  }
  if (store === null) {
    store = Store.create({ lastUpdate: Date.now() })
  }
  if (snapshot) {
    applySnapshot(store, snapshot)
  }
  return store
}
export function generateStuff(amount) {
    runInAction(() => {
        for (var i = 0; i < amount; i++) {
            store.addBox(
                "#" + i,
                Math.random() * window.innerWidth * 0.5,
                Math.random() * window.innerHeight
            )
        }
        const allBoxes = store.boxes.values()
        for (var i = 0; i < amount; i++) {
            store.addArrow(
                allBoxes[Math.floor(Math.random() * allBoxes.length)],
                allBoxes[Math.floor(Math.random() * allBoxes.length)]
            )
        }
    })
}

/**
    Save / Restore the state of the store while self module is hot reloaded
*/
if (module.hot) {
    if (module.hot.data && module.hot.data.store) {
        applySnapshot(store, module.hot.data.store)
    }
    module.hot.dispose(data => {
        data.store = getSnapshot(store)
    })
}
Example #3
0
export function nextState() {
    if (currentFrame === states.length - 1) return
    currentFrame++
    applySnapshot(store, states[currentFrame])
}
Example #4
0
export function previousState() {
    if (currentFrame === 0) return
    currentFrame--
    applySnapshot(store, states[currentFrame])
}