mirror of
https://git.um-react.app/um/um-react.git
synced 2026-11-25 14:56:58 +00:00
refactor: major package updates
This commit is contained in:
1 parent
2e52c67533
commit
a11caaae92
34 files changed
+373
-240
No files matched your search
@@ -0,0 +1,28 @@
|
||||
export class SimpleQueue {
|
||||
private queue: (() => void)[] = [];
|
||||
private running = 0;
|
||||
|
||||
constructor(private concurrency: number) {}
|
||||
|
||||
async enter() {
|
||||
return new Promise<void>((resolve) => {
|
||||
this.queue.push(resolve);
|
||||
setTimeout(this.next);
|
||||
});
|
||||
}
|
||||
|
||||
leave() {
|
||||
this.running--;
|
||||
setTimeout(this.next);
|
||||
}
|
||||
|
||||
private next = () => {
|
||||
while (this.running < this.concurrency && this.queue.length > 0) {
|
||||
const fn = this.queue.shift();
|
||||
if (fn) {
|
||||
this.running++;
|
||||
setTimeout(fn);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -50,7 +50,7 @@ export class WorkerClientBus<T = string> {
|
||||
|
||||
async request<R, P>(actionName: T, payload: P): Promise<R> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const id = `request://${actionName}/${nanoid()}`;
|
||||
const id = `request://${actionName as string}/${nanoid()}`;
|
||||
this.idPromiseMap.set(id, [resolve, reject]);
|
||||
this.worker.postMessage({
|
||||
id,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ConcurrentQueue } from '../ConcurrentQueue';
|
||||
import { nextTickAsync } from '../nextTick';
|
||||
|
||||
class SimpleQueue<T, R = void> extends ConcurrentQueue<T> {
|
||||
handler(_item: T): Promise<R> {
|
||||
handler(this: void, _item: T): Promise<R> {
|
||||
throw new Error('Method not overridden');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ test('should be able to forward request to worker client bus', async () => {
|
||||
const bus = new WorkerClientBus<DECRYPTION_WORKER_ACTION_NAME>(null as never);
|
||||
vi.spyOn(bus, 'request').mockImplementation(
|
||||
async (actionName: DECRYPTION_WORKER_ACTION_NAME, payload: unknown): Promise<unknown> => {
|
||||
return { actionName, payload };
|
||||
return Promise.resolve({ actionName, payload });
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
export function applyTemplate(tpl: string, values: Record<string, unknown>) {
|
||||
return tpl.replace(/\{\{\s*(\w+)\s*\}\}/g, (_, key) => (Object.hasOwn(values, key) ? String(values[key]) : ''));
|
||||
return tpl.replace(/\{\{\s*(\w+)\s*\}\}/g, (_, key: string) =>
|
||||
Object.hasOwn(values, key) ? String(values[key]) : '',
|
||||
);
|
||||
}
|
||||
@@ -1,12 +1,8 @@
|
||||
import { toast } from 'react-toastify';
|
||||
|
||||
export const copyToClipboard = (text: string) => {
|
||||
navigator.clipboard
|
||||
.writeText(text)
|
||||
.then(() => {
|
||||
toast.success('已复制到剪贴板');
|
||||
})
|
||||
.catch((err) => {
|
||||
toast.error(`复制失败,请手动复制\n${err}`);
|
||||
});
|
||||
navigator.clipboard.writeText(text).then(
|
||||
() => toast.success('已复制到剪贴板'),
|
||||
(err) => toast.error(`复制失败,请手动复制。\n错误: ${err as Error}`),
|
||||
);
|
||||
};
|
||||
@@ -1,3 +1,3 @@
|
||||
export function deepClone<T>(obj: T): T {
|
||||
return JSON.parse(JSON.stringify(obj));
|
||||
return JSON.parse(JSON.stringify(obj)) as T;
|
||||
}
|
||||
Reference in new issue
Block a user