<commit_before>D.Store = class Store extends D.Base {
    constructor (mod, options) {
        super('Store', options, {
            app: mod.app,
            module: mod,
            _models: {}
        });

        this.app.delegateEvent(this);

        this._callbacks = this._option('callbacks');
        mapObj(this._callbacks, (value, key) => {
            if (key.slice(0, 4) !== 'app.') return;
            this.listenTo(this.app, key, (payload) => value.call(this._callbackContext, payload));
        });
    }

    get models () {return this._models;}

    dispatch (name, payload) {
        let callback, n = name, p = payload;
        if (D.isObject(n)) {
            p = n.payload;
            n = n.name;
        }

        callback = this._callbacks[n];
        if (!callback) this._error(`No action callback for name: ${name}`);
        return this.chain(callback.call(this._callbackContext, p));
    }

    _initialize () {
        this._initializeModels();
        this._callbackContext = assign({
            models: this.models,
            module: this.module,
            app: this.app
        }, D.Request);
    }

    _initializeModels () {
        mapObj(this._option('models'), (value, key) => {<commit_msg>provide a way for module to listen to the change of shared models<commit_after>D.Store = class Store extends D.Base {
    constructor (mod, options) {
        super('Store', options, {
            app: mod.app,
            module: mod,
            _models: {}
        });

        this.app.delegateEvent(this);

        this._callbacks = this._option('callbacks');
        mapObj(this._callbacks, (value, key) => {
            if (key.slice(0, 4) === 'app.') {
                this.listenTo(this.app, key, (payload) => value.call(this._callbackContext, payload));
                return;
            }

            if (key.slice(0, 7) === 'shared.') {
                const name = key.slice(7), model = this._models[name];
                if (!model || model.store === this) this._error(`Can not bind to model: ${key}`);
                this.listenTo(model, 'changed', () => value.call(this._callbackContext));
            }
        });
    }

    get models () {return this._models;}

    dispatch (name, payload) {
        let callback, n = name, p = payload;
        if (D.isObject(n)) {
            p = n.payload;
            n = n.name;
        }

        callback = this._callbacks[n];
        if (!callback) this._error(`No action callback for name: ${name}`);
        return this.chain(callback.call(this._callbackContext, p));
    }

    _initialize () {
        this._initializeModels();
        this._callbackContext = assign({
            app: this.app,
            models: this.models,
            module: this.module,
            chain: this.chain
        }, D.Request);

        this._callbackContext.Promise = new D.Promise(this._callbackContext);
    }

    _initializeModels () {
        mapObj(this._option('models'), (value, key) => {
{'fraction_non_alphanumeric': 0.14462671576832942, 'fraction_numerical': 0.002343488449949782, 'mean_word_length': 1.8620689655172413, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '6371646', 'n_tokens_mistral': 862, 'n_tokens_neox': 839, 'n_words': 195}