Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/third_party/closure/goog/module/moduleloadcallback.js
2868 views
1
// Copyright 2008 The Closure Library Authors. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS-IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
/**
16
* @fileoverview A simple callback mechanism for notification about module
17
* loads. Should be considered package-private to goog.module.
18
*
19
*/
20
21
goog.provide('goog.module.ModuleLoadCallback');
22
23
goog.require('goog.debug.entryPointRegistry');
24
/** @suppress {extraRequire} */
25
goog.require('goog.module');
26
27
28
29
/**
30
* Class used to encapsulate the callbacks to be called when a module loads.
31
* @param {Function} fn Callback function.
32
* @param {Object=} opt_handler Optional handler under whose scope to execute
33
* the callback.
34
* @constructor
35
* @final
36
*/
37
goog.module.ModuleLoadCallback = function(fn, opt_handler) {
38
/**
39
* Callback function.
40
* @type {Function}
41
* @private
42
*/
43
this.fn_ = fn;
44
45
/**
46
* Optional handler under whose scope to execute the callback.
47
* @type {Object|undefined}
48
* @private
49
*/
50
this.handler_ = opt_handler;
51
};
52
53
54
/**
55
* Completes the operation and calls the callback function if appropriate.
56
* @param {*} context The module context.
57
*/
58
goog.module.ModuleLoadCallback.prototype.execute = function(context) {
59
if (this.fn_) {
60
this.fn_.call(this.handler_ || null, context);
61
this.handler_ = null;
62
this.fn_ = null;
63
}
64
};
65
66
67
/**
68
* Abort the callback, but not the actual module load.
69
*/
70
goog.module.ModuleLoadCallback.prototype.abort = function() {
71
this.fn_ = null;
72
this.handler_ = null;
73
};
74
75
76
// Register the browser event handler as an entry point, so that
77
// it can be monitored for exception handling, etc.
78
goog.debug.entryPointRegistry.register(
79
/**
80
* @param {function(!Function): !Function} transformer The transforming
81
* function.
82
*/
83
function(transformer) {
84
goog.module.ModuleLoadCallback.prototype.execute =
85
transformer(goog.module.ModuleLoadCallback.prototype.execute);
86
});
87
88