chore: add es-toolkit
This commit is contained in:
parent
5aa96a76f2
commit
14e7c61f39
5 changed files with 12 additions and 33 deletions
|
|
@ -40,6 +40,7 @@
|
|||
"yargs-parser": "^21.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"es-toolkit": "^1.8.0",
|
||||
"fuzzysort": "^3.0.1",
|
||||
"spitroast": "^1.4.4"
|
||||
},
|
||||
|
|
|
|||
7
pnpm-lock.yaml
generated
7
pnpm-lock.yaml
generated
|
|
@ -5,6 +5,9 @@ settings:
|
|||
excludeLinksFromLockfile: false
|
||||
|
||||
dependencies:
|
||||
es-toolkit:
|
||||
specifier: ^1.8.0
|
||||
version: 1.8.0
|
||||
fuzzysort:
|
||||
specifier: ^3.0.1
|
||||
version: 3.0.1
|
||||
|
|
@ -1165,6 +1168,10 @@ packages:
|
|||
is-symbol: 1.0.4
|
||||
dev: true
|
||||
|
||||
/es-toolkit@1.8.0:
|
||||
resolution: {integrity: sha512-ldETiVy9nu3uCHKsALW4pGitzASWivUq79DdMQqdLa2Nx0swhULpvXCqSoJrWYVI69bsgaNRqnFRwpHie8hY+A==}
|
||||
dev: false
|
||||
|
||||
/esbuild@0.20.2:
|
||||
resolution: {integrity: sha512-WdOOppmUNU+IbZ0PaDiTst80zjnrOkyJNHoKupIcVyU8Lvla3Ugx94VzkQ32Ijqd7UhHJy75gNWDMUekcrSJ6g==}
|
||||
engines: {node: '>=12'}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ const config = {
|
|||
{
|
||||
name: "swc",
|
||||
setup(build) {
|
||||
build.onLoad({ filter: /\.[jt]sx?$/ }, async args => {
|
||||
build.onLoad({ filter: /\.[cm]?[jt]sx?$/ }, async args => {
|
||||
const result = await swc.transformFile(args.path, {
|
||||
jsc: {
|
||||
externalHelpers: true,
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
/**
|
||||
* Returns a function that ensures that only one call
|
||||
* executes every given milliseconds.
|
||||
* @param funct Function to throttle
|
||||
* @param time Time to wait before allowing the next call
|
||||
* @returns Throttled function with the same signature as `funct`
|
||||
*/
|
||||
export function throttle<T extends (...args: any[]) => any>(
|
||||
funct: T,
|
||||
time: number = 200
|
||||
): T {
|
||||
let active = false;
|
||||
let calledWhileActive = false;
|
||||
return function (this: ReturnType<T>, ...args: Parameters<T>) {
|
||||
if (!active) {
|
||||
active = true;
|
||||
funct.apply(this, args);
|
||||
setTimeout(() => {
|
||||
active = false;
|
||||
if (calledWhileActive) {
|
||||
calledWhileActive = false;
|
||||
funct.apply(this, args);
|
||||
}
|
||||
}, time);
|
||||
} else {
|
||||
calledWhileActive = true;
|
||||
}
|
||||
} as T;
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { ClientInfoManager, MMKVManager } from "@lib/api/native/modules";
|
||||
import { throttle } from "@lib/utils/throttle";
|
||||
import { debounce } from "es-toolkit";
|
||||
|
||||
const CACHE_VERSION = 34;
|
||||
const BUNNY_METRO_CACHE_KEY = "__bunny_metro_cache_key__";
|
||||
|
|
@ -65,9 +65,9 @@ export async function initMetroCache() {
|
|||
}
|
||||
}
|
||||
|
||||
const saveCache = throttle(() => {
|
||||
const saveCache = debounce(() => {
|
||||
MMKVManager.setItem(BUNNY_METRO_CACHE_KEY, JSON.stringify(_metroCache));
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
function extractExportsFlags(moduleExports: any) {
|
||||
if (!moduleExports) return 0;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue