centau / vide

A reactive Luau library for creating UI.
https://centau.github.io/vide/
MIT License
95 stars 16 forks source link

Implement values and indexes #1

Closed sirjahames closed 1 year ago

sirjahames commented 1 year ago

Implementation of values and indexes transform functions for state tables. @centau defined its use and functionality as related to the transformation and creation of new states.

local names = source({ "Eli", "Bobby" })

local frames = values(names , function(i, name)
    --> 'i' (index/key) remains constant and will not be transformed when values are returned
    return create("Frame") { Name = name }
end)

--> Results:
--> frames = { [1] = Eli (Instance), [2] = Bobby (Instance) }

local numbers = source({ 1, 2, 3, 4, 5 })

local multiples = indexes(numbers , function(i, v)
    --> 'v' (value) remains constant and will not be transformed when values are returned
    return tostring(i)
end)

--> Results:
--> multiples = { ["1"] = 1, ["2"] = 2, ["3"] = 3, ["4"] = 4 }
sirjahames commented 1 year ago

Added in commit: https://github.com/centau/vide/commit/e03082c941a0bf17f7170b39857b8ce7632ac2f4 Closing issue.