mirror of
https://github.com/centau/vide.git
synced 2026-10-20 17:34:08 +00:00
Merge 446be23cfc into a4151bd41e
This commit is contained in:
commit
b448d26420
3 changed files with 13 additions and 1 deletions
|
|
@ -131,6 +131,8 @@ Creates a new context.
|
||||||
|
|
||||||
Calling `context()` returns a new context function.
|
Calling `context()` returns a new context function.
|
||||||
Call this function with no arguments to get the context value.
|
Call this function with no arguments to get the context value.
|
||||||
|
If no context is set, the default value is returned, or an error is thrown
|
||||||
|
if no default was given.
|
||||||
Call this function with a value and a function to create a new context with
|
Call this function with a value and a function to create a new context with
|
||||||
the given value.
|
the given value.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ local function context<T>(...: T): Context<T>
|
||||||
return (if value ~= nil_symbol then value else nil) :: T
|
return (if value ~= nil_symbol then value else nil) :: T
|
||||||
end
|
end
|
||||||
|
|
||||||
if has_default ~= nil then
|
if has_default then
|
||||||
return default_value
|
return default_value
|
||||||
else
|
else
|
||||||
error("attempt to get context when no context is set and no default context is set", 0)
|
error("attempt to get context when no context is set and no default context is set", 0)
|
||||||
|
|
|
||||||
|
|
@ -2769,6 +2769,16 @@ TEST("context()", function()
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
do CASE "get context without default"
|
||||||
|
local ctx = context()
|
||||||
|
|
||||||
|
CHECK(not pcall(ctx))
|
||||||
|
|
||||||
|
root(function()
|
||||||
|
CHECK(not pcall(ctx))
|
||||||
|
end)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
TEST("nested effects cases", function()
|
TEST("nested effects cases", function()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue