diff --git a/src/flags.luau b/src/flags.luau index 962301d..1b9f80e 100644 --- a/src/flags.luau +++ b/src/flags.luau @@ -1 +1,7 @@ -return { strict = false } +local function inline_test(): string + return debug.info(1, "n") +end + +local is_O2 = inline_test() ~= "inline_test" + +return { strict = not is_O2 } diff --git a/src/init.luau b/src/init.luau index 84d2ae4..62b6281 100644 --- a/src/init.luau +++ b/src/init.luau @@ -91,28 +91,22 @@ local vide = { end } -do - local set = false - - setmetatable(vide :: any, { - __index = function(_, index: unknown): () - if index == "strict" then - return flags.strict - else - throw(`{tostring(index)} is not a valid member of vide`) - end - end, - - __newindex = function(_, index: unknown, value: unknown) - if index == "strict" then - if set then throw "strict mode has already been set" end - set = true - flags.strict = value :: boolean - else - throw(`{tostring(index)} is not a valid member of vide`) - end +setmetatable(vide :: any, { + __index = function(_, index: unknown): () + if index == "strict" then + return flags.strict + else + throw(`{tostring(index)} is not a valid member of vide`) end - }) -end + end, + + __newindex = function(_, index: unknown, value: unknown) + if index == "strict" then + flags.strict = value :: boolean + else + throw(`{tostring(index)} is not a valid member of vide`) + end + end +}) return vide diff --git a/test/benchmark.luau b/test/benchmark.luau index 6702235..ca9c436 100644 --- a/test/benchmark.luau +++ b/test/benchmark.luau @@ -9,6 +9,8 @@ local values = vide.values local cleanup = vide.cleanup local create = vide.create +assert(not vide.strict) + local function TITLE(name: string) print() print(testkit.color.white(name)) diff --git a/test/tests.luau b/test/tests.luau index b0e7e67..a12df38 100644 --- a/test/tests.luau +++ b/test/tests.luau @@ -31,6 +31,8 @@ end local NIL = nil :: any +vide.strict = false + TEST("graph", function() local create_node = graph.create_node local track = graph.track @@ -1644,6 +1646,8 @@ TEST("changed()", wrap_root(function() end end)) +vide.strict = true + TEST("strict", wrap_root(function() vide.strict = true diff --git a/todo.md b/todo.md index bac72b2..5b9fc47 100644 --- a/todo.md +++ b/todo.md @@ -1,16 +1,13 @@ # todo -- auto-enable of strict mode depending on compiler optimizaton level - property binding optimization - would no longer allow `cleanup()` usage in binding scopes - solution to nested reactivity, see: SolidJS stores -- investigate performance of wide graphs -- optimize child removal +- optimize wide graph updating - implement from solid: - Portal - batch - optimize `indexes()` double-diffing - define behavior of deriving a source within a derived source -- review destruction of node under a root that has a child in another root -- check in strict mode for forgetting to call constructor `create(class)` +- define behavior of node destruction under a root that has a child in another root - improve crash course, some sections feel like information dumps