Socket
Socket
Sign inDemoInstall

svelte-infinite

Package Overview
Dependencies
0
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.6 to 0.2.1

27

dist/InfiniteLoader.svelte.d.ts

@@ -8,2 +8,3 @@ import { SvelteComponent } from "svelte";

};
import { type Snippet } from "svelte";
declare const __propDef: {

@@ -13,8 +14,20 @@ props: {

loopTimeout?: number | undefined;
loopDetectionTimeout?: number | undefined;
loopMaxCalls?: number | undefined;
intersectionOptions?: IntersectionObserverInit | undefined;
} & {
children?: ((this: void) => typeof import("svelte").SnippetReturn & {
children: Snippet;
loading?: ((this: void) => typeof import("svelte").SnippetReturn & {
_: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
}) | undefined;
noResults?: ((this: void) => typeof import("svelte").SnippetReturn & {
_: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
}) | undefined;
noData?: ((this: void) => typeof import("svelte").SnippetReturn & {
_: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
}) | undefined;
error?: ((this: void, args_0: {
attemptLoad: Promise<() => void>;
}) => typeof import("svelte").SnippetReturn & {
_: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
}) | undefined;
};

@@ -24,11 +37,3 @@ events: {

};
slots: {
default: {};
loading: {};
'no-results': {};
'no-data': {};
error: {
attemptLoad: () => Promise<void>;
};
};
slots: {};
};

@@ -35,0 +40,0 @@ type InfiniteLoaderProps_ = typeof __propDef.props;

@@ -9,3 +9,3 @@ {

},
"version": "0.1.6",
"version": "0.2.1",
"license": "MIT",

@@ -12,0 +12,0 @@ "homepage": "https://svelte-5-infinite.vercel.app",

@@ -23,2 +23,4 @@ <p align="center">

Svelte 5 is still early days, but I couldn't find an infinite loader-type component that was maintained for the last few years of Svelte 4. So I had recently built this for a Svelte 5-based application I was working on and was pretty happy with it, so I decided to clean it up and share it with the world! As Svelte 5 inevitably changes over the next weeks and months, I plan to keep this package updated and working with the latest available version of Svelte 5.
## 🏗️ Getting Started

@@ -136,6 +138,11 @@

<!-- There are a few optional slots for customizing what is shown at the bottom
of the scroller in various states, see README.md for more details -->
<div slot="loading">Loading...</div>
<div slot="no-data">Thats it, no more users left!</div>
<!-- 3. There are a few optional snippets for customizing what is shown at the bottom
of the scroller in various states, see the 'Snippets' section for more details -->
{#snippet loading()}
Loading...
{/snippet}
{#snippet error(load)}
<div>Error fetching data</div>
<button onclick={load}>Retry</button>
{/snippet}
</InfiniteLoader>

@@ -149,5 +156,5 @@ </main>

The `InfiniteLoader` component is a wrapper around your items, which will trigger the `triggerLoad` function when the user scrolls to the bottom of the list.
This package consists of two parts, first the `InfiniteLoader` component which is a wrapper around your items. It will trigger whichever async function you've passed to the `triggerLoad` prop when the user scrolls to the bottom of the list.
However, there is also a `loaderState` export which you should use to interact with the internal state of the loader. For example, if your `fetch` call errored, or you've reached the maximum number of items, etc. See the `loadMore` function above or the example application in `/src/routes` in this repository.
Second, there is also a `loaderState` import which you should use to interact with the internal state of the loader. For example, if your `fetch` call errored, or you've reached the maximum number of items, etc. you can communicate that to the loader. The most basic usage example can be seen in the 'Getting Started' section above. A more complex example can be seen in the 'Example' section, and of course the application in `/src/routes/+page.svelte` in this repository also has a "real-world" usage example.

@@ -161,5 +168,5 @@ ### loaderState

- `loaderState.error()`
- Designed to be called after a failed fetch or any other error. This will cause the `InfiniteLoader` to render a "Retry" button by default, or the `error` slot.
- Designed to be called after a failed fetch or any other error. This will cause the `InfiniteLoader` to render a "Retry" button by default, or the `error` snippet.
- `loaderState.complete()`
- Designed to be called when you've reached the end of your list and there are no more items to fetch. This will render a "No more data" string, or the `no-data` slot.
- Designed to be called when you've reached the end of your list and there are no more items to fetch. This will render a "No more data" string, or the `no-data` snippet.
- `loaderState.reset()`

@@ -175,17 +182,21 @@ - Designed to be called when you want to reset the state of the `InfiniteLoader` to its initial state, for example if there is a search input tied to your infinite list and the user enters a new query.

- It may also be required to pass in a reference to your scroll container as the `root` option, if your scroll container is not the window.
- `loopTimeout: number = 1000` - optional
- If the `loopMaxCalls` is reached within this duration (in milliseconds), a cool down period is triggered.
- `loopTimeout: number = 2000` - optional
- If the `loopMaxCalls` is reached within the detection timeout, a cool down period is triggered of this length (in milliseconds).
- `loopDetectionTimeout: number = 1000` - optional
- The time in milliseconds in which the `loopMaxCalls` count must be hit in order to trigger a cool down period of `loopTimeout` length.
- `loopMaxCalls: number = 5` - optional
- The number of calls to the `triggerLoad` function within timeout which should trigger cool down period.
### Slots
### Snippets
Snippets [replace slots](https://svelte-5-preview.vercel.app/docs/snippets#snippets-and-slots) in Svelte 5, and as such are used here to customize the content shown at the bottom of the scroller in various states. The `InfiniteLoader` component has 4 props for snippets available.
- `loading`
- Shown while calling `triggerLoad` and waiting on a response.
- `no-results`
- `noResults`
- Shown when there are no more results to display and we haven't fetched any data yet (i.e. data is less than count of items to be shown on first "page").
- `no-data`
- `noData`
- Shown when `loaderState.complete()` is called, indicating we've fetched and displayed all available data.
- `error`
- Shown when there is an error or `loaderState.error()` has been called. The slot has an `attemptLoad` prop passed to it which is just the internal `triggerLoad` function, designed for a "Retry" button or similar.
- Shown when there is an error or `loaderState.error()` has been called. The snippet has an `attemptLoad` parameter passed to it which is just the internal `triggerLoad` function, designed for a "Retry" button or similar.

@@ -192,0 +203,0 @@ ## 📦 Contributing

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc