Mailspring/internal_packages/file-list/lib/file-frame-store.coffee
Ben Gotow 9378f4480c fix(naming): Move atom/inbox/nilas refs to Nylas
Conflicts:
	internal_packages/inbox-activity-bar/lib/activity-bar-long-poll-item.cjsx
2015-05-15 11:07:28 -07:00

55 lines
No EOL
1.2 KiB
CoffeeScript

Reflux = require 'reflux'
_ = require 'underscore-plus'
fs = require 'fs'
{WorkspaceStore,
FocusedContentStore,
FileDownloadStore,
Actions} = require 'nylas-exports'
module.exports =
FileFrameStore = Reflux.createStore
init: ->
@_resetInstanceVars()
@_afterViewUpdate = []
@listenTo FocusedContentStore, @_onFocusedContentChange
@listenTo FileDownloadStore, @_onFileDownloadChange
file: ->
@_file
ready: ->
@_ready
download: ->
@_download
_resetInstanceVars: ->
@_file = null
@_download = null
@_ready = false
_update: ->
_onFileDownloadChange: ->
@_download = FileDownloadStore.downloadForFileId(@_file.id) if @_file
if @_file and @_ready is false and not @_download
@_ready = true
@trigger()
_onFocusedContentChange: (change) ->
return unless change.impactsCollection('file')
@_file = FocusedContentStore.focused('file')
if @_file
filepath = FileDownloadStore.pathForFile(@_file)
fs.exists filepath, (exists) =>
Actions.fetchFile(@_file) if not exists
@_download = FileDownloadStore.downloadForFileId(@_file.id)
@_ready = not @_download
@trigger()
else
@_ready = false
@_download = null
@trigger()