API Docs for: 0.0.8-0
Show:

File: javascript\src\RAMP\Utils\functionMangler.js

/* global define */

/**
* Utility module containint useful static classes.
*
* @module Utils
*/

/**
* ??? Description
*
*
* @class FunctionMangler
* @static
* @uses dojo/on
* @uses dojo/_base/lang
* @uses dojo/topic
* @uses Util
*/

define([
/* Dojo */
        "dojo/topic", "dojo/_base/lang", "dojo/on",

/* Utils */
        "utils/util"
    ],

    function (
    /* Dojo */
        topic, dojoLang, dojoOn,

    /* Utils */
        utilMisc) {
        "use strict";

        /**
        * [_initDojoPrototype description] Adds following extensions:
        * - `topic.subscrive(name, listener, scope)` - An extension of dojoLang.subscribe that allows the callback function to be
        * hitched with the given scope.
        * - `dojoOn(target, type, listener, scope)` -
        *
        *
        * @method _initDojoPrototype
        * @private
        */
        function _initDojoPrototype() {
            var originalOn = dojoOn;
            dojoOn = function (target, type, listener, scope) {
                if (utilMisc.isUndefined(scope)) {
                    return originalOn(target, type, listener);
                } else {
                    return originalOn(target, type, dojoLang.hitch(scope, listener));
                }
            };

            var originalSubscribe = topic.subscribe;
            topic.subscribe = function (eventName, listener) {
                if (utilMisc.isUndefined(eventName)) {
                    console.error("Trying to subscribe to an undefined event");
                    console.trace();
                } else {
                    return originalSubscribe(eventName, listener);
                }
            };
        }

        return {
            /**
            * [load description]
            *
            * @method load
            * @param  {[type]} id      [description]
            * @param  {[type]} require [description]
            * @param  {[type]} load    [description]
            * @return {[type]}         [description]
            */
            load: function (id, require, load) {
                _initDojoPrototype();

                load();
            }
        };
    });