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

Unified Diff: lib/compat.js

Issue 29345407: Issue 4090 - Make require() load modules lazily (Closed)
Patch Set: Added dependency update Created May 31, 2016, 3:12 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ensure_dependencies.py ('k') | metadata.common » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compat.js
===================================================================
--- a/lib/compat.js
+++ b/lib/compat.js
@@ -16,18 +16,25 @@
*/
//
// Module framework stuff
//
function require(module)
{
- return require.scopes[module];
+ let result = require.scopes[module];
+ if (typeof result == "function" && !(module in require.loaded))
+ {
+ result = require.scopes[module] = result();
+ require.loaded[module] = true;
+ }
+ return result;
}
+require.loaded = Object.create(null);
require.scopes = Object.create(null);
function importAll(module, globalObj)
{
var exports = require(module);
for (var key in exports)
globalObj[key] = exports[key];
}
« no previous file with comments | « ensure_dependencies.py ('k') | metadata.common » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld