From d997c80d3186b012c992d267921352407af5f82f Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 22 Sep 2015 10:50:11 -0600 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20use=20Serializable=20mixin=20in?= =?UTF-8?q?=20Project?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/project-spec.coffee | 8 ++++---- src/project.coffee | 32 ++++++++++++++++---------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/spec/project-spec.coffee b/spec/project-spec.coffee index 753bf23cd..13dd3e70c 100644 --- a/spec/project-spec.coffee +++ b/spec/project-spec.coffee @@ -66,7 +66,7 @@ describe "Project", -> runs -> expect(atom.project.getBuffers().length).toBe 1 - deserializedProject = atom.project.testSerialization() + deserializedProject = Project.deserialize(atom.project.serialize()) expect(deserializedProject.getBuffers().length).toBe 0 it "listens for destroyed events on deserialized buffers and removes them when they are destroyed", -> @@ -75,7 +75,7 @@ describe "Project", -> runs -> expect(atom.project.getBuffers().length).toBe 1 - deserializedProject = atom.project.testSerialization() + deserializedProject = Project.deserialize(atom.project.serialize()) expect(deserializedProject.getBuffers().length).toBe 1 deserializedProject.getBuffers()[0].destroy() @@ -91,7 +91,7 @@ describe "Project", -> runs -> expect(atom.project.getBuffers().length).toBe 1 fs.mkdirSync(pathToOpen) - deserializedProject = atom.project.testSerialization() + deserializedProject = Project.deserialize(atom.project.serialize()) expect(deserializedProject.getBuffers().length).toBe 0 it "does not deserialize buffers when their path is inaccessible", -> @@ -104,7 +104,7 @@ describe "Project", -> runs -> expect(atom.project.getBuffers().length).toBe 1 fs.chmodSync(pathToOpen, '000') - deserializedProject = atom.project.testSerialization() + deserializedProject = Project.deserialize(atom.project.serialize()) expect(deserializedProject.getBuffers().length).toBe 0 describe "when an editor is saved and the project has no path", -> diff --git a/src/project.coffee b/src/project.coffee index 1b92eabda..b3f05a942 100644 --- a/src/project.coffee +++ b/src/project.coffee @@ -4,7 +4,6 @@ url = require 'url' _ = require 'underscore-plus' fs = require 'fs-plus' {Emitter} = require 'event-kit' -Serializable = require 'serializable' TextBuffer = require 'text-buffer' DefaultDirectoryProvider = require './default-directory-provider' @@ -19,12 +18,25 @@ GitRepositoryProvider = require './git-repository-provider' module.exports = class Project extends Model atom.deserializers.add(this) - Serializable.includeInto(this) ### 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}={}) -> @emitter = new Emitter @buffers ?= [] @@ -75,23 +87,11 @@ class Project extends Model Section: Serialization ### - serializeParams: -> + serialize: -> + deserializer: 'Project' paths: @getPaths() buffers: _.compact(@buffers.map (buffer) -> buffer.serialize() if buffer.isRetained()) - deserializeParams: (params) -> - params.buffers = _.compact params.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) - params - ### Section: Event Subscription ###