Path: blob/trunk/third_party/closure/goog/module/moduleloadcallback.js
2868 views
// Copyright 2008 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview A simple callback mechanism for notification about module16* loads. Should be considered package-private to goog.module.17*18*/1920goog.provide('goog.module.ModuleLoadCallback');2122goog.require('goog.debug.entryPointRegistry');23/** @suppress {extraRequire} */24goog.require('goog.module');25262728/**29* Class used to encapsulate the callbacks to be called when a module loads.30* @param {Function} fn Callback function.31* @param {Object=} opt_handler Optional handler under whose scope to execute32* the callback.33* @constructor34* @final35*/36goog.module.ModuleLoadCallback = function(fn, opt_handler) {37/**38* Callback function.39* @type {Function}40* @private41*/42this.fn_ = fn;4344/**45* Optional handler under whose scope to execute the callback.46* @type {Object|undefined}47* @private48*/49this.handler_ = opt_handler;50};515253/**54* Completes the operation and calls the callback function if appropriate.55* @param {*} context The module context.56*/57goog.module.ModuleLoadCallback.prototype.execute = function(context) {58if (this.fn_) {59this.fn_.call(this.handler_ || null, context);60this.handler_ = null;61this.fn_ = null;62}63};646566/**67* Abort the callback, but not the actual module load.68*/69goog.module.ModuleLoadCallback.prototype.abort = function() {70this.fn_ = null;71this.handler_ = null;72};737475// Register the browser event handler as an entry point, so that76// it can be monitored for exception handling, etc.77goog.debug.entryPointRegistry.register(78/**79* @param {function(!Function): !Function} transformer The transforming80* function.81*/82function(transformer) {83goog.module.ModuleLoadCallback.prototype.execute =84transformer(goog.module.ModuleLoadCallback.prototype.execute);85});868788