Move Project.deserialize to instance method

So we can instantiate atom.project during Atom environment construction.

Signed-off-by: Max Brunsfeld <maxbrunsfeld@github.com>
This commit is contained in:
Nathan Sobo
2015-10-02 12:12:16 -06:00
parent 6348d8f078
commit 26f0ef5424
6 changed files with 37 additions and 30 deletions

View File

@@ -652,9 +652,9 @@ class Atom extends Model
deserializeProject: ->
Project = require './project'
startTime = Date.now()
@project ?= @deserializers.deserialize(@state.project) ? new Project()
@project = new Project()
@project.deserialize(@state.project, @deserializers) if @state.project?
@deserializeTimings.project = Date.now() - startTime
deserializeWorkspace: ->

View File

@@ -21,23 +21,10 @@ class Project extends Model
Section: Construction and Destruction
###
@deserialize: (state) ->
state.buffers = _.compact state.buffers.map (bufferState) ->
# Check that buffer's file path is accessible
return if fs.isDirectorySync(bufferState.filePath)
if bufferState.filePath
try
fs.closeSync(fs.openSync(bufferState.filePath, 'r'))
catch error
return unless error.code is 'ENOENT'
atom.deserializers.deserialize(bufferState)
new this(state)
constructor: ({path, paths, @buffers}={}) ->
constructor: ->
@emitter = new Emitter
@buffers ?= []
@buffers = []
@paths = []
@rootDirectories = []
@repositories = []
@@ -68,11 +55,6 @@ class Project extends Model
@setPaths(@getPaths())
)
@subscribeToBuffer(buffer) for buffer in @buffers
paths ?= _.compact([path])
@setPaths(paths)
destroyed: ->
buffer.destroy() for buffer in @getBuffers()
@setPaths([])
@@ -85,6 +67,22 @@ class Project extends Model
Section: Serialization
###
deserialize: (state, deserializerManager) ->
states.paths = [state.path] if state.path? # backward compatibility
@buffers = _.compact state.buffers.map (bufferState) ->
# Check that buffer's file path is accessible
return if fs.isDirectorySync(bufferState.filePath)
if bufferState.filePath
try
fs.closeSync(fs.openSync(bufferState.filePath, 'r'))
catch error
return unless error.code is 'ENOENT'
deserializerManager.deserialize(bufferState)
@subscribeToBuffer(buffer) for buffer in @buffers
@setPaths(state.paths)
serialize: ->
deserializer: 'Project'
paths: @getPaths()