Start moving AtomEnvironment instantiation bits inside the snapshot

This commit is contained in:
Antonio Scandurra
2017-03-07 18:07:48 +01:00
parent b128b5de48
commit 44e3573fcb
4 changed files with 36 additions and 22 deletions

View File

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

View File

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

View File

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

View File

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