refactor: rename Source to Molecule

This commit is contained in:
Richard 2024-03-29 11:47:46 -07:00
parent f2ec300204
commit 0046af5598
11 changed files with 60 additions and 50 deletions

View file

@ -1,5 +1,6 @@
local store = require(script.Parent.store)
local types = require(script.Parent.types)
local unwrap = require(script.Parent.unwrap)
type Atom<T> = types.Atom<T>
type AtomOptions<T> = types.AtomOptions<T>
@ -15,7 +16,14 @@ local function atom<T>(state: T, options: AtomOptions<T>?): Atom<T>
return state
end
local nextState = if type(...) == "function" then (...)(state) else ...
local nextState = ...
if type(nextState) == "function" then
-- Atoms called in a function should not be included as dependencies
nextState = unwrap(function()
return nextState(state)
end)
end
if state ~= nextState and not (equals and equals(state, nextState)) then
state = nextState