mikolalysenko / mudb

Low latency state replication for the web

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RDAMap.move problem

hediyi opened this issue · comments

const M = new MuRDAMap(new MuVarint(), new MuRDARegister(new MuVarint()))
const store = M.createStore({0: 0, 1: 1})
const dispatchers = M.action(store)

// { type: 'move', data: MuStruct { id: 1, key: 0, sequence: 2 } }
const mv = dispatchers.move(1, 0)
// { type: 'move', data: MuStruct { id: 2, key: 1, sequence: 1 } }
const mvi = store.inverse(M, mv)

store.apply(M, mv)
// { type: 'move', data: MuStruct { id: 2, key: 1, sequence: 1 } }
const mvr = dispatchers.move(0, 1)

The problem comes from we expect applying two identical action objects to the same state to result in different states. Since we're not supposed to touch the state when generating action objects or inverses, either mvi or mvr has to carry extra info to differentiate itself from the other.