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

Side by Side Diff: mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl

Issue 2779493002: Mojo JS bindings: support auto-loading mojom.js deps. (Closed)
Patch Set: . Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 {%- if use_new_js_bindings %} 5 {%- if use_new_js_bindings %}
6 6
7 "use strict"; 7 'use strict';
8 8
9 (function() { 9 (function() {
10 var mojomId = '{{module.path}}';
11 if (mojoBindings.internal.isMojomLoaded(mojomId)) {
12 console.warn('The following mojom is loaded multiple times: ' + mojomId);
13 return;
14 }
15 mojoBindings.internal.markMojomLoaded(mojomId);
16
10 // TODO(yzshen): Define these aliases to minimize the differences between the 17 // TODO(yzshen): Define these aliases to minimize the differences between the
11 // old/new modes. Remove them when the old mode goes away. 18 // old/new modes. Remove them when the old mode goes away.
12 var bindings = mojoBindings; 19 var bindings = mojoBindings;
13 var codec = mojoBindings.internal; 20 var codec = mojoBindings.internal;
14 var validator = mojoBindings.internal; 21 var validator = mojoBindings.internal;
22
15 {%- for import in imports %} 23 {%- for import in imports %}
16 var {{import.unique_name}} = {{import.module.namespace}}; 24 var {{import.unique_name}} =
25 mojoBindings.internal.exposeNamespace('{{import.module.namespace}}');
26 if (mojoBindings.config.auto_load_mojom_deps) {
27 mojoBindings.internal.loadMojomIfNecessary(
28 '{{import.module.path}}',
29 new URL(
30 '{{import.module|get_relative_path(module)}}.js',
31 document.currentScript.src).href);
32 }
17 {%- endfor %} 33 {%- endfor %}
18 34
19 {% include "module_definition.tmpl" %} 35 {% include "module_definition.tmpl" %}
20 })(); 36 })();
21 37
22 {%- else %} 38 {%- else %}
23 39
24 define("{{module.path}}", [ 40 define("{{module.path}}", [
25 {%- if module.path != "mojo/public/interfaces/bindings/interface_control_messa ges.mojom" %} 41 {%- if module.path != "mojo/public/interfaces/bindings/interface_control_messa ges.mojom" %}
26 "mojo/public/js/bindings", 42 "mojo/public/js/bindings",
(...skipping 11 matching lines...) Expand all
38 {%- for import in imports -%} 54 {%- for import in imports -%}
39 , {{import.unique_name}} 55 , {{import.unique_name}}
40 {%- endfor -%} 56 {%- endfor -%}
41 ) { 57 ) {
42 58
43 {%- include "module_definition.tmpl" %} 59 {%- include "module_definition.tmpl" %}
44 60
45 return exports; 61 return exports;
46 }); 62 });
47 63
48 {%- endif %} 64 {%- endif %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698