mirror of
https://github.com/centau/vide.git
synced 2026-08-20 23:01:37 +00:00
Echo initial value if given a source
This commit is contained in:
parent
1a1b4d9f39
commit
6b465280eb
2 changed files with 11 additions and 1 deletions
|
|
@ -9,6 +9,10 @@ local update = graph.update
|
||||||
export type Source<T> = (() -> T) & ((T) -> T)
|
export type Source<T> = (() -> T) & ((T) -> T)
|
||||||
|
|
||||||
local function source<T>(initial_value: T): Source<T>
|
local function source<T>(initial_value: T): Source<T>
|
||||||
|
if type(initial_value) == "function" then
|
||||||
|
return initial_value
|
||||||
|
end
|
||||||
|
|
||||||
local node = create_start_node(initial_value)
|
local node = create_start_node(initial_value)
|
||||||
|
|
||||||
return function(...): T
|
return function(...): T
|
||||||
|
|
@ -28,4 +32,4 @@ local function source<T>(initial_value: T): Source<T>
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return source :: (<T>(initial_value: T) -> Source<T>) & (<T>() -> Source<T>)
|
return source :: (<T>(source: Source<T>) -> Source<T>) & (<T>(initial_value: T) -> Source<T>) & (<T>() -> Source<T>)
|
||||||
|
|
|
||||||
|
|
@ -359,6 +359,12 @@ TEST("source()", wrap_root(function()
|
||||||
CHECK(src() == 2)
|
CHECK(src() == 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
do CASE "echo if value is a source"
|
||||||
|
local a = source(1)
|
||||||
|
local b = source(a)
|
||||||
|
CHECK(a == b)
|
||||||
|
end
|
||||||
|
|
||||||
do CASE "does not update if same value"
|
do CASE "does not update if same value"
|
||||||
local src = source(1)
|
local src = source(1)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue