<commit_before>module feather.hub {

    import TypedMap      = feather.types.TypedMap
    import EventAware    = feather.event.EventAware
    import ensure        = feather.objects.ensure
    import collect       = feather.objects.collectAnnotationsFromTypeMap
    import WidgetFactory = feather.boot.WidgetFactory

    export const subscribers    = new WeakMap<any, TypedMap<Subscriber[]>>()

    export class Subscriber {
        constructor(public event: string, public method: string) {
        }
    }

    export abstract class Subscribable extends EventAware {
        parentWidget: Subscribable
        childWidgets: Array<Subscribable> = []

        // noinspection JSUnusedGlobalSymbols
        triggerUp(event: string, data: any) {
            feather.hub.Subscribable.trigger(event, this, data)
            if (this.parentWidget) {
                this.parentWidget.triggerUp(event, data)
            }
        }

        // noinspection JSUnusedGlobalSymbols
        triggerSingleton(event: string, data: any) {
            WidgetFactory.singletonRegistry.forEach(w => feather.hub.Subscribable.trigger(event, w, data))
        }

        triggerDown(event: string, data: any) {
            feather.hub.Subscribable.trigger(event, this, data)
            if (this.childWidgets) {
                for (const child of this.childWidgets) {
                    child.triggerDown(event, data)
                }
            }
        }

        private static trigger(event: string, context: Subscribable, data: any) {
            const subs = collect(subscribers, context)
            if (subs[event]) {
                for (const sub of subs[event]) {
                    context[sub.method].call(context, data)
                }
            }
        }

        cleanUp() {
            super.cleanUp()
            subscribers.delete(this)
        }
    }

    export let Subscribe = (event: string) => (proto: Subscribable, method: string) =>
        ensure(subscribers, proto, {[event]: [new Subscriber(event, method)]})
}<commit_msg>fix typings<commit_after>module feather.hub {

    import TypedMap      = feather.types.TypedMap
    import EventAware    = feather.event.EventAware
    import ensure        = feather.objects.ensure
    import collect       = feather.objects.collectAnnotationsFromTypeMap
    import WidgetFactory = feather.boot.WidgetFactory

    export const subscribers    = new WeakMap<any, TypedMap<Subscriber[]>>()

    export class Subscriber {
        constructor(public event: string, public method: string) {
        }
    }

    export abstract class Subscribable extends EventAware {
        parentWidget: Subscribable
        childWidgets: Array<Subscribable> = []

        // noinspection JSUnusedGlobalSymbols
        triggerUp(event: string, ...data: any[]) {
            feather.hub.Subscribable.trigger(event, this, data)
            if (this.parentWidget) {
                this.parentWidget.triggerUp(event, ...data)
            }
        }

        // noinspection JSUnusedGlobalSymbols
        triggerSingleton(event: string, ...data: any[]) {
            WidgetFactory.singletonRegistry.forEach(w => feather.hub.Subscribable.trigger(event, w, data))
        }

        triggerDown(event: string, ...data: any[]) {
            feather.hub.Subscribable.trigger(event, this, data)
            if (this.childWidgets) {
                for (const child of this.childWidgets) {
                    child.triggerDown(event, ...data)
                }
            }
        }

        private static trigger(event: string, context: Subscribable, ...data: any[]) {
            const subs = collect(subscribers, context)
            if (subs[event]) {
                for (const sub of subs[event]) {
                    context[sub.method].apply(context, ...data)
                }
            }
        }

        cleanUp() {
            super.cleanUp()
            subscribers.delete(this)
        }
    }

    export let Subscribe = (event: string) => (proto: Subscribable, method: string) =>
        ensure(subscribers, proto, {[event]: [new Subscriber(event, method)]})
}
{'fraction_non_alphanumeric': 0.10126274890723652, 'fraction_numerical': 0.0, 'mean_word_length': 1.9956363636363637, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '240015', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1086, 'n_words': 241}