Home › Overview › MainModule › Flux
Store
Deep reactive stores: Flux.store(table) returns a proxy whose fields are tracked per key, with Flux.Store helpers for arrays, snapshots and teardown.
local state = Flux.store({ player = { hp = 100 } })
Flux.effect(function() print(state.player.hp) end)
state.player.hp = 90Functions
new
Store.new<T>(initialState: T): TWraps a plain table in a deep reactive proxy: reading a field inside a computed or effect subscribes to that field, and assigning a new value re-runs only the dependents of the leaves that changed. Nested plain tables are proxied recursively on access; metatable'd values (Flux nodes, class instances) stay atomic. Available as Flux.store.
Destroy
Store.Destroy<T>(proxy: T)Tears down a store and every nested proxy beneath it, destroying their per-key nodes so dependents stop tracking them; the proxy is left an empty plain table and the raw table is left intact. A store created inside a scope is torn down when the scope is destroyed; Flux.dispose performs the same cleanup. An unreferenced store is garbage-collected automatically; call this method only to disconnect its dependents early.
unwrap
Store.unwrap<T>(proxy: T): TReturns the raw, un-proxied table underlying a store: the live backing object, not a copy. Reads through it bypass tracking entirely (no node is subscribed), so use it for cheap snapshots or to hand a plain table to non-reactive code. Passing a value that is not a store returns it unchanged.
insert
Store.insert(proxy: any, posOrValue: any, value: any?)Reactive counterpart of table.insert: with no third argument, appends posOrValue to the end; with a third argument, inserts value at 1-based position posOrValue and shifts subsequent elements up. Use this instead of assigning past the array's length so iteration and # watchers fire and the shifted indices re-sync. An out-of-range position errors.
remove
Store.remove(proxy: any, pos: number?): anyReactive counterpart of table.remove: removes and returns the element at pos (default: the last), shifting subsequent elements down. Use this instead of proxy[i] = nil, which leaves a hole that corrupts the array part. An out-of-range pos errors.
move
Store.move(proxy: any, from: number, to: number)Reactively reorders the array, moving the element at 1-based index from to to and shifting the elements between them so positional readers and #/iteration watchers follow. Equivalent to a table.remove + table.insert but as a single tracked step: the length is unchanged, so nothing is removed and no nested proxy is torn down, ideal for drag-and-drop list reordering. Both indices must be in [1, #proxy]; an out-of-range index errors.
reconcile
Store.reconcile<T>(proxy: T, newData: T, key: string?): TDiffs the snapshot newData into the live store proxy, firing only the nodes whose leaves actually changed and reusing unchanged nested proxies instead of tearing them down. Arrays diff positionally by default; when key is given, array elements are matched by element[key] instead (recursively through every nested array), so reordered or inserted rows keep their proxy (and their Flux.forValue result) and only changed rows fire. newData should be a plain, acyclic snapshot. Returns proxy.