From 8161a07dba401f04dac93f861e6b2cffe53ab7e3 Mon Sep 17 00:00:00 2001
From: Vendicated <vendicated@riseup.net>
Date: Sat, 1 Oct 2022 00:42:50 +0200
Subject: Add in client updater, Notices API

---
 src/utils/misc.tsx | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

(limited to 'src/utils/misc.tsx')

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(" ");
+}
-- 
cgit 

