@solid-primitives/scheduled
Advanced tools
Comparing version 1.4.3 to 1.4.4
@@ -131,2 +131,2 @@ import { Accessor } from 'solid-js'; | ||
export { ScheduleCallback, Scheduled, createScheduled, debounce, leading, leadingAndTrailing, scheduleIdle, throttle }; | ||
export { type ScheduleCallback, type Scheduled, createScheduled, debounce, leading, leadingAndTrailing, scheduleIdle, throttle }; |
@@ -11,7 +11,5 @@ import { getOwner, onCleanup, createSignal, getListener } from 'solid-js'; | ||
const clear = () => clearTimeout(timeoutId); | ||
if (getOwner()) | ||
onCleanup(clear); | ||
if (getOwner()) onCleanup(clear); | ||
const debounced = (...args) => { | ||
if (timeoutId !== void 0) | ||
clear(); | ||
if (timeoutId !== void 0) clear(); | ||
timeoutId = setTimeout(() => callback(...args), wait); | ||
@@ -28,4 +26,3 @@ }; | ||
lastArgs = args; | ||
if (isThrottled) | ||
return; | ||
if (isThrottled) return; | ||
isThrottled = true; | ||
@@ -41,4 +38,3 @@ timeoutId = setTimeout(() => { | ||
}; | ||
if (getOwner()) | ||
onCleanup(clear); | ||
if (getOwner()) onCleanup(clear); | ||
return Object.assign(throttled, { clear }); | ||
@@ -48,8 +44,7 @@ }; | ||
// requestIdleCallback is not supported in Safari | ||
window.requestIdleCallback ? (callback, maxWait) => { | ||
typeof requestIdleCallback !== "undefined" ? (callback, maxWait) => { | ||
let isDeferred = false, id, lastArgs; | ||
const deferred = (...args) => { | ||
lastArgs = args; | ||
if (isDeferred) | ||
return; | ||
if (isDeferred) return; | ||
isDeferred = true; | ||
@@ -68,4 +63,3 @@ id = requestIdleCallback( | ||
}; | ||
if (getOwner()) | ||
onCleanup(clear); | ||
if (getOwner()) onCleanup(clear); | ||
return Object.assign(deferred, { clear }); | ||
@@ -81,4 +75,3 @@ } : ( | ||
const scheduled2 = (...args) => { | ||
if (called) | ||
return; | ||
if (called) return; | ||
called = true; | ||
@@ -92,4 +85,3 @@ callback(...args); | ||
const func = (...args) => { | ||
if (!isScheduled) | ||
callback(...args); | ||
if (!isScheduled) callback(...args); | ||
isScheduled = true; | ||
@@ -102,4 +94,3 @@ scheduled(); | ||
}; | ||
if (getOwner()) | ||
onCleanup(clear); | ||
if (getOwner()) onCleanup(clear); | ||
return Object.assign(func, { clear }); | ||
@@ -111,4 +102,3 @@ } | ||
const scheduled2 = (...args) => { | ||
if (called) | ||
return; | ||
if (called) return; | ||
called = true; | ||
@@ -132,4 +122,3 @@ callback(...args); | ||
if (state !== 2 /* Trailing */) { | ||
if (state === 0 /* Ready */) | ||
callback(...args); | ||
if (state === 0 /* Ready */) callback(...args); | ||
state += 1; | ||
@@ -143,4 +132,3 @@ } | ||
}; | ||
if (getOwner()) | ||
onCleanup(clear); | ||
if (getOwner()) onCleanup(clear); | ||
return Object.assign(fn, { clear }); | ||
@@ -157,4 +145,3 @@ } | ||
return () => { | ||
if (!isDirty) | ||
call(), track(); | ||
if (!isDirty) call(), track(); | ||
if (isDirty) { | ||
@@ -161,0 +148,0 @@ isDirty = !!listeners; |
{ | ||
"name": "@solid-primitives/scheduled", | ||
"version": "1.4.3", | ||
"version": "1.4.4", | ||
"description": "Primitives for creating scheduled — throttled or debounced — callbacks.", | ||
@@ -62,3 +62,3 @@ "contributors": [ | ||
"@solid-primitives/event-listener": "^2.3.3", | ||
"@solid-primitives/timer": "^1.3.9" | ||
"@solid-primitives/timer": "^1.3.10" | ||
}, | ||
@@ -65,0 +65,0 @@ "peerDependencies": { |
@@ -16,3 +16,3 @@ <p> | ||
- [`throttle`](#throttle) - Creates a callback that is **throttled** and cancellable. | ||
- [`scheduleIdle`](#scheduleIdle) - Creates a callback throttled using `window.requestIdleCallback()`. | ||
- [`scheduleIdle`](#scheduleidle) - Creates a callback throttled using `window.requestIdleCallback()`. | ||
- [`leading`](#leading) - Creates a scheduled and cancellable callback that will be called on **leading** edge. | ||
@@ -19,0 +19,0 @@ - [`createScheduled`](#createscheduled) - Creates a signal used for scheduling execution of solid computations by tracking. |
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
27994
7
422