<commit_before>import { Component } from '../component';
import { Control } from '../control';

export interface View {
    [key: string]: Component | Component[] | (() => Component | Component[]);
}

export class View {
    private static _componentMap: {
        [mode: string]: {
            controls: Control[];
            components: Component[];
        };
    } = {};

    static viewName: string;

    static parent: typeof View | string;

    static getParent(): typeof View | undefined {
        if (typeof this.parent === 'string') return session.views[this.parent];
        return this.parent;
    }

    static getComponent(control: Control, mode: string): Component | null {
        // check in current view
        if (this._componentMap[mode] !== undefined) {
            const componentMapIndex = this._componentMap[mode].controls.indexOf(control);
            if (componentMapIndex !== -1) {
                return this._componentMap[mode].components[componentMapIndex];
            }
        }
        // component not found in view? check in parent
        const parent = this.getParent();
        if (parent) return parent.getComponent(control, mode);
        // not in current view, no parent to check? return null
        return null;
    }

    static connectControl(control: Control) {
        // check view modes in order for component/control registration
        let component = null;
        for (const activeMode of session.activeModes) {
            component = this.getComponent(control, activeMode);
            // if component is not null, we're done looking
            if (component) break;
        }
        // only set the component when it has changed
        if (control.activeComponent !== component) control.activeComponent = component;
    }

    static init() {
        const instance = new this();
        // give each subclass its own componentMap
        Object.getOwnPropertyNames(instance).map(key => {<commit_msg>Fix regrsssion in View init: add back unique componentMap for each subclass<commit_after>import { Component } from '../component';
import { Control } from '../control';

export interface View {
    [key: string]: Component | Component[] | (() => Component | Component[]);
}

export class View {
    private static _componentMap: {
        [mode: string]: {
            controls: Control[];
            components: Component[];
        };
    };

    static viewName: string;

    static parent: typeof View | string;

    static getParent(): typeof View | undefined {
        if (typeof this.parent === 'string') return session.views[this.parent];
        return this.parent;
    }

    static getComponent(control: Control, mode: string): Component | null {
        // check in current view
        if (this._componentMap[mode] !== undefined) {
            const componentMapIndex = this._componentMap[mode].controls.indexOf(control);
            if (componentMapIndex !== -1) {
                return this._componentMap[mode].components[componentMapIndex];
            }
        }
        // component not found in view? check in parent
        const parent = this.getParent();
        if (parent) return parent.getComponent(control, mode);
        // not in current view, no parent to check? return null
        return null;
    }

    static connectControl(control: Control) {
        // check view modes in order for component/control registration
        let component = null;
        for (const activeMode of session.activeModes) {
            component = this.getComponent(control, activeMode);
            // if component is not null, we're done looking
            if (component) break;
        }
        // only set the component when it has changed
        if (control.activeComponent !== component) control.activeComponent = component;
    }

    static init() {
        const instance = new this();
        // give each subclass its own componentMap
        this._componentMap = {};
        Object.getOwnPropertyNames(instance).map(key => {
{'fraction_non_alphanumeric': 0.10477849676455948, 'fraction_numerical': 0.0004977600796416127, 'mean_word_length': 2.3603678929765888, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4473550', 'n_tokens_mistral': 975, 'n_tokens_neox': 961, 'n_words': 330}