Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Unified Diff: ios/web/webui/resources/web_ui_module_load_notifier.js

Issue 1929783002: [ios Mojo] Supporting code for define WebUI function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo_require_js
Patch Set: Merged with require.js CL Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/web/webui/resources/web_ui_bundle.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..36979e59ee841e09f2647092bc29783f221a9212
--- /dev/null
+++ b/ios/web/webui/resources/web_ui_module_load_notifier.js
@@ -0,0 +1,54 @@
+// 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_ = {};
+};
+
+/**
+ * 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.
+ * @return {String} Identifier for the added context, can be later used for
dpapad 2016/04/28 22:29:20 s/String/string/
Eugene But (OOO till 7-30) 2016/04/29 00:10:41 Done.
+ * {@code moduleLoadCompleted} and {@code moduleLoadFailed} arguments.
+ */
+WebUIModuleLoadNotifier.prototype.addPendingContext = function(name, context) {
+ var loadId = this.lastUsedId_ + 1;
+ this.lastUsedId_ = loadId;
dpapad 2016/04/28 22:29:20 I am confused by lines 24-25, it seems that loadId
dpapad 2016/04/28 22:29:20 I am confused by lines 24-25, it seems that loadId
Eugene But (OOO till 7-30) 2016/04/29 00:10:41 Done.
+ var key = name + loadId;
+ this.pendingContexts_[key] = context;
+ return String(loadId);
+}
dpapad 2016/04/28 22:29:20 Nit: Semicolon missing, here and elsewhere.
+
+/**
+ * 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) {
+ var key = name + loadId;
+ var context = this.pendingContexts_[key];
+ delete this.pendingContexts_[key];
+ return context;
+}
« no previous file with comments | « ios/web/webui/resources/web_ui_bundle.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698