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

Side by Side Diff: ios/web/webui/resources/web_ui_module_load_notifier.js

Issue 2946383002: Support new-style Mojo JS core API on IOS. (Closed)
Patch Set: . Created 3 years, 5 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 unified diff | Download patch
« no previous file with comments | « ios/web/webui/resources/web_ui_bundle.js ('k') | ios/web/webui/web_ui_mojo_inttest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 goog.provide('__crWeb.webUIModuleLoadNotifier');
6
7 /**
8 * A holder class for require.js contexts whose load is pending.
9 * @constructor
10 */
11 var WebUIModuleLoadNotifier = function() {
12 this.lastUsedId_ = 0;
13 this.pendingContexts_ = new Map();
14 };
15
16 /**
17 * Adds the given context to the list of pending contexts.
18 * @param {string} name Name of the module that will be loaded.
19 * @param {!Object} context Require.js context to hold.
20 * @return {string} Identifier for the added context, can be later used for
21 * {@code moduleLoadCompleted} and {@code moduleLoadFailed} arguments.
22 */
23 WebUIModuleLoadNotifier.prototype.addPendingContext = function(name, context) {
24 this.lastUsedId_++;
25 var key = name + this.lastUsedId_;
26 this.pendingContexts_.set(key, context);
27 return String(this.lastUsedId_);
28 };
29
30 /**
31 * Signals that module has successfully loaded.
32 * @param {string} name Name of the module that has been loaded.
33 * @param {String} loadId Identifier returned from {@code addPendingContext}.
34 */
35 WebUIModuleLoadNotifier.prototype.moduleLoadCompleted = function(name, loadId) {
36 this.popContext_(name, loadId).completeLoad(name);
37 };
38
39 /**
40 * Signals that module has failed to load.
41 * @param {string} name Name of the module that has failed to load.
42 * @param {String} loadId Identifier returned from {@code addPendingContext}.
43 */
44 WebUIModuleLoadNotifier.prototype.moduleLoadFailed = function(name, loadId) {
45 this.popContext_(name, loadId).onScriptFailure(name);
46 };
47
48 /**
49 * Pops the pending context.
50 * @param {string} name Name of the module that has failed to load.
51 * @param {String} loadId Identifier returned from {@code addPendingContext}.
52 * @return {Object} Require.js context
53 */
54 WebUIModuleLoadNotifier.prototype.popContext_ = function(name, loadId) {
55 var key = name + loadId;
56 var context = this.pendingContexts_.get(key);
57 this.pendingContexts_.delete(key);
58 return context;
59 };
OLDNEW
« no previous file with comments | « ios/web/webui/resources/web_ui_bundle.js ('k') | ios/web/webui/web_ui_mojo_inttest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698