123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- goog.provide('goog.module.ModuleInfo');
- goog.require('goog.Disposable');
- goog.require('goog.async.throwException');
- goog.require('goog.functions');
- goog.require('goog.module');
- goog.require('goog.module.BaseModule');
- goog.require('goog.module.ModuleLoadCallback');
- goog.forwardDeclare('goog.module.ModuleManager.FailureType');
- goog.module.ModuleInfo = function(deps, id) {
- goog.Disposable.call(this);
-
- this.deps_ = deps;
-
- this.id_ = id;
-
- this.onloadCallbacks_ = [];
-
- this.onErrorCallbacks_ = [];
-
- this.earlyOnloadCallbacks_ = [];
- };
- goog.inherits(goog.module.ModuleInfo, goog.Disposable);
- goog.module.ModuleInfo.prototype.uris_ = null;
- goog.module.ModuleInfo.prototype.moduleConstructor_ = goog.module.BaseModule;
- goog.module.ModuleInfo.prototype.module_ = null;
- goog.module.ModuleInfo.prototype.getDependencies = function() {
- return this.deps_;
- };
- goog.module.ModuleInfo.prototype.getId = function() {
- return this.id_;
- };
- goog.module.ModuleInfo.prototype.setUris = function(uris) {
- this.uris_ = uris;
- };
- goog.module.ModuleInfo.prototype.getUris = function() {
- return this.uris_;
- };
- goog.module.ModuleInfo.prototype.setModuleConstructor = function(constructor) {
- if (this.moduleConstructor_ === goog.module.BaseModule) {
- this.moduleConstructor_ = constructor;
- } else {
- throw Error('Cannot set module constructor more than once.');
- }
- };
- goog.module.ModuleInfo.prototype.registerEarlyCallback = function(
- fn, opt_handler) {
- return this.registerCallback_(this.earlyOnloadCallbacks_, fn, opt_handler);
- };
- goog.module.ModuleInfo.prototype.registerCallback = function(fn, opt_handler) {
- return this.registerCallback_(this.onloadCallbacks_, fn, opt_handler);
- };
- goog.module.ModuleInfo.prototype.registerErrback = function(fn, opt_handler) {
- return this.registerCallback_(this.onErrorCallbacks_, fn, opt_handler);
- };
- goog.module.ModuleInfo.prototype.registerCallback_ = function(
- callbacks, fn, opt_handler) {
- var callback = new goog.module.ModuleLoadCallback(fn, opt_handler);
- callbacks.push(callback);
- return callback;
- };
- goog.module.ModuleInfo.prototype.isLoaded = function() {
- return !!this.module_;
- };
- goog.module.ModuleInfo.prototype.getModule = function() {
- return this.module_;
- };
- goog.module.ModuleInfo.prototype.onLoad = function(contextProvider) {
-
- var module = new this.moduleConstructor_;
- module.initialize(contextProvider());
-
- this.module_ = module;
-
- var errors =
- !!this.callCallbacks_(this.earlyOnloadCallbacks_, contextProvider());
-
- errors =
- errors || !!this.callCallbacks_(this.onloadCallbacks_, contextProvider());
- if (!errors) {
-
- this.onErrorCallbacks_.length = 0;
- }
- return errors;
- };
- goog.module.ModuleInfo.prototype.onError = function(cause) {
- var result = this.callCallbacks_(this.onErrorCallbacks_, cause);
- if (result) {
-
-
- window.setTimeout(
- goog.functions.error('Module errback failures: ' + result), 0);
- }
- this.earlyOnloadCallbacks_.length = 0;
- this.onloadCallbacks_.length = 0;
- };
- goog.module.ModuleInfo.prototype.callCallbacks_ = function(callbacks, context) {
-
-
-
-
-
-
-
-
-
-
-
- var errors = [];
- for (var i = 0; i < callbacks.length; i++) {
- try {
- callbacks[i].execute(context);
- } catch (e) {
- goog.async.throwException(e);
- errors.push(e);
- }
- }
-
- callbacks.length = 0;
- return errors.length ? errors : null;
- };
- goog.module.ModuleInfo.prototype.disposeInternal = function() {
- goog.module.ModuleInfo.superClass_.disposeInternal.call(this);
- goog.dispose(this.module_);
- };
|