Fix zone.js patches by avoiding multiple global moduleMerge's.

The previous implementation was calling moduleMerge multiple times for a
required module if it had more than one configured global lazy-loaded
functions/properties. We now keep tracked of merged modules and merge only
the first time.
This commit is contained in:
Hristo Deshev
2015-12-22 15:01:45 +02:00
parent e458a94191
commit 18c75d2ba1

View File

@ -31,17 +31,24 @@ global.registerModule("ui/dialogs", () => require("ui/dialogs"));
global.registerModule("../xhr/xhr", () => require("../xhr/xhr")); global.registerModule("../xhr/xhr", () => require("../xhr/xhr"));
global.registerModule("fetch", () => require("fetch")); global.registerModule("fetch", () => require("fetch"));
function registerOnGlobalContext(name, module) { const __tnsGlobalMergedModules = new Map<string, boolean>();
function registerOnGlobalContext(name: string, module: string): void {
Object.defineProperty(global, name, { Object.defineProperty(global, name, {
get: function () { get: function () {
// We do not need to cache require() call since it is already cached in the runtime. // We do not need to cache require() call since it is already cached in the runtime.
let m = global.loadModule(module); let m = global.loadModule(module);
global.moduleMerge(m, global); if (!__tnsGlobalMergedModules.has(module)) {
__tnsGlobalMergedModules.set(module, true);
global.moduleMerge(m, global);
}
// Redefine the property to make sure the above code is executed only once. // Redefine the property to make sure the above code is executed only once.
Object.defineProperty(this, name, { value: m[name], configurable: true, writable: true }); let resolvedValue = m[name];
Object.defineProperty(this, name, { value: resolvedValue, configurable: true, writable: true });
return m[name]; return resolvedValue;
}, },
configurable: true configurable: true
}); });