<commit_before>'use strict';

var Dispatcher = require('./vendor/Dispatcher');
var _ = require('./helper');

function FFluxDispatcher() {
    /**
     * Create facebook's dispatcher realization
     * @type {Dispatcher}
     */
    this._dispatcher = new Dispatcher();
    /**
     * Invoke dispatch method of the flux dispatcher's instance
     * @param {object} payload
     * @return true
     */
    this.dispatch = function(action) {
        this._dispatcher.dispatch.call(this._dispatcher, action);
    };
    
    /**
     * Bridge to dispatcher's waitFor
     * @param {array} arrayOfStores Array of stores to wait for
     */
    this.waitFor = function(arrayOfStores) {
        this._dispatcher.waitFor.call(this._dispatcher, arrayOfStores);
    };
}

_.extend(FFluxDispatcher.prototype, {
    /**
     * Register store to dispatcher
     * @param {FFluxStore} instance     FFluxStore instance
     * @return {string} Registration id
     */
    register: function(instance) {
        return this._dispatcher.register(function(action) {
            var type = action.type;
            var handler;
            // Get array of registered actions
            var actionKeys = _.keys(instance.actions);

            // If we have such actions listener(s), invoke 
            // related function with action provided
            actionKeys.forEach(function(key) {
                if (key === type) {
                    switch (typeof instance.actions[type]) {
                        case 'string':
                            handler = instance[instance.actions[type]];
                            break;
                        case 'function':
                            handler = instance.actions[type];
                            break;
                        default:
                            throw Error('You must specify handler for action ' + type);
                    }
                    
                    handler.call(instance, action.data);
                }
            });
        });
    },

    /**
     * Unregister store from dispatcher
     * @param {object} options  Binding identificator or store instance
     * @return {void}
     */
    unregister: function(options) {
        var id;

        if (typeof options === 'string') {
            id = options;
        } else {
            id = options._id;
        }

        this._dispatcher.unregister(id);
    }
});

module.exports = function() {
    return new FFluxDispatcher();
};<commit_msg>Fix register/unregister mechanism<commit_after>'use strict';

var Dispatcher = require('./vendor/Dispatcher');
var _ = require('./helper');

function FFluxDispatcher() {
    /**
     * Create facebook's dispatcher realization
     * @type {Dispatcher}
     */
    this._dispatcher = new Dispatcher();
    /**
     * Invoke dispatch method of the flux dispatcher's instance
     * @param {object} payload
     * @return true
     */
    this.dispatch = function(action) {
        this._dispatcher.dispatch.call(this._dispatcher, action);
    };
    
    /**
     * Bridge to dispatcher's waitFor
     * @param {array} arrayOfStores Array of stores to wait for
     */
    this.waitFor = function(arrayOfStores) {
        this._dispatcher.waitFor.call(this._dispatcher, arrayOfStores);
    };
}

_.extend(FFluxDispatcher.prototype, {
    /**
     * Register store to dispatcher
     * @param {FFluxStore} instance     FFluxStore instance
     * @return {void}
     */
    register: function(instance) {
        instance.dispatchToken = this._dispatcher.register(function(action) {
            var type = action.type;
            var handler;
            // Get array of registered actions
            var actionKeys = _.keys(instance.actions);

            // If we have such actions listener(s), invoke 
            // related function with action provided
            actionKeys.forEach(function(key) {
                if (key === type) {
                    switch (typeof instance.actions[type]) {
                        case 'string':
                            handler = instance[instance.actions[type]];
                            break;
                        case 'function':
                            handler = instance.actions[type];
                            break;
                        default:
                            throw Error('You must specify handler for action ' + type);
                    }
                    
                    handler.call(instance, action.data);
                }
            });
        });
    },

    /**
     * Unregister store from dispatcher
     * @param {object} options  Binding identificator or store instance
     * @return {void}
     */
    unregister: function(options) {
        var id;

        if (typeof options === 'string') {
            id = options;
        } else {
            id = options.dispatchToken;
        }

        this._dispatcher.unregister(id);
    }
});

module.exports = function() {
    return new FFluxDispatcher();
};
{'fraction_non_alphanumeric': 0.10411670663469225, 'fraction_numerical': 0.0, 'mean_word_length': 1.6040582726326742, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6298050', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1216, 'n_words': 312}