@lightningtv/solid
Advanced tools
Comparing version
@@ -1,14 +0,14 @@ | ||
import { type JSX, type ValidComponent } from 'solid-js'; | ||
import { type ElementNode } from '@lightningtv/solid'; | ||
type LazyProps<T extends readonly any[], U extends JSX.Element> = ElementNode & { | ||
import { type JSX } from 'solid-js'; | ||
import { type NodeProps } from '@lightningtv/solid'; | ||
type LazyProps<T extends readonly any[]> = Omit<NodeProps, 'children'> & { | ||
each: T | undefined | null | false; | ||
fallback?: JSX.Element; | ||
component?: ValidComponent; | ||
upCount: number; | ||
delay?: number; | ||
sync?: boolean; | ||
children: (item: T[number], index: number) => U; | ||
selected?: number; | ||
children: (item: T[number], index: number) => JSX.Element; | ||
}; | ||
export declare function LazyRow<T extends readonly any[], U extends JSX.Element>(props: LazyProps<T, U>): JSX.Element; | ||
export declare function LazyColumn<T extends readonly any[], U extends JSX.Element>(props: LazyProps<T, U>): JSX.Element; | ||
export declare function LazyRow<T extends readonly any[]>(props: LazyProps<T>): JSX.Element; | ||
export declare function LazyColumn<T extends readonly any[]>(props: LazyProps<T>): JSX.Element; | ||
export {}; |
@@ -5,5 +5,6 @@ import { Index, createEffect, createMemo, createSignal, Show, untrack, } from 'solid-js'; | ||
function createLazy(component, props, keyHandler) { | ||
// Need at least one item so it can be focused | ||
const [offset, setOffset] = createSignal(1); | ||
let timeoutId = null; | ||
createEffect(() => setOffset(props.selected || 0)); | ||
createEffect(() => setOffset(props.selected || 1)); | ||
if (props.sync !== true) { | ||
@@ -43,3 +44,3 @@ createEffect(() => { | ||
// }); | ||
return (<Show when={items().length > 0} fallback={props.fallback}> | ||
return (<Show when={items()} fallback={props.fallback}> | ||
<Dynamic component={component} {...props} {...keyHandler(updateOffset)}> | ||
@@ -46,0 +47,0 @@ <Index each={items()} children={props.children}/> |
@@ -11,2 +11,5 @@ import { type NodeProps, type TextProps, type RendererMain, type RendererMainSettings } from '@lightningtv/core'; | ||
export declare const effect: <T>(fn: (prev?: T) => T, init?: T) => void, memo: <T>(fn: () => T, equal: boolean) => () => T, createComponent: <T>(Comp: (props: T) => SolidNode, props: T) => SolidNode, createElement: (tag: string) => SolidNode, createTextNode: (value: string) => SolidNode, insertNode: (parent: SolidNode, node: SolidNode, anchor?: SolidNode | undefined) => void, insert: <T>(parent: any, accessor: T | (() => T), marker?: any | null) => SolidNode, spread: <T>(node: any, accessor: (() => T) | T, skipChildren?: Boolean) => void, setProp: <T>(node: SolidNode, name: string, value: T, prev?: T | undefined) => T, mergeProps: (...sources: unknown[]) => unknown, use: <A, T>(fn: (element: SolidNode, arg: A) => T, element: SolidNode, arg: A) => T; | ||
type Task = () => void; | ||
export declare function clearTasks(): void; | ||
export declare function scheduleTask(callback: Task, priority?: 'high' | 'low'): void; | ||
/** | ||
@@ -24,1 +27,2 @@ * renders an arbitrary custom or native component and passes the other props | ||
export declare const Text: (props: TextProps) => JSXElement; | ||
export {}; |
import { createRenderer as solidCreateRenderer } from 'solid-js/universal'; | ||
import { Config, startLightningRenderer, } from '@lightningtv/core'; | ||
import nodeOpts from './solidOpts.js'; | ||
import { splitProps, createMemo, untrack, } from 'solid-js'; | ||
import { setActiveElement } from './activeElement.js'; | ||
import { splitProps, createMemo, createRenderEffect, untrack, } from 'solid-js'; | ||
import { activeElement, setActiveElement } from './activeElement.js'; | ||
const solidRenderer = solidCreateRenderer(nodeOpts); | ||
@@ -20,2 +20,6 @@ let renderer; | ||
rootNode.rendered = true; | ||
renderer.on('idle', () => { | ||
tasksEnabled = true; | ||
processTasks(); | ||
}); | ||
return { | ||
@@ -28,2 +32,33 @@ renderer, | ||
export const { effect, memo, createComponent, createElement, createTextNode, insertNode, insert, spread, setProp, mergeProps, use, } = solidRenderer; | ||
const taskQueue = []; | ||
let tasksEnabled = false; | ||
createRenderEffect(() => { | ||
// should change whenever a keypress occurs, so we disable the task queue | ||
// until the renderer is idle again. | ||
activeElement(); | ||
tasksEnabled = false; | ||
}); | ||
export function clearTasks() { | ||
taskQueue.length = 0; | ||
} | ||
export function scheduleTask(callback, priority = 'low') { | ||
if (priority === 'high') { | ||
taskQueue.unshift(callback); | ||
} | ||
else { | ||
taskQueue.push(callback); | ||
} | ||
processTasks(); | ||
} | ||
function processTasks() { | ||
if (tasksEnabled && taskQueue.length) { | ||
setTimeout(() => { | ||
const task = taskQueue.shift(); | ||
if (task) { | ||
task(); | ||
processTasks(); | ||
} | ||
}, 0); | ||
} | ||
} | ||
/** | ||
@@ -30,0 +65,0 @@ * renders an arbitrary custom or native component and passes the other props |
{ | ||
"name": "@lightningtv/solid", | ||
"version": "2.7.6", | ||
"version": "2.7.7", | ||
"description": "Lightning Renderer for Solid Universal", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -14,2 +14,3 @@ import { createRenderer as solidCreateRenderer } from 'solid-js/universal'; | ||
createMemo, | ||
createRenderEffect, | ||
untrack, | ||
@@ -20,3 +21,3 @@ type JSXElement, | ||
import type { SolidNode } from './types.js'; | ||
import { setActiveElement } from './activeElement.js'; | ||
import { activeElement, setActiveElement } from './activeElement.js'; | ||
@@ -45,2 +46,7 @@ const solidRenderer = solidCreateRenderer<SolidNode>(nodeOpts); | ||
rootNode.rendered = true; | ||
renderer.on('idle', () => { | ||
tasksEnabled = true; | ||
processTasks(); | ||
}); | ||
return { | ||
@@ -67,2 +73,41 @@ renderer, | ||
type Task = () => void; | ||
const taskQueue: Task[] = []; | ||
let tasksEnabled = false; | ||
createRenderEffect(() => { | ||
// should change whenever a keypress occurs, so we disable the task queue | ||
// until the renderer is idle again. | ||
activeElement(); | ||
tasksEnabled = false; | ||
}); | ||
export function clearTasks(): void { | ||
taskQueue.length = 0; | ||
} | ||
export function scheduleTask( | ||
callback: Task, | ||
priority: 'high' | 'low' = 'low', | ||
): void { | ||
if (priority === 'high') { | ||
taskQueue.unshift(callback); | ||
} else { | ||
taskQueue.push(callback); | ||
} | ||
processTasks(); | ||
} | ||
function processTasks(): void { | ||
if (tasksEnabled && taskQueue.length) { | ||
setTimeout(() => { | ||
const task = taskQueue.shift(); | ||
if (task) { | ||
task(); | ||
processTasks(); | ||
} | ||
}, 0); | ||
} | ||
} | ||
/** | ||
@@ -69,0 +114,0 @@ * renders an arbitrary custom or native component and passes the other props |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
267300
1.03%3872
2.11%20
-4.76%