Add requireWithGlobals() to atom global

This commit is contained in:
Kevin Sawicki 2013-09-30 13:09:22 -07:00
parent dc9c59f0b3
commit 333c5a0db2
2 changed files with 16 additions and 14 deletions

View File

@ -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

View File

@ -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()