wip: intersection with last optimization

This commit is contained in:
dpiercey 2025-03-04 10:02:45 -07:00
parent 85211c1291
commit c4384166cd
No known key found for this signature in database
GPG Key ID: 8A959D84C57B3CE5
4 changed files with 21 additions and 0 deletions

View File

@ -46,6 +46,7 @@ export {
effect,
hoist,
intersection,
intersectionWithLast,
loopClosure,
nextTagId,
registerDynamicClosure,

View File

@ -22,11 +22,14 @@ export function queueRender<T>(
signalKey: number,
value?: T,
scopeKey = scope.___id,
isLast?: 1
) {
const key = scopeKey * scopeKeyOffset + signalKey;
const existingRender = signalKey >= 0 && pendingRendersLookup.get(key);
if (existingRender) {
existingRender.___value = value;
} else if (isLast) {
signal(scope);
} else {
const render: PendingRender = {
___key: key,

View File

@ -87,6 +87,22 @@ export function intersection(
};
}
export function intersectionWithLast(
id: number,
fn: SignalFn<never>,
scopeIdAccessor: Accessor = /*@__KEY__*/ "___id",
): Signal<never> {
return (scope, isLast?: 1) => {
if (scope.___pending) {
if (isLast) {
fn(scope);
}
} else {
queueRender(scope, fn as any, id, 0, scope[scopeIdAccessor], isLast);
}
};
}
export function loopClosure<T>(
valueAccessor: Accessor,
ownerLoopNodeAccessor: Accessor,

View File

@ -25,6 +25,7 @@ const pureFunctions: Array<keyof typeof import("../../dom")> = [
"createTemplate",
"dynamicClosure",
"intersection",
"intersectionWithLast",
"loopClosure",
"loopIn",
"loopOf",