diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index 7594f5de9..04f0a23e8 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -131,15 +131,22 @@ class AtomEnvironment extends Model # Call .loadOrCreate instead constructor: (params={}) -> - {@applicationDelegate, @window, @document, @blobStore, @clipboard, @configDirPath, @enablePersistence, onlyLoadBaseStyleSheets} = params + {@applicationDelegate, @clipboard, @enablePersistence, onlyLoadBaseStyleSheets} = params @nextProxyRequestId = 0 @unloaded = false @loadTime = null - {devMode, safeMode, resourcePath, clearWindowState} = @getLoadSettings() - @emitter = new Emitter @disposables = new CompositeDisposable + @deserializers = new DeserializerManager(this) + @deserializeTimings = {} + @views = new ViewRegistry(this) + @notifications = new NotificationManager + @config = new Config({notificationManager: @notifications, @enablePersistence}) + + initialize: (params={}) -> + {@applicationDelegate, @window, @document, @blobStore, @clipboard, @configDirPath, @enablePersistence, onlyLoadBaseStyleSheets} = params + {devMode, safeMode, resourcePath, clearWindowState} = @getLoadSettings() @stateStore = new StateStore('AtomEnvironments', 1) @@ -147,14 +154,9 @@ class AtomEnvironment extends Model @getStorageFolder().clear() @stateStore.clear() - @deserializers = new DeserializerManager(this) - @deserializeTimings = {} + @views.initialize() - @views = new ViewRegistry(this) - - @notifications = new NotificationManager - - @config = new Config({@configDirPath, resourcePath, notificationManager: @notifications, @enablePersistence}) + @config.initialize({@configDirPath, resourcePath}) @setConfigSchema() @keymaps = new KeymapManager({@configDirPath, resourcePath, notificationManager: @notifications}) diff --git a/src/config.coffee b/src/config.coffee index e7d05da6d..575e95a72 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -398,11 +398,13 @@ class Config value # Created during initialization, available as `atom.config` - constructor: ({@configDirPath, @resourcePath, @notificationManager, @enablePersistence}={}) -> + constructor: ({@notificationManager, @enablePersistence}={}) -> + @clear() + + initialize: ({@configDirPath, @resourcePath}) -> if @enablePersistence? @configFilePath = fs.resolve(@configDirPath, 'config', ['json', 'cson']) @configFilePath ?= path.join(@configDirPath, 'config.cson') - @clear() clear: -> @emitter = new Emitter diff --git a/src/initialize-application-window.coffee b/src/initialize-application-window.coffee index f0ea0ed12..076b1bf32 100644 --- a/src/initialize-application-window.coffee +++ b/src/initialize-application-window.coffee @@ -55,6 +55,15 @@ require('welcome') require('whitespace') require('wrap-guide') +clipboard = new Clipboard +TextEditor.setClipboard(clipboard) + +window.atom = new AtomEnvironment({ + clipboard, + applicationDelegate: new ApplicationDelegate, + enablePersistence: true +}) + # Like sands through the hourglass, so are the days of our lives. module.exports = ({blobStore}) -> {updateProcessEnv} = require('./update-process-env') @@ -73,14 +82,9 @@ module.exports = ({blobStore}) -> # Make React faster process.env.NODE_ENV ?= 'production' unless devMode - clipboard = new Clipboard - TextEditor.setClipboard(clipboard) - - window.atom = new AtomEnvironment({ - window, document, clipboard, blobStore, - applicationDelegate: new ApplicationDelegate, + window.atom.initialize({ + window, document, blobStore, configDirPath: process.env.ATOM_HOME, - enablePersistence: true, env: process.env }) diff --git a/src/view-registry.coffee b/src/view-registry.coffee index e2cd986dc..5a8e72a4c 100644 --- a/src/view-registry.coffee +++ b/src/view-registry.coffee @@ -54,9 +54,12 @@ class ViewRegistry minimumPollInterval: 200 constructor: (@atomEnvironment) -> - @observer = new MutationObserver(@requestDocumentPoll) + @polling = false @clear() + initialize: -> + @observer = new MutationObserver(@requestDocumentPoll) + clear: -> @views = new WeakMap @providers = [] @@ -267,10 +270,13 @@ class ViewRegistry startPollingDocument: -> window.addEventListener('resize', @requestDocumentPoll) @observer.observe(document, {subtree: true, childList: true, attributes: true}) + @polling = true stopPollingDocument: -> - window.removeEventListener('resize', @requestDocumentPoll) - @observer.disconnect() + if @polling + window.removeEventListener('resize', @requestDocumentPoll) + @observer.disconnect() + @polling = false requestDocumentPoll: => if @animationFrameRequest?