feat: add batch()

This commit is contained in:
Richard 2024-04-19 01:01:57 -07:00
parent 8a0d0977ca
commit f0a7938703
13 changed files with 112 additions and 52 deletions

View file

@ -4,19 +4,32 @@ type WeakMap<K, V> = types.WeakMap<K, V>
local listeners: WeakMap<Atom<any>, WeakMap<() -> (), unknown>> = setmetatable({}, { __mode = "k" })
local captured: { [Atom<any>]: true } = {}
local batched: { [Atom<any>]: true } = {}
local capturing = false
local batching = false
local function setCapturing(value: boolean)
capturing = value
end
local function shouldCapture()
local function isCapturing()
return capturing
end
local function setBatching(value: boolean)
batching = value
end
local function isBatching()
return batching
end
return {
listeners = listeners,
captured = captured,
batched = batched,
setCapturing = setCapturing,
shouldCapture = shouldCapture,
isCapturing = isCapturing,
setBatching = setBatching,
isBatching = isBatching,
}