@lightningtv/solid
Advanced tools
Comparing version
@@ -9,2 +9,3 @@ import { type JSX } from 'solid-js'; | ||
sync?: boolean; | ||
eagerLoad?: boolean; | ||
selected?: number; | ||
@@ -11,0 +12,0 @@ children: (item: T[number], index: number) => JSX.Element; |
import { Index, createEffect, createMemo, createSignal, Show, untrack, } from 'solid-js'; | ||
import { Dynamic } from '@lightningtv/solid'; | ||
import { Dynamic, scheduleTask } from '@lightningtv/solid'; | ||
import { Row, Column } from '@lightningtv/solid/primitives'; | ||
@@ -9,3 +9,6 @@ function createLazy(component, props, keyHandler) { | ||
createEffect(() => setOffset(props.selected || 1)); | ||
if (props.sync !== true) { | ||
if (props.sync) { | ||
setOffset(props.upCount); | ||
} | ||
else { | ||
createEffect(() => { | ||
@@ -17,5 +20,12 @@ if (props.each) { | ||
setOffset(count + 1); | ||
timeoutId = setTimeout(loadItems, 16); // ~30fps | ||
timeoutId = setTimeout(loadItems, 16); // ~60fps | ||
count++; | ||
} | ||
else if (props.eagerLoad) { | ||
const maxOffset = props.each ? props.each.length - 1 : 0; | ||
if (offset() >= maxOffset) | ||
return; | ||
setOffset((prev) => Math.min(prev + 1, maxOffset)); | ||
scheduleTask(loadItems); | ||
} | ||
}; | ||
@@ -26,5 +36,2 @@ loadItems(); | ||
} | ||
else { | ||
setOffset(props.upCount); | ||
} | ||
const items = createMemo(() => (Array.isArray(props.each) ? props.each.slice(0, offset()) : [])); | ||
@@ -42,6 +49,2 @@ const updateOffset = () => { | ||
}; | ||
// Don't need to cleanup because unluckly the timeout didnt finish | ||
// onCleanup(() => { | ||
// if (timeoutId) clearTimeout(timeoutId); | ||
// }); | ||
const handler = keyHandler(updateOffset); | ||
@@ -48,0 +51,0 @@ return (<Show when={items()} fallback={props.fallback}> |
@@ -12,2 +12,3 @@ import { type NodeProps, type TextProps, type RendererMain, type RendererMainSettings } from '@lightningtv/core'; | ||
type Task = () => void; | ||
export declare function setTasksEnabled(enabled: boolean): void; | ||
export declare function clearTasks(): void; | ||
@@ -14,0 +15,0 @@ export declare function scheduleTask(callback: Task, priority?: 'high' | 'low'): void; |
@@ -39,2 +39,5 @@ import { createRenderer as solidCreateRenderer } from 'solid-js/universal'; | ||
}); | ||
export function setTasksEnabled(enabled) { | ||
tasksEnabled = enabled; | ||
} | ||
export function clearTasks() { | ||
@@ -60,3 +63,3 @@ taskQueue.length = 0; | ||
} | ||
}, 0); | ||
}, Config.taskDelay || 50); | ||
} | ||
@@ -63,0 +66,0 @@ } |
@@ -20,2 +20,5 @@ import { type ElementNode, type Styles, type ElementText, type TextNode } from '@lightningtv/core'; | ||
} | ||
interface Config { | ||
taskDelay?: number; | ||
} | ||
} |
{ | ||
"name": "@lightningtv/solid", | ||
"version": "2.7.10", | ||
"version": "2.7.11", | ||
"description": "Lightning Renderer for Solid Universal", | ||
@@ -46,3 +46,3 @@ "type": "module", | ||
"dependencies": { | ||
"@lightningtv/core": "^2.7.3", | ||
"@lightningtv/core": "^2.7.5", | ||
"@solid-primitives/event-listener": "^2.3.3", | ||
@@ -49,0 +49,0 @@ "@solid-primitives/mouse": "^2.0.20", |
@@ -5,5 +5,5 @@ <p> | ||
# SolidJS Lightning | ||
# SolidJS for LightningJS | ||
Is a UI framework for [Lightning 3 Renderer](https://lightningjs.io/) built with [SolidJS](https://www.solidjs.com/) Universal Renderer. It allows you to declaratively construct lightning nodes with reactive primitives, just as you would construct a DOM tree in SolidJS. | ||
Is a UI framework for [LightningJS 3 Renderer](https://lightningjs.io/) built with [SolidJS](https://www.solidjs.com/) Universal Renderer. It allows you to declaratively construct lightning nodes with reactive primitives, with incredible performance. | ||
@@ -10,0 +10,0 @@ ## Need Support? |
@@ -81,2 +81,6 @@ import { createRenderer as solidCreateRenderer } from 'solid-js/universal'; | ||
export function setTasksEnabled(enabled: boolean): void { | ||
tasksEnabled = enabled; | ||
} | ||
export function clearTasks(): void { | ||
@@ -106,3 +110,3 @@ taskQueue.length = 0; | ||
} | ||
}, 0); | ||
}, Config.taskDelay || 50); | ||
} | ||
@@ -109,0 +113,0 @@ } |
@@ -32,2 +32,6 @@ import { | ||
} | ||
interface Config { | ||
taskDelay?: number; | ||
} | ||
} |
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
286041
0.39%4213
0.45%Updated