@solid-primitives/utils
Advanced tools
Comparing version 2.2.1 to 3.0.0
@@ -156,38 +156,2 @@ import { Accessor, Setter, onCleanup } from 'solid-js'; | ||
/** | ||
* Creates a promise that resolves *(or rejects)* after given time. | ||
* | ||
* @param ms timeout duration in ms | ||
* @param throwOnTimeout promise will be rejected on timeout if set to `true` | ||
* @param reason rejection reason | ||
* @returns Promise<void> | ||
* | ||
* @example | ||
* ```ts | ||
* await promiseTimeout(1500) // will resolve void after timeout | ||
* await promiseTimeout(1500, true, 'rejection reason') // will reject 'rejection reason' after timout | ||
* ``` | ||
*/ | ||
declare const promiseTimeout: (ms: number, throwOnTimeout?: boolean, reason?: string) => Promise<void>; | ||
/** | ||
* Combination of `Promise.race()` and `promiseTimeout`. | ||
* | ||
* @param promises single promise, or array of promises | ||
* @param ms timeout duration in ms | ||
* @param throwOnTimeout promise will be rejected on timeout if set to `true` | ||
* @param reason rejection reason | ||
* @returns a promise resulting in value of the first source promises to be resolved | ||
* | ||
* @example | ||
* ```ts | ||
* // single promise | ||
* await raceTimeout(new Promise(() => {...}), 3000) | ||
* // list of promises racing | ||
* await raceTimeout([new Promise(),new Promise()...], 3000) | ||
* // reject on timeout | ||
* await raceTimeout(new Promise(), 3000, true, 'rejection reason') | ||
* ``` | ||
*/ | ||
declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout: true, reason?: string): T extends any[] ? Promise<Awaited<T[number]>> : Promise<Awaited<T>>; | ||
declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout?: boolean, reason?: string): T extends any[] ? Promise<Awaited<T[number]> | undefined> : Promise<Awaited<T> | undefined>; | ||
/** | ||
* Solid's `onCleanup` that is registered only if there is a root. | ||
@@ -295,2 +259,2 @@ */ | ||
export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, AnyStatic, DeepPartialAny, Definite, Directive, ExtractIfPossible, Falsy, FalsyValue, ItemsOf, ItemsOfMany, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, Mutable, NonIterable, Noop, OnAccessEffectFunction, Position, PrimitiveValue, RequiredKeys, SetterValue, Simplify, StaticStoreSetter, Tail, Trigger, TriggerCache, Truthy, UnboxLazy, UnionToIntersection, Values, WeakTriggerCache, access, accessArray, accessWith, arrayEquals, asAccessor, asArray, chain, clamp, compare, createCallbackStack, createMicrotask, createProxy, createStaticStore, createTrigger, createTriggerCache, createWeakTriggerCache, entries, forEachEntry, handleDiffArray, isClient, isDev, isObject, isProd, isServer, keys, noop, ofClass, onRootCleanup, promiseTimeout, raceTimeout, warn, withAccess }; | ||
export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, AnyStatic, DeepPartialAny, Definite, Directive, ExtractIfPossible, Falsy, FalsyValue, ItemsOf, ItemsOfMany, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, Mutable, NonIterable, Noop, OnAccessEffectFunction, Position, PrimitiveValue, RequiredKeys, SetterValue, Simplify, StaticStoreSetter, Tail, Trigger, TriggerCache, Truthy, UnboxLazy, UnionToIntersection, Values, WeakTriggerCache, access, accessArray, accessWith, arrayEquals, asAccessor, asArray, chain, clamp, compare, createCallbackStack, createMicrotask, createProxy, createStaticStore, createTrigger, createTriggerCache, createWeakTriggerCache, entries, forEachEntry, handleDiffArray, isClient, isDev, isObject, isProd, isServer, keys, noop, ofClass, onRootCleanup, warn, withAccess }; |
@@ -1,3 +0,1 @@ | ||
"use strict"; | ||
// src/index.ts | ||
@@ -47,15 +45,8 @@ import { | ||
function forEachEntry(object, iterator) { | ||
Object.entries(object).forEach(([key, item], index, pairs) => iterator(key, item, index, pairs, object)); | ||
Object.entries(object).forEach( | ||
([key, item], index, pairs) => iterator(key, item, index, pairs, object) | ||
); | ||
} | ||
var entries = Object.entries; | ||
var keys = Object.keys; | ||
var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms)); | ||
function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") { | ||
const promises = asArray(input); | ||
const race = Promise.race([...promises, promiseTimeout(ms, throwOnTimeout, reason)]); | ||
race.finally(() => { | ||
promises.forEach((p) => p && typeof p === "object" && typeof p.dispose === "function" && p.dispose()); | ||
}); | ||
return race; | ||
} | ||
var onRootCleanup = (fn) => getOwner() ? onCleanup(fn) : fn; | ||
@@ -83,10 +74,13 @@ var createCallbackStack = () => { | ||
function createProxy(traps) { | ||
return new Proxy({}, { | ||
get: (_, k) => traps.get(k), | ||
set: (_, k, v) => { | ||
var _a; | ||
(_a = traps.set) == null ? void 0 : _a.call(traps, k, v); | ||
return false; | ||
return new Proxy( | ||
{}, | ||
{ | ||
get: (_, k) => traps.get(k), | ||
set: (_, k, v) => { | ||
var _a; | ||
(_a = traps.set) == null ? void 0 : _a.call(traps, k, v); | ||
return false; | ||
} | ||
} | ||
}); | ||
); | ||
} | ||
@@ -229,6 +223,4 @@ var createTrigger = isDev ? () => createSignal(void 0, { equals: false, name: "trigger" }) : () => createSignal(void 0, { equals: false }); | ||
onRootCleanup, | ||
promiseTimeout, | ||
raceTimeout, | ||
warn, | ||
withAccess | ||
}; |
{ | ||
"name": "@solid-primitives/utils", | ||
"version": "2.2.1", | ||
"version": "3.0.0", | ||
"description": "A bunch of reactive utility types and functions, for building primitives with Solid.js", | ||
@@ -24,7 +24,2 @@ "author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>", | ||
], | ||
"scripts": { | ||
"build": "tsup", | ||
"test": "uvu -r solid-register", | ||
"test:watch": "watchlist src test -- npm test" | ||
}, | ||
"keywords": [ | ||
@@ -41,4 +36,4 @@ "utilities", | ||
"tslib": "^2.4.0", | ||
"tsup": "^6.1.2", | ||
"uvu": "^0.5.4", | ||
"tsup": "^6.1.3", | ||
"uvu": "^0.5.6", | ||
"watchlist": "^0.3.1" | ||
@@ -48,3 +43,8 @@ }, | ||
"solid-js": "^1.4.1" | ||
}, | ||
"scripts": { | ||
"build": "tsup", | ||
"test": "uvu -r solid-register", | ||
"test:watch": "watchlist src test -- npm test" | ||
} | ||
} | ||
} |
@@ -19,29 +19,2 @@ <p> | ||
<details> | ||
<summary><b>Expand Changelog</b></summary> | ||
0.0.100 | ||
First commit of the timer primitive. | ||
0.0.250 | ||
Republished version with better ESM support and build tooling. | ||
0.0.260 | ||
Added comments for util methods. | ||
0.1.0 | ||
Add `/fp` and `/setter` export entries. Add `destore` and `raceTimeout` util. More jsdoc. | ||
0.1.2 | ||
Updated to Solid 1.3 | ||
0.1.3 | ||
Minor upgrades. | ||
</details> | ||
See [CHANGELOG.md](./CHANGELOG.md) |
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
26873
748
20