mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
This commit is contained in:
parent
e776183452
commit
e35887f7d1
3 changed files with 23 additions and 27 deletions
|
|
@ -4,20 +4,20 @@ local create = require(script.Parent.create)
|
||||||
local graph = require(script.Parent.graph)
|
local graph = require(script.Parent.graph)
|
||||||
type Node<T> = graph.Node<T>
|
type Node<T> = graph.Node<T>
|
||||||
local create_node = graph.create_node
|
local create_node = graph.create_node
|
||||||
local get_stack_scope = graph.get_stack_scope
|
local get_scope = graph.get_scope
|
||||||
local open_scope = graph.open_scope
|
local open_scope = graph.open_scope
|
||||||
local close_scope = graph.close_scope
|
local close_scope = graph.close_scope
|
||||||
|
|
||||||
local non_tracking_scope = create_node(false)
|
|
||||||
|
|
||||||
local function untrack<T>(source: () -> T): T
|
local function untrack<T>(source: () -> T): T
|
||||||
local scope = get_stack_scope(1)
|
local scope = get_scope()
|
||||||
|
assert(scope)
|
||||||
|
|
||||||
open_scope(scope or non_tracking_scope)
|
local effect = scope.effect
|
||||||
|
scope.effect = false
|
||||||
|
|
||||||
local v = source()
|
local v = source()
|
||||||
|
|
||||||
close_scope()
|
scope.effect = effect :: () -> ()
|
||||||
|
|
||||||
return v
|
return v
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1062,7 +1062,7 @@ TEST("untrack()", wrap_root(function()
|
||||||
local a = source(0)
|
local a = source(0)
|
||||||
local b = source(0)
|
local b = source(0)
|
||||||
|
|
||||||
local count = -1
|
local count = 0
|
||||||
|
|
||||||
watch(function()
|
watch(function()
|
||||||
count += 1
|
count += 1
|
||||||
|
|
@ -1071,10 +1071,10 @@ TEST("untrack()", wrap_root(function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
b(1)
|
b(1)
|
||||||
CHECK(count == 1)
|
CHECK(count == 2)
|
||||||
|
|
||||||
a(1)
|
a(1)
|
||||||
CHECK(count == 1)
|
CHECK(count == 2)
|
||||||
|
|
||||||
CHECK(a() == untrack(a))
|
CHECK(a() == untrack(a))
|
||||||
end
|
end
|
||||||
|
|
@ -1088,7 +1088,7 @@ TEST("untrack()", wrap_root(function()
|
||||||
return a() + b()
|
return a() + b()
|
||||||
end
|
end
|
||||||
|
|
||||||
local count = -1
|
local count = 0
|
||||||
|
|
||||||
watch(function()
|
watch(function()
|
||||||
count += 1
|
count += 1
|
||||||
|
|
@ -1097,11 +1097,11 @@ TEST("untrack()", wrap_root(function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
c(1)
|
c(1)
|
||||||
CHECK(count == 1)
|
CHECK(count == 2)
|
||||||
|
|
||||||
a(1)
|
a(1)
|
||||||
b(1)
|
b(1)
|
||||||
CHECK(count == 1)
|
CHECK(count == 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
do CASE "outer scope"
|
do CASE "outer scope"
|
||||||
|
|
@ -1141,16 +1141,19 @@ TEST("untrack()", wrap_root(function()
|
||||||
|
|
||||||
input(1)
|
input(1)
|
||||||
|
|
||||||
-- todo
|
CHECK(outer_count == 1)
|
||||||
CHECK(outer_count == 2)
|
CHECK(inner_count == 2)
|
||||||
CHECK(inner_count == 3)
|
|
||||||
CHECK(cleaned_count == 1)
|
CHECK(cleaned_count == 1)
|
||||||
|
|
||||||
local output3 = output()
|
local output3 = output()
|
||||||
CHECK(output2() == "1")
|
CHECK(output2() == "1")
|
||||||
CHECK(output3() == "1")
|
CHECK(output3() == "1")
|
||||||
|
|
||||||
CHECK(output2 ~= output3)
|
CHECK(output2 == output3)
|
||||||
|
|
||||||
|
destroy()
|
||||||
|
|
||||||
|
CHECK(cleaned_count == 2)
|
||||||
end
|
end
|
||||||
end))
|
end))
|
||||||
|
|
||||||
|
|
|
||||||
15
todo.md
15
todo.md
|
|
@ -3,22 +3,15 @@
|
||||||
- better error reporting and stack traces in strict mode
|
- better error reporting and stack traces in strict mode
|
||||||
- auto-enable of strict mode depending on compiler optimizaton level
|
- auto-enable of strict mode depending on compiler optimizaton level
|
||||||
- investigate if weak table iteration can be invalidated
|
- investigate if weak table iteration can be invalidated
|
||||||
- have derived sources/bindings track sources dynamically?
|
- define behavior of `cleanup()` in `untrack()` scopes
|
||||||
- solves case where sources are used in if-branching guarded by another
|
-
|
||||||
source
|
|
||||||
- significantly reduces performance
|
|
||||||
- solution to component cleanup
|
|
||||||
- rely on `Instance.Destroying` event and manual destruction when cleanup is
|
|
||||||
needed?
|
|
||||||
- expand behavior of `vide.cleanup()` to detect garbage collection of
|
|
||||||
arbitrary values, not needing manual destruction
|
|
||||||
- look into SolidJS's reactive contexts
|
|
||||||
- solution to nested reactivity, see: SolidJS stores
|
- solution to nested reactivity, see: SolidJS stores
|
||||||
- SolidJS control flow components
|
- SolidJS control flow components
|
||||||
- equality checking of derived sources
|
- equality checking of derived sources
|
||||||
|
- implement from solid:
|
||||||
- Show
|
- Show
|
||||||
- Switch
|
- Switch
|
||||||
- Dynamic
|
- Dynamic
|
||||||
- Portal
|
- Portal
|
||||||
- batch source updates
|
- batch
|
||||||
- optimize `indexes()` double-diffing
|
- optimize `indexes()` double-diffing
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue