Adrian Ehrsam 1 рік тому
батько
коміт
6dfe5a3925
2 змінених файлів з 35 додано та 34 видалено
  1. 1 34
      nicegui/elements/aggrid.js
  2. 34 0
      nicegui/static/utils/dynamic_obj.js

+ 1 - 34
nicegui/elements/aggrid.js

@@ -1,37 +1,4 @@
-function recursive_has_dynamic(obj) {
-  if (typeof obj !== "object" || obj === null) return false;
-  if (Array.isArray(obj)) {
-    return obj.some((v) => recursive_has_dynamic(v));
-  }
-  for (const [key, value] of Object.entries(obj)) {
-    if (key.startsWith(":")) return true;
-    if (recursive_has_dynamic(value)) {
-      return true;
-    }
-  }
-  return false;
-}
-
-function recursive_convert_dynamic(obj) {
-  if (!recursive_has_dynamic(obj)) return obj; // double-loop hierarchy is probably safer and uses less RAM if dynamic not used
-  if (typeof obj !== "object" || obj === null) return obj;
-  if (Array.isArray(obj)) {
-    return obj.map((v) => recursive_convert_dynamic(v));
-  }
-  const targetObj = {};
-  for (const [attr, value] of Object.entries(obj)) {
-    if (attr.startsWith(":")) {
-      try {
-        targetObj[attr.slice(1)] = new Function("return " + value)();
-      } catch (e) {
-        console.error(`Error while converting ${attr} attribute to function:`, e);
-      }
-    } else {
-      targetObj[attr] = recursive_convert_dynamic(value);
-    }
-  }
-  return targetObj;
-}
+import { recursive_convert_dynamic } from "../../static/utils/dynamic_obj.js";
 
 export default {
   template: "<div></div>",

+ 34 - 0
nicegui/static/utils/dynamic_obj.js

@@ -0,0 +1,34 @@
+export function recursive_has_dynamic(obj) {
+  if (typeof obj !== "object" || obj === null) return false;
+  if (Array.isArray(obj)) {
+    return obj.some((v) => recursive_has_dynamic(v));
+  }
+  for (const [key, value] of Object.entries(obj)) {
+    if (key.startsWith(":")) return true;
+    if (recursive_has_dynamic(value)) {
+      return true;
+    }
+  }
+  return false;
+}
+
+export function recursive_convert_dynamic(obj) {
+  if (!recursive_has_dynamic(obj)) return obj; // double-loop hierarchy is probably safer and uses less RAM if dynamic not used
+  if (typeof obj !== "object" || obj === null) return obj;
+  if (Array.isArray(obj)) {
+    return obj.map((v) => recursive_convert_dynamic(v));
+  }
+  const targetObj = {};
+  for (const [attr, value] of Object.entries(obj)) {
+    if (attr.startsWith(":")) {
+      try {
+        targetObj[attr.slice(1)] = new Function("return " + value)();
+      } catch (e) {
+        console.error(`Error while converting ${attr} attribute to function:`, e);
+      }
+    } else {
+      targetObj[attr] = recursive_convert_dynamic(value);
+    }
+  }
+  return targetObj;
+}