mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
add vide.mutate
This commit is contained in:
parent
fbe2f01bb9
commit
2c5461d602
2 changed files with 17 additions and 0 deletions
|
|
@ -16,6 +16,7 @@ local cleanup = require(script.cleanup)
|
||||||
local untrack = require(script.untrack)
|
local untrack = require(script.untrack)
|
||||||
local read = require(script.read)
|
local read = require(script.read)
|
||||||
local batch = require(script.batch)
|
local batch = require(script.batch)
|
||||||
|
local mutate = require(script.mutate)
|
||||||
local switch = require(script.switch)
|
local switch = require(script.switch)
|
||||||
local show = require(script.show)
|
local show = require(script.show)
|
||||||
local indexes, values = require(script.maps)()
|
local indexes, values = require(script.maps)()
|
||||||
|
|
@ -63,6 +64,7 @@ local vide = {
|
||||||
untrack = untrack,
|
untrack = untrack,
|
||||||
read = read,
|
read = read,
|
||||||
batch = batch,
|
batch = batch,
|
||||||
|
mutate = mutate,
|
||||||
|
|
||||||
-- animations
|
-- animations
|
||||||
spring = spring,
|
spring = spring,
|
||||||
|
|
|
||||||
15
src/mutate.luau
Normal file
15
src/mutate.luau
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
if not game then script = require "test/relative-string" end
|
||||||
|
|
||||||
|
local untrack = require(script.Parent.untrack)
|
||||||
|
|
||||||
|
local function mutate<T>(source: () -> T, mutate: (T) -> any?)
|
||||||
|
local value = untrack(source)
|
||||||
|
local packed = table.pack(mutate(value))
|
||||||
|
if packed.n > 0 then
|
||||||
|
return source(unpack(packed, 1, packed.n))
|
||||||
|
end
|
||||||
|
|
||||||
|
source(value)
|
||||||
|
end
|
||||||
|
|
||||||
|
return mutate
|
||||||
Loading…
Add table
Add a link
Reference in a new issue