@woylie/doggo 0.15.0 → 0.15.1

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
@@ -21,7 +21,7 @@ The package can be installed by adding `doggo` to your list of dependencies in
21
21
  ```elixir
22
22
  def deps do
23
23
  [
24
- {:doggo, "~> 0.15.0"}
24
+ {:doggo, "~> 0.15.1"}
25
25
  ]
26
26
  end
27
27
  ```
@@ -83,11 +83,17 @@ export function initCarousel(carousel) {
83
83
 
84
84
  const syncActiveState = () => setActiveIdx(getActiveIdx());
85
85
 
86
+ const SCROLL_SETTLE_MS = 100;
87
+
88
+ let pendingIdx = null;
89
+ let settleTimer = null;
90
+
86
91
  const scrollToIdx = (idx) => {
87
92
  const item = getItems()[idx];
88
93
 
89
94
  if (!item) return;
90
95
 
96
+ pendingIdx = idx;
91
97
  setActiveIdx(idx);
92
98
 
93
99
  const itemsContainer = getItemsContainer();
@@ -190,7 +196,15 @@ export function initCarousel(carousel) {
190
196
  carousel.addEventListener(
191
197
  "scroll",
192
198
  (e) => {
193
- if (e.target === getItemsContainer()) syncActiveState();
199
+ if (e.target !== getItemsContainer()) return;
200
+
201
+ clearTimeout(settleTimer);
202
+ settleTimer = setTimeout(() => {
203
+ pendingIdx = null;
204
+ syncActiveState();
205
+ }, SCROLL_SETTLE_MS);
206
+
207
+ if (pendingIdx === null) syncActiveState();
194
208
  },
195
209
  true,
196
210
  );
@@ -295,7 +309,12 @@ export function initCarousel(carousel) {
295
309
  }
296
310
  };
297
311
 
298
- return { update: syncAfterUpdate, destroy: stopAutoRotation };
312
+ const destroy = () => {
313
+ stopAutoRotation();
314
+ clearTimeout(settleTimer);
315
+ };
316
+
317
+ return { update: syncAfterUpdate, destroy };
299
318
  }
300
319
 
301
320
  export default {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@woylie/doggo",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "description": "JavaScript hooks for the Doggo component library",
5
5
  "keywords": [
6
6
  "phoenix",