Learn / Events, folds and gates
Decide locally, store the fact
When foldkit-sync replays a durable Message on the server or on another device, it installs the shared slice (todos) into initial, runs update, and reads todos back. Every unshared field — like filter — starts at its initial value during replay.
| What a durable Message does | Result when submitted |
|---|---|
Returns a Command | Refused: live side effects cannot replay |
| Modifies a field outside the shared slice | Refused, naming the unshared field |
| Reads a field outside the shared slice | Accepted, but replay sees initial instead |
That third case is why ClearedShown deletes the wrong rows. Resolve local context on the device before creating the durable Message, and put the concrete ids inside ClearedTodos:
const clearShownMessage = (model: Model) => {
const shown = model.todos.filter(todo => model.filter === 'all' || todo.done)
return Message.ClearedTodos({ ids: shown.map(todo => todo.id) })
}Calling clearShownMessage with filter: 'done' over folded returns ClearedTodos({ ids: ['a'] }). Every replica now clears only 'a', regardless of its own local filter. The same rule applies to generated UUIDs and timestamps: create them once when building the intent, and store the resulting values inside the Message.