aboutsummaryrefslogtreecommitdiff
path: root/src/utils/misc.tsx
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2022-10-01 00:42:50 +0200
committerVendicated <vendicated@riseup.net>2022-10-01 00:42:50 +0200
commit8161a07dba401f04dac93f861e6b2cffe53ab7e3 (patch)
tree1499e825bcd6a162bc43507f492b262e9b1901ed /src/utils/misc.tsx
parent9aaa47ea4e9ac068bf5fcbb997e31d722f43f1e5 (diff)
downloadVencord-8161a07dba401f04dac93f861e6b2cffe53ab7e3.tar.gz
Vencord-8161a07dba401f04dac93f861e6b2cffe53ab7e3.tar.bz2
Vencord-8161a07dba401f04dac93f861e6b2cffe53ab7e3.zip
Add in client updater, Notices API
Diffstat (limited to 'src/utils/misc.tsx')
-rw-r--r--src/utils/misc.tsx30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/utils/misc.tsx b/src/utils/misc.tsx
index 8a9afe1..4159906 100644
--- a/src/utils/misc.tsx
+++ b/src/utils/misc.tsx
@@ -1,3 +1,4 @@
+import { FilterFn, find } from "../webpack";
import { React } from "../webpack/common";
/**
@@ -7,9 +8,22 @@ import { React } from "../webpack/common";
*/
export function lazy<T>(factory: () => T): () => T {
let cache: T;
- return () => {
- return cache ?? (cache = factory());
- };
+ return () => cache ?? (cache = factory());
+}
+
+/**
+ * Do a lazy webpack search. Searches the module on first property access
+ * @param filter Filter function
+ * @returns Proxy. Note that only get and set are implemented, all other operations will have unexpected
+ * results.
+ */
+export function lazyWebpack<T = any>(filter: FilterFn): T {
+ const getMod = lazy(() => find(filter));
+
+ return new Proxy({}, {
+ get: (_, prop) => getMod()[prop],
+ set: (_, prop, v) => getMod()[prop] = v
+ }) as T;
}
/**
@@ -48,7 +62,7 @@ export function useAwaiter<T>(factory: () => Promise<T>, fallbackValue: T | null
export function LazyComponent<T = any>(factory: () => React.ComponentType<T>) {
return (props: T) => {
const Component = React.useMemo(factory, []);
- return <Component {...props} />;
+ return <Component {...props as any /* I hate react typings ??? */} />;
};
}
@@ -98,3 +112,11 @@ export function humanFriendlyJoin(elements: any[], mapper: (e: any) => string =
return s;
}
+
+/**
+ * Calls .join(" ") on the arguments
+ * classes("one", "two") => "one two"
+ */
+export function classes(...classes: string[]) {
+ return classes.join(" ");
+}