Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_ = {}; | |
|
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!
| |
| 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. | |
|
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.
| |
| 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_[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_|
| |
| 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 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.
| |
| 49 var key = name + loadId; | |
| 50 var context = this.pendingContexts_[key]; | |
| 51 delete this.pendingContexts_[key]; | |
| 52 return context; | |
| 53 }; | |
| OLD | NEW |