summaryrefslogtreecommitdiff
path: root/mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl
diff options
context:
space:
mode:
Diffstat (limited to 'mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl')
-rw-r--r--mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl70
1 files changed, 70 insertions, 0 deletions
diff --git a/mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl b/mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl
new file mode 100644
index 0000000000..3637b196ac
--- /dev/null
+++ b/mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl
@@ -0,0 +1,70 @@
+// Copyright 2014 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 use_new_js_bindings %}
+
+'use strict';
+
+(function() {
+ var mojomId = '{{module.path}}';
+ if (mojo.internal.isMojomLoaded(mojomId)) {
+ console.warn('The following mojom is loaded multiple times: ' + mojomId);
+ return;
+ }
+ mojo.internal.markMojomLoaded(mojomId);
+
+ // TODO(yzshen): Define these aliases to minimize the differences between the
+ // old/new modes. Remove them when the old mode goes away.
+ var bindings = mojo;
+ var codec = mojo.internal;
+ var validator = mojo.internal;
+
+{%- for import in imports %}
+ var {{import.unique_name}} =
+ mojo.internal.exposeNamespace('{{import.module.namespace}}');
+ if (mojo.config.autoLoadMojomDeps) {
+ mojo.internal.loadMojomIfNecessary(
+ '{{import.module.path}}',
+ new URL(
+ '{{import.module|get_relative_path(module)}}.js',
+ document.currentScript.src).href);
+ }
+{%- endfor %}
+
+{% include "module_definition.tmpl" %}
+})();
+
+{%- else %}
+
+define("{{module.path}}", [
+{%- if module.path !=
+ "mojo/public/interfaces/bindings/interface_control_messages.mojom" and
+ module.path !=
+ "mojo/public/interfaces/bindings/pipe_control_messages.mojom" %}
+ "mojo/public/js/bindings",
+{%- endif %}
+ "mojo/public/js/codec",
+ "mojo/public/js/core",
+ "mojo/public/js/validator",
+{%- for import in imports %}
+ "{{import.module.path}}",
+{%- endfor %}
+], function(
+{%- if module.path !=
+ "mojo/public/interfaces/bindings/interface_control_messages.mojom" and
+ module.path !=
+ "mojo/public/interfaces/bindings/pipe_control_messages.mojom" -%}
+bindings, {% endif -%}
+codec, core, validator
+{%- for import in imports -%}
+ , {{import.unique_name}}
+{%- endfor -%}
+) {
+
+{%- include "module_definition.tmpl" %}
+
+ return exports;
+});
+
+{%- endif %}