@raycast/utils
Advanced tools
Comparing version 1.4.9 to 1.4.10
@@ -24,3 +24,2 @@ import type { Image } from "@raycast/api"; | ||
}): Image.Asset; | ||
export declare function singletonPromise<T>(promise: () => Promise<T>): T | Promise<T>; | ||
//# sourceMappingURL=avatar.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.singletonPromise = exports.getAvatarIcon = void 0; | ||
exports.getAvatarIcon = void 0; | ||
const color_1 = require("./color"); | ||
@@ -114,20 +114,1 @@ function getWholeCharAndI(str, i) { | ||
exports.getAvatarIcon = getAvatarIcon; | ||
const cache = new Map(); | ||
function singletonPromise(promise) { | ||
const cached = cache.get(promise); | ||
if (cached) { | ||
return cached.result || cached.inFlight; | ||
} | ||
const inFlight = promise() | ||
.then((result) => { | ||
cache.set(promise, { result }); | ||
return result; | ||
}) | ||
.catch((err) => { | ||
cache.delete(promise); | ||
throw err; | ||
}); | ||
cache.set(promise, { inFlight }); | ||
return inFlight; | ||
} | ||
exports.singletonPromise = singletonPromise; |
@@ -58,3 +58,3 @@ "use strict"; | ||
// but only if we need it (eg. only when we want to automatically rollback after) | ||
dataBeforeOptimisticUpdate = JSON.parse(JSON.stringify(latestData.current)); | ||
dataBeforeOptimisticUpdate = structuredClone(latestData.current); | ||
} | ||
@@ -77,3 +77,5 @@ const data = options.optimisticUpdate(latestData.current); | ||
lastUpdateFrom.current = "cache"; | ||
// @ts-expect-error when undefined, it's expected | ||
laggyDataRef.current = dataBeforeOptimisticUpdate; | ||
// @ts-expect-error when undefined, it's expected | ||
mutateCache(dataBeforeOptimisticUpdate); | ||
@@ -80,0 +82,0 @@ } |
@@ -12,3 +12,2 @@ "use strict"; | ||
const react_1 = require("react"); | ||
const useDeepMemo_1 = require("./useDeepMemo"); | ||
const useCachedPromise_1 = require("./useCachedPromise"); | ||
@@ -123,7 +122,2 @@ const useLatest_1 = require("./useLatest"); | ||
}; | ||
const args = (0, useDeepMemo_1.useDeepMemo)([ | ||
Array.isArray(optionsOrArgs) ? optionsOrArgs : [], | ||
execOptions, | ||
input, | ||
]); | ||
const abortable = (0, react_1.useRef)(); | ||
@@ -162,3 +156,3 @@ const parseOutputRef = (0, useLatest_1.useLatest)(parseOutput || defaultParsing); | ||
}, [parseOutputRef]); | ||
return (0, useCachedPromise_1.useCachedPromise)(fn, [command, ...args], { | ||
return (0, useCachedPromise_1.useCachedPromise)(fn, [command, Array.isArray(optionsOrArgs) ? optionsOrArgs : [], execOptions, input], { | ||
...useCachedPromiseOptions, | ||
@@ -165,0 +159,0 @@ abortable, |
@@ -10,3 +10,2 @@ "use strict"; | ||
const content_type_1 = __importDefault(require("content-type")); | ||
const useDeepMemo_1 = require("./useDeepMemo"); | ||
const useCachedPromise_1 = require("./useCachedPromise"); | ||
@@ -96,5 +95,4 @@ const useLatest_1 = require("./useLatest"); | ||
}, [parseResponseRef]); | ||
const args = (0, useDeepMemo_1.useDeepMemo)([url, fetchOptions]); | ||
return (0, useCachedPromise_1.useCachedPromise)(fn, args, { ...useCachedPromiseOptions, abortable }); | ||
return (0, useCachedPromise_1.useCachedPromise)(fn, [url, fetchOptions], { ...useCachedPromiseOptions, abortable }); | ||
} | ||
exports.useFetch = useFetch; |
@@ -86,6 +86,6 @@ "use strict"; | ||
// but only if we need it (eg. only when we want to automatically rollback after) | ||
dataBeforeOptimisticUpdate = JSON.parse(JSON.stringify(latestValue.current?.value)); | ||
dataBeforeOptimisticUpdate = structuredClone(latestValue.current?.value); | ||
} | ||
const update = options.optimisticUpdate; | ||
set((prevState) => ({ ...prevState, value: update(prevState.data) })); | ||
set((prevState) => ({ ...prevState, data: update(prevState.data) })); | ||
} | ||
@@ -97,6 +97,6 @@ return await asyncUpdate; | ||
const update = options.rollbackOnError; | ||
set((prevState) => ({ ...prevState, value: update(prevState.data) })); | ||
set((prevState) => ({ ...prevState, data: update(prevState.data) })); | ||
} | ||
else if (options?.optimisticUpdate && options?.rollbackOnError !== false) { | ||
set((prevState) => ({ ...prevState, value: dataBeforeOptimisticUpdate })); | ||
set((prevState) => ({ ...prevState, data: dataBeforeOptimisticUpdate })); | ||
} | ||
@@ -124,3 +124,3 @@ throw err; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, (0, useDeepMemo_1.useDeepMemo)([args, options?.execute, callback])); | ||
}, [(0, useDeepMemo_1.useDeepMemo)([args, options?.execute, callback])]); | ||
// abort request when unmounting | ||
@@ -127,0 +127,0 @@ (0, react_1.useEffect)(() => { |
{ | ||
"name": "@raycast/utils", | ||
"version": "1.4.9", | ||
"version": "1.4.10", | ||
"description": "Set of utilities to streamline building Raycast extensions", | ||
@@ -18,3 +18,3 @@ "author": "Raycast Technologies Ltd.", | ||
"peerDependencies": { | ||
"@raycast/api": ">=1.39.2" | ||
"@raycast/api": ">=1.42.0" | ||
}, | ||
@@ -40,3 +40,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"@raycast/api": "^1.39.2", | ||
"@raycast/api": "^1.42.0", | ||
"@types/content-type": "^1.1.5", | ||
@@ -54,5 +54,4 @@ "@types/media-typer": "^1.1.1", | ||
"eslint-plugin-react-hooks": "4.5.0", | ||
"sql.js": "^1.7.0", | ||
"typescript": "4.7.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
14
121694
2632