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

Unified Diff: mojo/public/js/new_bindings/base.js

Issue 2759563004: Mojo JS bindings: change module loading solution. (Closed)
Patch Set: add test module-loading.html Created 3 years, 9 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
Index: mojo/public/js/new_bindings/base.js
diff --git a/mojo/public/js/new_bindings/base.js b/mojo/public/js/new_bindings/base.js
new file mode 100644
index 0000000000000000000000000000000000000000..31173957a4790d0bf3e23e16740116a4d0900b10
--- /dev/null
+++ b/mojo/public/js/new_bindings/base.js
@@ -0,0 +1,31 @@
+// Copyright 2017 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.
+
+if (mojoBindings) {
+ throw new Error("mojoBindings has been initialized.");
+}
+
+var mojoBindings = {};
Ken Rockot(use gerrit already) 2017/03/20 15:27:20 I wonder about naming here, but it's kind of just
yzshen1 2017/03/20 17:45:02 According to JS style guide, namespace should be n
Ken Rockot(use gerrit already) 2017/03/21 16:42:43 I agree with this rationale, so SGTM. In fact I wa
alokp 2017/03/27 01:56:25 Bikeshed: I find mojoBindings ugly :) I am open t
+mojoBindings.internal = {};
+mojoBindings.internal.global = this;
+
+(function() {
+ var internal = mojoBindings.internal;
+
+ function exposeNamespace(namespace) {
+ var current = internal.global;
+ var parts = namespace.split('.');
+
+ for (var part; parts.length && (part = parts.shift());) {
+ if (!current[part]) {
+ current[part] = {};
+ }
+ current = current[part];
+ }
+
+ return current;
+ }
+
+ internal.exposeNamespace = exposeNamespace;
+})();

Powered by Google App Engine
This is Rietveld 408576698