<commit_before>/**
 * Main application class.
 *
 * @export
 * @class App
 */
import {Child} from "./child/child";

export class App {
    /**
     * Run the application
     * @returns {void}
     */
    run() {
        this._router = [
            {route: ["", "child"], module: () => new Child()}
        ];

        this.locationChanged();
        window.addEventListener("popstate", () => this.locationChanged());
    }

    /**
     * The application location has changed try and locate a new module to display
     * @returns {void}
     */
    locationChanged() {
        const root = document.getElementById("root");

        const lookupRoute = (window.location.hash || "").replace(/^#\//, "");

        const foundRoute = this._router.find((testRoute) => this.matchRoute(lookupRoute, testRoute));
        if (foundRoute) {
            const module = foundRoute.module();
            while (root.hasChildNodes()) {
                root.removeChild(root.lastChild);
            }
            module.render(root);
        }
    }

    /**
     * Does the given route match
     * @param lookupRoute {string}
     * @param testRoute { route: string | string[]; module(): any }
     * @returns {void}
     */
    matchRoute(lookupRoute, testRoute) {
        return Array.isArray(testRoute.route)
            ? testRoute.route.indexOf(lookupRoute) >= 0 : testRoute.route === lookupRoute;
    }
}

// Generated by UniteJS<commit_msg>Update vanilla app documentation<commit_after>/**
 * Main application class.
 *
 * @export
 * @class App
 */
import {Child} from "./child/child";

export class App {
    /**
     * Run the application
     * @returns {void}
     */
    run() {
        this._router = [
            {route: ["", "child"], module: () => new Child()}
        ];

        this.locationChanged();
        window.addEventListener("popstate", () => this.locationChanged());
    }

    /**
     * The application location has changed try and locate a new module to display
     * @returns {void}
     */
    locationChanged() {
        const root = document.getElementById("root");

        const lookupRoute = (window.location.hash || "").replace(/^#\//, "");

        const foundRoute = this._router.find((testRoute) => this.matchRoute(lookupRoute, testRoute));
        if (foundRoute) {
            const module = foundRoute.module();
            while (root.hasChildNodes()) {
                root.removeChild(root.lastChild);
            }
            module.render(root);
        }
    }

    /**
     * Does the given route match
     * @param lookupRoute {string}
     * @param testRoute {route}
     * @returns {void}
     */
    matchRoute(lookupRoute, testRoute) {
        return Array.isArray(testRoute.route)
            ? testRoute.route.indexOf(lookupRoute) >= 0 : testRoute.route === lookupRoute;
    }
}

// Generated by UniteJS
{'fraction_non_alphanumeric': 0.1456072803640182, 'fraction_numerical': 0.0007000350017500875, 'mean_word_length': 2.137211855104281, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3394447', 'n_tokens_mistral': 791, 'n_tokens_neox': 780, 'n_words': 186}