Source: _loader.js

"use strict";



/** 
 * @class _Loader
 * @description 
 *   A class to load a file.  This wraps a standard AJAX method and 
 *   Includes an xmit instance to more easily handle events.
 *   the fetch command performs the load and also returns a promise.
 *   <br>
 *   This unit is a pseudo class.  This is meant to be compiled with browserify and 
 *   aliasify.  If DEV_MODE environment variable is set to FINAL, this class 
 *   will load _LoaderAtom class, which contains no parameter validations.  Otherwise it 
 *   will load _Loader class which does.
 */

/**  
 * @constructor 
 *   
 * @param {string} url
 * @description default url to be loaded by this class.
 * @param {function} method (optional)
 * @descrition the method to be used . default is GET
 * @param {object} XmitType (optional)
 * @description Allows overriding of the standard Xmit type
 * @param {object} ChannelType (optional)
 * @description Allows overriding of the standard Channel type
 * @memberof _Loader
 */

/**
 * @function fetch
 * @description loads a file
 * @param {string} url (optional)
 * @description the url to be loaded.  if none, uses this._url
 * @param {string} method (optional) 
 * @description the method to use when loading.  If none, uses this._method
 * @memberof _Loader
 * @returns {object} Promise
 */

/**
 * @function on
 * @description proxies the xmit.on function to the loader API 
 * @param {*} channel_name
 * @description channel_name should be either a number or a string
 * @param {function} lambda (optional) 
 * @description the calback method 
 * @memberof _Loader
 * @returns {object} loader instance for continuations
 */
/**
 * @function loaded
 * @description proxies xmit.on(EVS.ON_LOAD) to the loader API
 * @param {function} lambda (optional) 
 * @description the calback method 
 * @memberof _Loader
 * @returns {object} loader instance for continuations
 */
/**
 * @function error
 * @description proxies xmit.on(EVS.ON_ERROR) to the loader API
 * @param {function} lambda (optional) 
 * @description the calback method 
 * @memberof _Loader
 * @returns {object} loader instance for continuations
 */

/** 
 * @function _on_load
 * @description internal use function to unlock the loader if 
 * a fetch (load) is completed.
 * @memberof _Loader
 */
/** 
 * @function _on_error
 * @description internal use function to unlock the loader if 
 * a fetch (load) is throws an error.
 * @memberof _Loader
 */


var __XB = require("xbrowser_debug"),
		assert = __XB.assert,
		log = __XB.log;

var LoaderAtom = require("./_loader_atom"),
	validateUrl = require("./___validate_url"),
	validateMethod = require("./___validate_method");

function Loader(url, method, XmitType, ChannelType){
	LoaderAtom.call(this, url, method, XmitType, ChannelType);
	validateUrl(this._url);
	validateMethod(this._method);
};

Loader.prototype = Object.create(LoaderAtom.prototype, 
	{ 
		"TYPE":{ 
			value:"LOADER"
		},
		"fetch":{ 
			value:function(url, method) { 
				validateUrl(url||this._url);
				validateMethod(method||this._method);
				return LoaderAtom.prototype.fetch.call(this, url, method);
			}
		}
	}
);

module.exports = Loader;