Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/agera/.size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "All publics",
"path": "dist/index.js",
"import": "*",
"limit": "2.46 kB"
"limit": "2.47 kB"
},
{
"name": "Signal",
Expand All @@ -21,6 +21,6 @@
"name": "Popular set",
"path": "dist/index.js",
"import": "{ signal, computed, effect, mountable, onMounted }",
"limit": "1.87 kB"
"limit": "1.88 kB"
}
]
2 changes: 1 addition & 1 deletion packages/agera/src/effect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ describe('agera', () => {

$num(1)

expect(fn).toHaveBeenCalledWith(undefined)
expect(fn).toHaveBeenLastCalledWith()

stop()
})
Expand Down
35 changes: 27 additions & 8 deletions packages/agera/src/internals/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ export function effect(fn: EffectCallback, noDefer = false): Destroy {
}
}

runEffect(e, true)
warmupEffect(e)

return effectOper.bind(e)
}
Expand Down Expand Up @@ -654,22 +654,41 @@ function updateSignal(s: SignalNode): boolean {
return s.value !== (s.value = s.pendingValue)
}

function runEffect(e: EffectNode, warmup?: true): void {
function warmupEffect(e: EffectNode): void {
const prevSub = pushActiveSub(e)
const prevNoMount = isMountableUsed ? pushNoMount(e.noMount) : undefined

try {
e.destroy = e.fn(warmup) || undefined
e.destroy = e.fn(true) || undefined
} finally {
popNoMount(prevNoMount)
popActiveSub(prevSub)
e.flags &= ~RecursedCheckFlag

if (warmup === undefined) {
purgeDeps(e)
if (isMountableUsed) {
popNoMount(prevNoMount)
notifyMounted(activeSub)
}
}
}

notifyMounted(activeSub)
function runEffect(e: EffectNode): void {
const prevSub = pushActiveSub(e)
const prevNoMount = isMountableUsed ? pushNoMount(e.noMount) : undefined

try {
e.destroy = e.fn() || undefined
} finally {
if (isMountableUsed) {
popNoMount(prevNoMount)
}

popActiveSub(prevSub)
e.flags &= ~RecursedCheckFlag
purgeDeps(e)

if (isMountableUsed) {
notifyMounted(activeSub)
}
}
}

Expand Down Expand Up @@ -840,7 +859,7 @@ function runDeferredEffects(link: Link): void {
runDeferredEffects(dep.deps)
}
} else {
runEffect(dep as EffectNode, true)
warmupEffect(dep as EffectNode)
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/kida/.size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"name": "Popular set",
"path": "dist/index.js",
"import": "{ signal, record, computed, effect, mountable, onMount }",
"limit": "2.21 kB"
"limit": "2.23 kB"
}
]
2 changes: 1 addition & 1 deletion packages/store/.size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"name": "Popular set",
"path": "dist/index.js",
"import": "{ signal, record, computed, effect, mountable, onMount }",
"limit": "2.21 kB"
"limit": "2.23 kB"
}
]