fix circular import bricking browser version
This commit is contained in:
parent
0f74817e25
commit
f39f16d34b
3 changed files with 26 additions and 19 deletions
23
src/utils/lazyReact.tsx
Normal file
23
src/utils/lazyReact.tsx
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* Vencord, a Discord client mod
|
||||||
|
* Copyright (c) 2023 Vendicated and contributors
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { makeLazy } from "./lazy";
|
||||||
|
|
||||||
|
const NoopComponent = () => null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A lazy component. The factory method is called on first render.
|
||||||
|
* @param factory Function returning a Component
|
||||||
|
* @param attempts How many times to try to get the component before giving up
|
||||||
|
* @returns Result of factory function
|
||||||
|
*/
|
||||||
|
export function LazyComponent<T extends object = any>(factory: () => React.ComponentType<T>, attempts = 5) {
|
||||||
|
const get = makeLazy(factory, attempts);
|
||||||
|
return (props: T) => {
|
||||||
|
const Component = get() ?? NoopComponent;
|
||||||
|
return <Component {...props} />;
|
||||||
|
};
|
||||||
|
}
|
|
@ -18,9 +18,10 @@
|
||||||
|
|
||||||
import { React, useEffect, useMemo, useReducer, useState } from "@webpack/common";
|
import { React, useEffect, useMemo, useReducer, useState } from "@webpack/common";
|
||||||
|
|
||||||
import { makeLazy } from "./lazy";
|
|
||||||
import { checkIntersecting } from "./misc";
|
import { checkIntersecting } from "./misc";
|
||||||
|
|
||||||
|
export * from "./lazyReact";
|
||||||
|
|
||||||
export const NoopComponent = () => null;
|
export const NoopComponent = () => null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -143,17 +144,3 @@ export function useTimer({ interval = 1000, deps = [] }: TimerOpts) {
|
||||||
|
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A lazy component. The factory method is called on first render.
|
|
||||||
* @param factory Function returning a Component
|
|
||||||
* @param attempts How many times to try to get the component before giving up
|
|
||||||
* @returns Result of factory function
|
|
||||||
*/
|
|
||||||
export function LazyComponent<T extends object = any>(factory: () => React.ComponentType<T>, attempts = 5) {
|
|
||||||
const get = makeLazy(factory, attempts);
|
|
||||||
return (props: T) => {
|
|
||||||
const Component = get() ?? NoopComponent;
|
|
||||||
return <Component {...props} />;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { proxyLazy } from "@utils/lazy";
|
import { proxyLazy } from "@utils/lazy";
|
||||||
|
import { LazyComponent } from "@utils/lazyReact";
|
||||||
import { Logger } from "@utils/Logger";
|
import { Logger } from "@utils/Logger";
|
||||||
import { LazyComponent } from "@utils/react";
|
|
||||||
import type { WebpackInstance } from "discord-types/other";
|
import type { WebpackInstance } from "discord-types/other";
|
||||||
|
|
||||||
import { traceFunction } from "../debug/Tracer";
|
import { traceFunction } from "../debug/Tracer";
|
||||||
|
@ -338,9 +338,6 @@ export function waitFor(filter: string | string[] | FilterFn, callback: Callback
|
||||||
else if (typeof filter !== "function")
|
else if (typeof filter !== "function")
|
||||||
throw new Error("filter must be a string, string[] or function, got " + typeof filter);
|
throw new Error("filter must be a string, string[] or function, got " + typeof filter);
|
||||||
|
|
||||||
const [existing, id] = find(filter!, { isIndirect: true, isWaitFor: true });
|
|
||||||
if (existing) return void callback(existing, id);
|
|
||||||
|
|
||||||
subscriptions.set(filter, callback);
|
subscriptions.set(filter, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue