Improve error messages for derived sources

There seemed to be confusion over reactive-scoping (likely due to
incomplete docs), so I've added more explicit error messages when
deriving in non-reactive scopes to warn the user to use `root()` or
`mount()`.
This commit is contained in:
aaron 2023-09-18 09:40:54 +01:00
parent d13f66a1e1
commit c4a0180a2f
9 changed files with 31 additions and 42 deletions

View file

@ -10,7 +10,7 @@ local create_start_node = graph.create_start_node
local set_owner = graph.set_owner
local track = graph.track
local update = graph.update
local get_scope = graph.get_scope
local get_owning_scope = graph.get_owning_scope
local open_scope = graph.open_scope
local close_scope = graph.close_scope
local evaluate_node = graph.evaluate_node
@ -28,10 +28,7 @@ local function check_primitives(t: {})
end
local function indexes<K, VI, VO>(input: () -> Map<K, VI>, transform: (() -> VI, K) -> VO): () -> { VO }
local owner = get_scope()
if not owner then
throw("cannot derive in non-reactive scope")
end; assert(owner)
local owner = get_owning_scope()
local subowner = create_node(false, false)
set_owner(subowner, owner)
@ -125,10 +122,7 @@ local function indexes<K, VI, VO>(input: () -> Map<K, VI>, transform: (() -> VI,
end
local function values<K, VI, VO>(input: () -> Map<K, VI>, transform: (VI, () -> K) -> VO): () -> { VO }
local owner = get_scope()
if not owner then
throw("cannot derive in non-reactive scope")
end; assert(owner)
local owner = get_owning_scope()
local subowner = create_node(false, false)
set_owner(subowner, owner)