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: Addressed comments and fixed list of initially loaded modules Created May 31, 2016, 1:43 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 | « no previous file | metadata.common » ('j') | metadata.common » ('J')
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 | « no previous file | metadata.common » ('j') | metadata.common » ('J')

Powered by Google App Engine
This is Rietveld