feat: add flag for inner effect tracking

This commit is contained in:
littensy 2025-10-02 19:37:03 -07:00
parent 87e7260c16
commit 027c5bf8f8
4 changed files with 7 additions and 1 deletions

1
.gitignore vendored
View file

@ -8,5 +8,6 @@
node_modules
*.tsbuildinfo
*.rbxm
*.tgz
.DS_Store
roblox.d.luau

View file

@ -349,7 +349,7 @@ local function effect(fn: (dispose: () -> ()) -> ...(() -> ())?): () -> ()
cleanup = nil :: any,
}
self.cleanup = effectStop(self)
if activeSub then
if activeSub and config.trackInnerEffects then
link(self, activeSub)
elseif activeScope then
link(self, activeScope)

View file

@ -12,4 +12,8 @@ return {
--- Enforces immutability of atoms by deep-freezing table values. Enabled
--- if the optimization level is below 2, which is true in studio.
frozen = not isO2,
--- Whether inner effects should clean up after themselves when their
--- parent effect re-runs. This is usually desirable, but can be disabled
--- to revert to the old behavior. Defaults to `true`.
trackInnerEffects = true,
}

View file

@ -13,6 +13,7 @@ export type Equals<T> = (current: T, incoming: T) => boolean;
export const flags: {
strict: boolean;
frozen: boolean;
trackInnerEffects: boolean;
};
export function atom<T>(value: T, equals?: Equals<T>): Atom<T>;