@solid-primitives/scheduled
Advanced tools
Comparing version 1.4.0 to 1.4.1
@@ -84,4 +84,3 @@ import { getOwner, onCleanup, createSignal, getListener } from 'solid-js'; | ||
let isScheduled = false; | ||
const onTrail = () => isScheduled = false; | ||
const scheduled = schedule(onTrail, wait); | ||
const scheduled = schedule(() => isScheduled = false, wait); | ||
const func = (...args) => { | ||
@@ -112,24 +111,23 @@ if (!isScheduled) | ||
} | ||
const LEADING = 0; | ||
const TRAILING = 1; | ||
const RESET = 2; | ||
let firstCall = true; | ||
const onTrail = (callType, args) => { | ||
if (callType === RESET) { | ||
firstCall = true; | ||
return; | ||
let State; | ||
((State2) => { | ||
State2[State2["Ready"] = 0] = "Ready"; | ||
State2[State2["Leading"] = 1] = "Leading"; | ||
State2[State2["Trailing"] = 2] = "Trailing"; | ||
})(State || (State = {})); | ||
let state = 0 /* Ready */; | ||
const scheduled = schedule((args) => { | ||
state === 2 /* Trailing */ && callback(...args); | ||
state = 0 /* Ready */; | ||
}, wait); | ||
const fn = (...args) => { | ||
if (state !== 2 /* Trailing */) { | ||
if (state === 0 /* Ready */) | ||
callback(...args); | ||
state += 1; | ||
} | ||
if (callType === TRAILING) | ||
callback(...args); | ||
setTimeout(() => scheduled(RESET), 0); | ||
scheduled(args); | ||
}; | ||
const scheduled = schedule(onTrail, wait); | ||
const func = (...args) => { | ||
if (firstCall) | ||
callback(...args); | ||
scheduled(firstCall ? LEADING : TRAILING, args); | ||
firstCall = false; | ||
}; | ||
const clear = () => { | ||
firstCall = true; | ||
state = 0 /* Ready */; | ||
scheduled.clear(); | ||
@@ -139,3 +137,3 @@ }; | ||
onCleanup(clear); | ||
return Object.assign(func, { clear }); | ||
return Object.assign(fn, { clear }); | ||
} | ||
@@ -142,0 +140,0 @@ function createScheduled(schedule) { |
{ | ||
"name": "@solid-primitives/scheduled", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "Primitives for creating scheduled — throttled or debounced — callbacks.", | ||
@@ -57,4 +57,4 @@ "contributors": [ | ||
"devDependencies": { | ||
"solid-js": "1.7.6", | ||
"@solid-primitives/event-listener": "^2.2.13", | ||
"solid-js": "1.7.9", | ||
"@solid-primitives/event-listener": "^2.2.14", | ||
"@solid-primitives/timer": "^1.3.7" | ||
@@ -61,0 +61,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32333
8
609