summaryrefslogtreecommitdiff
path: root/tools/winscope/spec/utils/tree.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/winscope/spec/utils/tree.js')
-rw-r--r--tools/winscope/spec/utils/tree.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/tools/winscope/spec/utils/tree.js b/tools/winscope/spec/utils/tree.js
new file mode 100644
index 000000000..379ebaf46
--- /dev/null
+++ b/tools/winscope/spec/utils/tree.js
@@ -0,0 +1,33 @@
+class Node {
+ constructor(nodeDef, children) {
+ Object.assign(this, nodeDef);
+ this.children = children;
+ }
+}
+
+class DiffNode extends Node {
+ constructor(nodeDef, diffType, children) {
+ super(nodeDef, children);
+ this.diff = { type: diffType };
+ }
+}
+
+function isPrimitive(test) {
+ return test !== Object(test);
+};
+
+function toPlainObject(theClass) {
+ if (isPrimitive(theClass)) {
+ return theClass;
+ } else if (Array.isArray(theClass)) {
+ return theClass.map(item => toPlainObject(item));
+ } else {
+ const keys = Object.getOwnPropertyNames(Object.assign({}, theClass));
+ return keys.reduce((classAsObj, key) => {
+ classAsObj[key] = toPlainObject(theClass[key]);
+ return classAsObj;
+ }, {});
+ }
+}
+
+export { Node, DiffNode, toPlainObject }; \ No newline at end of file