svelte-infinite 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -92,9 +92,11 @@ See the example below and [in this repository](https://github.com/ndom91/svelte-
92
92
  // Ideally, like most paginated endpoints, this should return the data
93
93
  // you've requested for your page, as well as the total amount of data
94
94
  // available to page through
95
-
96
95
  if (!dataResponse.ok) {
97
96
  stateChanger.error()
97
+
98
+ // On errors, set the pageNumber back so we can retry
99
+ // that page's data on the next 'loadMore' attempt
98
100
  pageNumber -= 1
99
101
  return
100
102
  }
@@ -163,8 +165,8 @@ The `stateChanger` import is an object with 4 methods on it:
163
165
 
164
166
  - `triggerLoad: () => Promise<void>` - **required**
165
167
  - The async function to call when we should attempt to load more data to show.
166
- - `intersectionOptions` - optional
167
- - The options to pass to the `IntersectionObserver` instance. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/IntersectionObserver#options) for more details. Default is `{ rootMargin: "0px 0px 200px 0px" }`, making it trigger the `loadMore` function 200px before it actually intersects with the root element (window by default). This has the effect of beginning to load the next page of data before the user has actually reached the bottom of the list, making the experience feel more smooth.
168
+ - `intersectionOptions: `[`IntersectionObserverInit`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/IntersectionObserver#options)` = { rootMargin: "0px 0px 200px 0px" }` - optional
169
+ - The options to pass to the `IntersectionObserver` instance. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/IntersectionObserver#options) for more details. The default `rootMargin` value will cause the target to intersect 200px earlier and trigger the `loadMore` function before it actually intersects with the root element (window by default). This has the effect of beginning to load the next page of data before the user has actually reached the current bottom of the list, making the experience feel more smooth.
168
170
  - 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.
169
171
  - `loopTimeout: number = 1000` - optional
170
172
  - If the `loopMaxCalls` is reached within this duration (in milliseconds), a cool down period is triggered.
@@ -25,7 +25,7 @@ export const stateChanger = {
25
25
  };
26
26
  </script>
27
27
 
28
- <script>import { onDestroy } from "svelte";
28
+ <script>import { onMount, onDestroy } from "svelte";
29
29
  const {
30
30
  triggerLoad,
31
31
  loopTimeout = 1e3,
@@ -72,7 +72,7 @@ async function attemptLoad() {
72
72
  }
73
73
  }
74
74
  }
75
- $effect(() => {
75
+ onMount(() => {
76
76
  if (observer || !intersectionTarget)
77
77
  return;
78
78
  const appliedIntersectionOptions = {
@@ -130,22 +130,17 @@ onDestroy(() => {
130
130
 
131
131
  <style>
132
132
  .infinite-loader-wrapper {
133
- display: grid;
134
133
  width: 100%;
135
- place-items: center;
136
134
 
137
135
  .infinite-loading {
138
- margin-top: 1rem;
139
136
  font-size: 1.5rem;
140
137
  }
141
138
 
142
139
  .infinite-no-results {
143
- margin-top: 1rem;
144
140
  font-size: 1.5rem;
145
141
  }
146
142
 
147
143
  .infinite-no-data {
148
- margin-top: 1rem;
149
144
  font-size: 1.5rem;
150
145
  }
151
146
 
@@ -180,6 +175,7 @@ onDestroy(() => {
180
175
  width: 100%;
181
176
  min-height: 1px;
182
177
  display: flex;
178
+ margin-block: 2rem;
183
179
  flex-direction: column;
184
180
  align-items: center;
185
181
  justify-content: center;
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "email": "yo@ndo.dev",
7
7
  "url": "https://ndo.dev"
8
8
  },
9
- "version": "0.1.2",
9
+ "version": "0.1.4",
10
10
  "license": "MIT",
11
11
  "homepage": "https://svelte-5-infinite.vercel.app",
12
12
  "keywords": [