mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
Add show()
This commit is contained in:
parent
c4a0180a2f
commit
d1da0b4ea5
2 changed files with 20 additions and 0 deletions
|
|
@ -15,6 +15,7 @@ local cleanup = require(script.cleanup)
|
|||
local untrack = require(script.untrack)
|
||||
local derive = require(script.derive)
|
||||
local switch = require(script.switch)
|
||||
local show = require(script.show)
|
||||
local indexes, values = require(script.maps)()
|
||||
local spring, update_springs = require(script.spring)()
|
||||
local action = require(script.action)()
|
||||
|
|
@ -51,6 +52,7 @@ local vide = {
|
|||
effect = effect,
|
||||
derive = derive,
|
||||
switch = switch,
|
||||
show = show,
|
||||
indexes = indexes,
|
||||
values = values,
|
||||
|
||||
|
|
|
|||
18
src/show.luau
Normal file
18
src/show.luau
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
if not game then script = require "test/relative-string" end
|
||||
|
||||
local switch = require(script.Parent.switch)
|
||||
|
||||
local function show<T>(source: () -> any, component: () -> T, fallback: (() -> T)?): () -> T?
|
||||
local function truthy()
|
||||
return not not source()
|
||||
end
|
||||
|
||||
return switch(truthy) {
|
||||
[true] = component,
|
||||
[false] = fallback,
|
||||
}
|
||||
end
|
||||
|
||||
return show ::
|
||||
(<T>(source: () -> any, component: () -> T) -> () -> T?) &
|
||||
(<T, U>(source: () -> any, component: () -> T, fallback: () -> U) -> () -> (T | U)?)
|
||||
Loading…
Add table
Add a link
Reference in a new issue