JSFiddle - React, Tailwind, and code Playground

by adelura

JavaScript

class Node {
            constructor (name, parent = null) {
                this.parent = parent;
                if (parent) {
                    parent.addChild(this);
                }

                this.name = name;
                this.children = [];
            }

            addChild (child) {
                this.children.push(child);
            }

            get path () {
                let path = [];
                let parent = this;

                while(parent && parent.name) {
                    path.unshift(parent.name);

                    parent = parent.parent;
                }

                return path;
            }

            get childrenPaths () {
                let paths = [];
                let path = this.path.join(".");

                for(let child of this.children) {
                    paths.push(`${path}.${child.name}`);
                }

                return paths;
            }
        }

        // let configs = {
        //     feature: {
        //         messageCentre: {
        //             enabled: Symbol(),
        //             disabled: Symbol()
        //         }
        //     }
        // };
        //
        // // @TODO: this require proper naming
        // function fetch(root, rootNode) {
        //     for (let key in root) {
        //         let node = new Node(key, rootNode);
        //
        //         fetch(root[key], node);
        //     }
        // }
        //
        // let CONFIGS;
        //
        // CONFIGS = new Node(null, null);
        //
        // fetch(configs, CONFIGS);

        // let feature = new Node("feature", CONFIGS);
        // let messageCentre = new Node("messageCentre", feature);
        // let disabled = new Node("disabled", messageCentre);
        // let enabled = new Node("enabled", messageCentre);