Chromium Code Reviews| Index: ios/web/webui/resources/web_ui_module_load_notifier.js |
| diff --git a/ios/web/webui/resources/web_ui_module_load_notifier.js b/ios/web/webui/resources/web_ui_module_load_notifier.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..52d2a2811f226d3dfaf04e8ae88accdc092a2cae |
| --- /dev/null |
| +++ b/ios/web/webui/resources/web_ui_module_load_notifier.js |
| @@ -0,0 +1,53 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +goog.provide('__crWeb.webUIModuleLoadNotifier'); |
| + |
| +/** |
| + * A holder class for require.js contexts whose load is pending. |
| + * @constructor |
| + */ |
| +var WebUIModuleLoadNotifier = function() { |
| + this.lastUsedId_ = 0; |
| + this.pendingContexts_ = {}; |
|
dpapad
2016/05/05 17:19:59
Does native Map (https://developer.mozilla.org/en-
Eugene But (OOO till 7-30)
2016/05/05 18:43:49
It works. Thanks!
|
| +}; |
| + |
| +/** |
| + * Adds the given context to the list of pending contexts. |
| + * @param {string} name Name of the module that will be loaded. |
| + * @param {Object} context Require.js context to hold. |
|
dpapad
2016/05/05 17:19:59
It does not seem that null/undefined values should
Eugene But (OOO till 7-30)
2016/05/05 18:43:49
Done.
|
| + * @return {string} Identifier for the added context, can be later used for |
| + * {@code moduleLoadCompleted} and {@code moduleLoadFailed} arguments. |
| + */ |
| +WebUIModuleLoadNotifier.prototype.addPendingContext = function(name, context) { |
| + this.lastUsedId_++; |
| + var key = name + this.lastUsedId_; |
| + this.pendingContexts_[key] = context; |
|
dpapad
2016/05/05 17:19:59
Should there be a check that there is no entry for
Eugene But (OOO till 7-30)
2016/05/05 18:43:49
key is always a new string, because |lastUsedId_|
|
| + return String(this.lastUsedId_); |
| +}; |
| + |
| +/** |
| + * Signals that module has successfully loaded. |
| + * @param {string} name Name of the module that has been loaded. |
| + * @param {String} loadId Identifier returned from {@code addPendingContext}. |
| + */ |
| +WebUIModuleLoadNotifier.prototype.moduleLoadCompleted = function(name, loadId) { |
| + this.popContext_(name, loadId).completeLoad(name); |
| +}; |
| + |
| +/** |
| + * Signals that module has failed to load. |
| + * @param {string} name Name of the module that has failed to load. |
| + * @param {String} loadId Identifier returned from {@code addPendingContext}. |
| + */ |
| +WebUIModuleLoadNotifier.prototype.moduleLoadFailed = function(name, loadId) { |
| + this.popContext_(name, loadId).onScriptFailure(name); |
| +}; |
| + |
| +WebUIModuleLoadNotifier.prototype.popContext_ = function(name, loadId) { |
|
dpapad
2016/05/05 17:19:59
Type annotations missing.
Eugene But (OOO till 7-30)
2016/05/05 18:43:49
Done.
|
| + var key = name + loadId; |
| + var context = this.pendingContexts_[key]; |
| + delete this.pendingContexts_[key]; |
| + return context; |
| +}; |