Learn / Events, folds and gates

Events, folds and gates

Suppose your todo app syncs todos across devices while keeping filter ('all' or 'done') local to each device. You add a ClearedShown Message that checks model.filter inside update so it removes only the todos visible on screen.

On your laptop with filter: 'done', ClearedShown clears only completed items. On the server and on your phone, however, filter is local and not shared, so both replay ClearedShown with initial.filter ('all') and wipe out every todo in the list. When the synced state lands back on your laptop, your screen clears too.

That bug reveals the three rules behind shared state in Foldkit Plus:

  1. A replicated Message must carry the exact facts of what changed, never depend on unshared local state.
  2. State is whatever update leaves after folding Messages, starting from initial.
  3. Correctness is enforced at the server gate (authorize and laws), not by trusting the client's Message union.