Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: templates/modules.js.tmpl

Issue 29399569: Issue 5060 - Move require into modules template, make info a module (Closed)
Patch Set: Don't redeclare require Created March 31, 2017, 6:48 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 {%- if args["module"] -%} 1 {%- if args["module"] -%}
2 if (!("require" in window))
Sebastian Noack 2017/03/31 10:42:01 The assumption of the global object being "window"
kzar 2017/03/31 14:03:01 Done.
3 {
4 window.require = function(module)
5 {
6 if (!(module in require.scopes))
7 {
8 let scope = {exports: {}};
9 require.scopes[module] = require.modules[module](scope, scope.exports);
10 }
11 return require.scopes[module];
12 }
13 require.modules = Object.create(null);
14 require.scopes = Object.create(null);
15 }
2 {%- for module_name, script in modules -%} 16 {%- for module_name, script in modules -%}
3 require.modules[{{ module_name|json }}] = function(module, exports) 17 require.modules[{{ module_name|json }}] = function(module, exports)
4 { 18 {
5 {{ script }} 19 {{ script }}
6 return module.exports; 20 return module.exports;
7 }; 21 };
8 22
9 {% endfor -%} 23 {% endfor -%}
10 {%- set modules = dict(modules) -%} 24 {%- set modules = dict(modules) -%}
11 {%- for module_name in args["autoload"] -%} 25 {%- for module_name in args["autoload"] -%}
12 {%- if module_name in modules -%} 26 {%- if module_name in modules -%}
13 require({{ module_name|json }}); 27 require({{ module_name|json }});
14 {% endif %} 28 {% endif %}
15 {%- endfor -%} 29 {%- endfor -%}
16 {%- else -%} 30 {%- else -%}
17 {%- for module_name, script in modules -%} 31 {%- for module_name, script in modules -%}
18 {{ script }} 32 {{ script }}
19 {% endfor -%} 33 {% endfor -%}
20 {%- endif -%} 34 {%- endif -%}
OLDNEW

Powered by Google App Engine
This is Rietveld