vinum-team / Vinum

A modern reactive state management library for correctness and speed.
MIT License
16 stars 1 forks source link

State Reflection #5

Closed sinlerdev closed 1 year ago

sinlerdev commented 1 year ago

Sometimes, we need to "mirror" a specific state objects directly, without another state object to base results of. This is where "state reflection" comes into play.

It's exactly the same as state mirroring (see #1), though the difference is that we are directly reflecting a state object value, instead of mirroring it via absorbing its value.

I.e:

local state = hold(100, Vinum.JustOk)
local reflectedState = Reflect(state) -- all changes transmitted to state will also be sent to reflectedState

reflectedState:set(13) -- errors, and the set method doesn't exist at all

As you can see, state reflection can be used to create a reflected version of a state object that is publicly immutable.