Giter Club home page Giter Club logo

solid-windowed's Introduction

Solid Windowed

Given a list of items, only render what's visible on the screen while allowing scrolling the whole list.

A Solid component. See https://www.solidjs.com/

Usage

Use in the same way as a solid For. Please see: https://www.solidjs.com/docs/latest/api

import Windowed from 'solid-windowed'

let list = []
for (let i = 0; i < 250_000; i++) list.push(i)

export default function YourComponent() {
	return (
		<div style="height:100%;">
			<Windowed each={list}>
				{(value, index) => {
					return (
						<div>
							Index in list is {index}, value is: {value}
						</div>
					)
				}}
			</Windowed>
		</div>
	)
}

Install

npm install solid-windowed

How it works?

It renders the first 10 elements of the list, then averages the height and with that in mind, we get the height of the container and render N items. As you scroll we slice the list to show what's supposed to be visible. If our average didn't fill the whole available space, we will add more items till its filled.

Caveats

Alternatives

I started this project without knowing there was already an implementation of this concept

Bugs That Have Been Fixed

The end of the list, seems to be a problematic edge case for the implementation of this concept.

  • scrolling to the bottom doesn't render the last few items
  • when at the bottom of the list and then maximising to a bigger size, doesn't render previous items

Author

URL

solid-windowed's People

Contributors

titobouzout avatar

Stargazers

Andy Parsons avatar Zafar Ansari avatar Simon O avatar Liu Yike avatar Francisco Bongiovanni avatar tom.wen avatar Johan Heyvaert avatar Usman Yunusov avatar Igor Kamyşev avatar Julien Karst  avatar Nikita avatar icode avatar rok avatar Conor Sinclair avatar Felipe Chernicharo avatar 北雁云依 avatar Kacper Kapuściak avatar Gregory avatar Hazel Atkinson avatar Iain Simmons avatar  avatar  avatar Sung Jeon avatar Daniel Sokil avatar Damian Tarnawski avatar Gabriel Alves Cunha avatar 张世阳 avatar Winston Fassett avatar John Wright avatar Halu avatar Oren Elbaum avatar Tolotra Raharison avatar  avatar Adrian Dayrit avatar Prince Neil Cedrick Castro avatar  avatar Rinat Valiullov avatar Alexandre Stahmer avatar Duc-Thien Bui avatar Ryan Carniato avatar abjutus avatar Martin Pengelly-Phillips avatar  avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

s0kil banging12 aca

solid-windowed's Issues

Playground issue

Playground example https://playground.solidjs.com/?hash=-1161667584&version=1.3.7 doesn't load.

Displays error

/main.tsx: A numeric separator is only allowed between two digits. (10:23)

8 | // lets render a list with 1 and a half million of items
9 | let list = [];
> 10 | for (let i = 0; i < 1_500_000; i++) list.push(i);
| ^
11 |
12 | return (
13 | <div style="height:100%;">

When using HTML5 (`<!DOCTYPE html>`), solid-windowed requires that html/body have height set to 100%

Thanks for sharing your library. I think it fits my current project well.

It seems like Windowed requires this styling, when it's used in an HTML5 document:

html, body {
    height: 100%;
}

I realized that this issue may not be apparent in Solid Playground, because there are base styles there, including html, body { height: 100% }.

What happens without it? Well, it can be a blank page. What surprised me at first is that there were no elements being rendered by the <For> loop inside <Windowed>, in my local code... until I removed <!DOCTYPE html> from my index.html! I think it's because solid-windowed's calculations were deciding to render zero elements.


Thinking about a solution: maybe just adding a note to the README with that chunk of CSS?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.