From 7b4fdde7ae0dc33f3c7151675812d7044fc88abf Mon Sep 17 00:00:00 2001 From: Brian Ford Date: Wed, 4 Jun 2014 11:56:06 -0700 Subject: [PATCH] fix: commonjs wrapper Closes #19 --- zone.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/zone.js b/zone.js index ee267d479..474626226 100644 --- a/zone.js +++ b/zone.js @@ -1,5 +1,9 @@ 'use strict'; +(function (window) { + +var zone = null; + function Zone(parentZone, data) { var zone = (arguments.length) ? Object.create(parentZone) : this; @@ -79,10 +83,10 @@ Zone.prototype = { run: function run (fn, applyTo, applyWith) { applyWith = applyWith || []; - var oldZone = window.zone, + var oldZone = zone, result; - window.zone = this; + window.zone = zone = this; try { this.beforeTask(); @@ -95,7 +99,7 @@ Zone.prototype = { } } finally { this.afterTask(); - window.zone = oldZone; + window.zone = zone = oldZone; } return result; }, @@ -665,13 +669,14 @@ Zone.onEventNames = Zone.eventNames.map(function (property) { }); Zone.init = function init () { - if (typeof module !== 'undefined' && module && module.exports) { - module.exports = new Zone(); - } else { - window.zone = new Zone(); - } + window.zone = zone = new Zone(); Zone.patch(); }; Zone.init(); + +window.Zone = Zone; + +}((typeof module !== 'undefined' && module && module.exports) ? + module.exports : window));