vinum-team / Vinum

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

Mirror Object #1

Closed sinlerdev closed 1 year ago

sinlerdev commented 1 year ago

It could be nice to have a match-like object that inherits a state object's value, if its defined key matches the current inputState value.

i.e:


local root = Hold(100, JustOk)
local currentMirror = Mirror(root, {
    [100] = Hold("Fighter", JustOk),
    [200] = Hold("Leader", JustOk),
    ["default"] = Hold("Solider", JustOk)
}) 

print(currentMirror:get()) -- "Fighter"

This is useful in the case you just want to return different values depending on a state object's value. It is also important to note that this is kind of possible with Calc and Match (Match will likely behave the same), although either they will introduce boilerplate code (You need to write a function to just return a state object value), or they will cause unneeded updates

sinlerdev commented 1 year ago

implemented 44c34f8

Will be closed once Vinum V0.2 is released.