From 333c5a0db2dff9fd4e4cf498e5ab1522e5a281e4 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 30 Sep 2013 13:09:22 -0700 Subject: [PATCH] Add requireWithGlobals() to atom global --- src/atom.coffee | 14 ++++++++++++++ src/window.coffee | 16 ++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/atom.coffee b/src/atom.coffee index 74459a619..2f8713a10 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -273,3 +273,17 @@ class Atom require userInitScriptPath if fsUtils.isFileSync(userInitScriptPath) catch error console.error "Failed to load `#{userInitScriptPath}`", error.stack, error + + requireWithGlobals: (id, globals={}) -> + existingGlobals = {} + for key, value of globals + existingGlobals[key] = window[key] + window[key] = value + + require(id) + + for key, value of existingGlobals + if value is undefined + delete window[key] + else + window[key] = value diff --git a/src/window.coffee b/src/window.coffee index 344ae23c4..98601fd72 100644 --- a/src/window.coffee +++ b/src/window.coffee @@ -123,20 +123,8 @@ window.deserialize = (args...) -> atom.deserializers.deserialize(args...) window.getDeserializer = (args...) -> atom.deserializer.getDeserializer(args...) - -window.requireWithGlobals = (id, globals={}) -> - existingGlobals = {} - for key, value of globals - existingGlobals[key] = window[key] - window[key] = value - - require(id) - - for key, value of existingGlobals - if value is undefined - delete window[key] - else - window[key] = value +window.requireWithGlobals = (args...) -> + atom.requireWithGlobals(args...) window.measure = (description, fn) -> start = new Date().getTime()