<commit_before>/**
 * @link http://www.blendjs.com/
 * @copyright Copyright (c) 2014 TrueSoftware B.V.
 * @license http://www.blendjs.com/license/
 */

/**
 * This class can be used to derive controller classes that can be used to
 * controll UI and other component behaviours.
 */
Blend.defineClass('Blend.mvc.Controller', {
    requires: [
        'Blend.mvc.Context',
        'Blend.mvc.Model'
    ],
    refs: null,
    /**
     * @private
     * The context id of the mvc context hosting this controller
     */
    mvcContextId: null,
    /**
     * Runs a function that is delegated for an object reference.
     * @param {string} ref name ofthe reference
     * @param {string} handler name of the handler (click,dag...)
     * @param {object[]} args arguments to pass to the handler
     * @private
     */
    delegate: function (ref, handler, args) {
        var me = this;
        var refObj = me[ref] || null;
        if (Blend.isObject(refObj)) {
            var refHandler = refObj[handler] || null;
            if (Blend.isObject(refObj) && Blend.isFunction(refHandler)) {
                setTimeout(function () {
                    refHandler.apply(me, args);
                }, 3);
            }
        }
    },
    /**
     * Gets the reference to an object from a component or a view. This function
     * will either return a single object or an array of objects if there are
     * multiple object with the same reference name.
     * @param {string} refName name of the reference to search.
     * @return {object/object[]} A single object or an array of objects.
     */
    getReference: function (refName) {
        var me = this;
        if (me.refs[refName]) {
            if (me.refs[refName].length === 1) {
                return me.refs[refName][0];
            } else {
                return me.refs[refName];
            }
        } else {
            return null;
        }
    },
    /**
     * Sets the reference of a component in this controller. This function is
     * internal and should not be used, unless you are absolutely sure of what
     * you are doing. When a reference for component is set, this class automatically
     * will try to create a getter function for the given component. For example if set the
     * a component by refName="text", a function that is called getText(...) will automatically
     * be created in this controller. This function optionally consumes a filter callback
     * that can be used to filter a result of the getter function when the getter returns an
     * array of objects.
     * @private
     * @param {string} refName the name of the reference.
     * @param {object} obj The object to create the refenece for.
     */
    setReference: function (refName, obj) {
        var me = this, getterName, filter;
        if (!me.refs[refName]) {
            getterName = 'get' + Blend.camelCase(refName);
            me[getterName] = function (filter) {
                filter = Blend.isFunction(filter) ? filter : function () {
                    return arguments;
                };
                var values = me.getReference(refName);
                if (Blend.isArray(values)) {
                    return filter.apply(me, [values]);
                } else {
                    return values;
                }
            }
            me.refs[refName] = [obj];
        } else {
            me.refs[refName].push(obj);
        }
    },
    init: function () {
        var me = this;
        me.callParent.apply(me, arguments);
        me.refs = {};
        if (!me.mvcContextId) {
            throw new Error("This controller is not in any MVC context. Are you trying to instantiate this controller manually?");
        }
    },
    getMVCContext: function () {
        return Blend.mvc.Context.getMVCContext(this.mvcContextId);
    }
});
<commit_msg>Added model handling to the Controller<commit_after>/**
 * @link http://www.blendjs.com/
 * @copyright Copyright (c) 2014 TrueSoftware B.V.
 * @license http://www.blendjs.com/license/
 */

/**
 * This class can be used to derive controller classes that can be used to
 * controll UI and other component behaviours.
 */
Blend.defineClass('Blend.mvc.Controller', {
    requires: [
        'Blend.mvc.Context',
        'Blend.mvc.Model'
    ],
    models: null,
    refs: null,
    /**
     * @private
     * The context id of the mvc context hosting this controller
     */
    mvcContextId: null,
    /**
     * Runs a function that is delegated for an object reference.
     * @param {string} ref name ofthe reference
     * @param {string} handler name of the handler (click,dag...)
     * @param {object[]} args arguments to pass to the handler
     * @private
     */
    delegate: function (ref, handler, args) {
        var me = this;
        var refObj = me[ref] || null;
        if (Blend.isObject(refObj)) {
            var refHandler = refObj[handler] || null;
            if (Blend.isObject(refObj) && Blend.isFunction(refHandler)) {
                setTimeout(function () {
                    refHandler.apply(me, args);
                }, 3);
            }
        }
    },
    /**
     * Gets the reference to an object from a component or a view. This function
     * will either return a single object or an array of objects if there are
     * multiple object with the same reference name.
     * @param {string} refName name of the reference to search.
     * @return {object/object[]} A single object or an array of objects.
     */
    getReference: function (refName) {
        var me = this;
        if (me.refs[refName]) {
            if (me.refs[refName].length === 1) {
                return me.refs[refName][0];
            } else {
                return me.refs[refName];
            }
        } else {
            return null;
        }
    },
    /**
     * Sets the reference of a component in this controller. This function is
     * internal and should not be used, unless you are absolutely sure of what
     * you are doing. When a reference for component is set, this class automatically
     * will try to create a getter function for the given component. For example if set the
     * a component by refName="text", a function that is called getText(...) will automatically
     * be created in this controller. This function optionally consumes a filter callback
     * that can be used to filter a result of the getter function when the getter returns an
     * array of objects.
     * @private
     * @param {string} refName the name of the reference.
     * @param {object} obj The object to create the refenece for.
     */
    setReference: function (refName, obj) {
        var me = this, getterName, filter;
        if (!me.refs[refName]) {
            getterName = 'get' + Blend.camelCase(refName);
            me[getterName] = function (filter) {
                filter = Blend.isFunction(filter) ? filter : function () {
                    return arguments;
                };
                var values = me.getReference(refName);
                if (Blend.isArray(values)) {
                    return filter.apply(me, [values]);
                } else {
                    return values;
                }
            }
            me.refs[refName] = [obj];
        } else {
            me.refs[refName].push(obj);
        }
    },
    init: function () {
        var me = this;
        me.callParent.apply(me, arguments);
        me.refs = {};
        me.models = me.models || {};
        if (!me.mvcContextId) {
            throw new Error("This controller is not in any MVC context. Are you trying to instantiate this controller manually?");
        }
        me.initModels();
    },
    initModels: function () {
        /**
         * There can only be one instance of a model with a context (application or window).
         * Therefore models will be registered and/or referenced within the application/window itself
         */
        var me = this,
                context = Blend.mvc.Context.getMVCContext(me.mvcContextId);
        context._models = context._models || {};
        Blend.foreach(me.models, function (model, name) {
            if (context._models[name]) {
                me.models[name] = context._models[name];
            } else {
                context._models[name] = Blend.create(model);
                me.models[name] = context._models[name];
            }
        });
    },
    getMVCContext: function () {
        return Blend.mvc.Context.getMVCContext(this.mvcContextId);
    }
});

{'fraction_non_alphanumeric': 0.10274454609429978, 'fraction_numerical': 0.0016420361247947454, 'mean_word_length': 1.8914886402170228, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '739205', 'n_tokens_mistral': 2358, 'n_tokens_neox': 2286, 'n_words': 796}