More renaming of view => data source

This commit is contained in:
Ben Gotow 2016-01-14 15:04:17 -08:00
parent 85e65e9135
commit 6b6f2b39d3
11 changed files with 74 additions and 90 deletions

View file

@ -26,7 +26,7 @@ class ThreadArchiveButton extends React.Component
return unless DOMUtils.nodeIsVisible(e.currentTarget) return unless DOMUtils.nodeIsVisible(e.currentTarget)
task = TaskFactory.taskForArchiving task = TaskFactory.taskForArchiving
threads: [@props.thread], threads: [@props.thread],
fromView: FocusedPerspectiveStore.current() fromPerspective: FocusedPerspectiveStore.current()
Actions.queueTask(task) Actions.queueTask(task)
Actions.popSheet() Actions.popSheet()
e.stopPropagation() e.stopPropagation()

View file

@ -28,7 +28,7 @@ class ThreadTrashButton extends React.Component
return unless DOMUtils.nodeIsVisible(e.currentTarget) return unless DOMUtils.nodeIsVisible(e.currentTarget)
task = TaskFactory.taskForMovingToTrash task = TaskFactory.taskForMovingToTrash
threads: [@props.thread], threads: [@props.thread],
fromView: FocusedPerspectiveStore.current() fromPerspective: FocusedPerspectiveStore.current()
Actions.queueTask(task) Actions.queueTask(task)
Actions.popSheet() Actions.popSheet()
e.stopPropagation() e.stopPropagation()

View file

@ -76,7 +76,7 @@ class DraftList extends React.Component
# Additional Commands # Additional Commands
_onRemoveFromView: => _onRemoveFromView: =>
items = DraftListStore.view().selection.items() items = DraftListStore.dataSource().selection.items()
for item in items for item in items
Actions.destroyDraft(item.clientId) Actions.destroyDraft(item.clientId)

View file

@ -30,7 +30,7 @@ class ThreadBulkArchiveButton extends React.Component
_onArchive: => _onArchive: =>
task = TaskFactory.taskForArchiving task = TaskFactory.taskForArchiving
threads: @props.selection.items(), threads: @props.selection.items(),
fromView: FocusedPerspectiveStore.current() fromPerspective: FocusedPerspectiveStore.current()
Actions.queueTask(task) Actions.queueTask(task)
class ThreadBulkTrashButton extends React.Component class ThreadBulkTrashButton extends React.Component
@ -54,7 +54,7 @@ class ThreadBulkTrashButton extends React.Component
_onRemove: => _onRemove: =>
task = TaskFactory.taskForMovingToTrash task = TaskFactory.taskForMovingToTrash
threads: @props.selection.items(), threads: @props.selection.items(),
fromView: FocusedPerspectiveStore.current() fromPerspective: FocusedPerspectiveStore.current()
Actions.queueTask(task) Actions.queueTask(task)
@ -115,13 +115,13 @@ ThreadNavButtonMixin =
isFirstThread: -> isFirstThread: ->
selectedId = FocusedContentStore.focusedId('thread') selectedId = FocusedContentStore.focusedId('thread')
ThreadListStore.view().get(0)?.id is selectedId ThreadListStore.dataSource().get(0)?.id is selectedId
isLastThread: -> isLastThread: ->
selectedId = FocusedContentStore.focusedId('thread') selectedId = FocusedContentStore.focusedId('thread')
lastIndex = ThreadListStore.view().count() - 1 lastIndex = ThreadListStore.dataSource().count() - 1
ThreadListStore.view().get(lastIndex)?.id is selectedId ThreadListStore.dataSource().get(lastIndex)?.id is selectedId
componentWillUnmount: -> componentWillUnmount: ->
@_unsubscribe() @_unsubscribe()

View file

@ -27,7 +27,7 @@ class ThreadArchiveQuickAction extends React.Component
_onArchive: (event) => _onArchive: (event) =>
task = TaskFactory.taskForArchiving task = TaskFactory.taskForArchiving
threads: [@props.thread] threads: [@props.thread]
fromView: FocusedPerspectiveStore.current() fromPerspective: FocusedPerspectiveStore.current()
Actions.queueTask(task) Actions.queueTask(task)
# Don't trigger the thread row click # Don't trigger the thread row click
@ -56,7 +56,7 @@ class ThreadTrashQuickAction extends React.Component
_onRemove: (event) => _onRemove: (event) =>
task = TaskFactory.taskForMovingToTrash task = TaskFactory.taskForMovingToTrash
threads: [@props.thread] threads: [@props.thread]
fromView: FocusedPerspectiveStore.current() fromPerspective: FocusedPerspectiveStore.current()
Actions.queueTask(task) Actions.queueTask(task)
# Don't trigger the thread row click # Don't trigger the thread row click

View file

@ -19,10 +19,10 @@ class ThreadListScrollTooltip extends React.Component
@state?.idx isnt newState.idx @state?.idx isnt newState.idx
setupForProps: (props) -> setupForProps: (props) ->
idx = Math.floor(ThreadListStore.view().count() / @props.totalHeight * @props.viewportCenter) idx = Math.floor(ThreadListStore.dataSource().count() / @props.totalHeight * @props.viewportCenter)
@setState @setState
idx: idx idx: idx
item: ThreadListStore.view().get(idx) item: ThreadListStore.dataSource().get(idx)
render: -> render: ->
if @state.item if @state.item

View file

@ -16,52 +16,36 @@ ThreadListViewFactory = require './thread-list-view-factory'
# to annotate logical regions in the text. # to annotate logical regions in the text.
class ThreadListStore extends NylasStore class ThreadListStore extends NylasStore
constructor: -> constructor: ->
@_resetInstanceVars()
@listenTo FocusedPerspectiveStore, @_onPerspectiveChanged @listenTo FocusedPerspectiveStore, @_onPerspectiveChanged
@createView() @createListDataSource()
# We can't create a @view on construction because the CategoryStore dataSource: ->
# has hot yet been populated from the database with the list of @_dataSource
# categories and their corresponding ids. Once that is ready, the
# CategoryStore will trigger, which will update the
# FocusedPerspectiveStore, which will cause us to create a new
# @view.
_resetInstanceVars: -> createListDataSource: ->
@_lastQuery = null
view: ->
@_view
createView: ->
mailboxPerspective = FocusedPerspectiveStore.current() mailboxPerspective = FocusedPerspectiveStore.current()
return unless mailboxPerspective return unless mailboxPerspective
@setView(ThreadListViewFactory.viewForPerspective(mailboxPerspective)) @_dataSourceUnlisten() if @_dataSourceUnlisten
Actions.setFocus(collection: 'thread', item: null) @_dataSource = ThreadListViewFactory.viewForPerspective(mailboxPerspective)
@_dataSourceUnlisten = @_dataSource.listen(@_onDataChanged, @)
setView: (view) ->
@_viewUnlisten() if @_viewUnlisten
@_view = view
@_viewUnlisten = view.listen(@_onViewDataChanged, @)
# Set up a one-time listener to focus an item in the new view # Set up a one-time listener to focus an item in the new view
if WorkspaceStore.layoutMode() is 'split' if WorkspaceStore.layoutMode() is 'split'
unlisten = view.listen -> unlisten = @_dataSource.listen =>
if view.loaded() if @_dataSource.loaded()
Actions.setFocus(collection: 'thread', item: view.get(0)) Actions.setFocus(collection: 'thread', item: @_dataSource.get(0))
unlisten() unlisten()
@trigger(@) @trigger(@)
Actions.setFocus(collection: 'thread', item: null)
# Inbound Events # Inbound Events
_onPerspectiveChanged: -> _onPerspectiveChanged: ->
@createView() @createListDataSource()
_onViewDataChanged: ({previous, next} = {}) => _onDataChanged: ({previous, next} = {}) =>
if previous and next if previous and next
focusedId = FocusedContentStore.focusedId('thread') focusedId = FocusedContentStore.focusedId('thread')
keyboardId = FocusedContentStore.keyboardCursorId('thread') keyboardId = FocusedContentStore.keyboardCursorId('thread')

View file

@ -43,10 +43,10 @@ class ThreadList extends React.Component
window.removeEventListener('resize', @_onResize, true) window.removeEventListener('resize', @_onResize, true)
_shift: ({offset, afterRunning}) => _shift: ({offset, afterRunning}) =>
view = ThreadListStore.view() dataSource = ThreadListStore.dataSource()
focusedId = FocusedContentStore.focusedId('thread') focusedId = FocusedContentStore.focusedId('thread')
focusedIdx = Math.min(view.count() - 1, Math.max(0, view.indexOfId(focusedId) + offset)) focusedIdx = Math.min(dataSource.count() - 1, Math.max(0, dataSource.indexOfId(focusedId) + offset))
item = view.get(focusedIdx) item = dataSource.get(focusedIdx)
afterRunning() afterRunning()
Actions.setFocus(collection: 'thread', item: item) Actions.setFocus(collection: 'thread', item: item)
@ -116,8 +116,8 @@ class ThreadList extends React.Component
event.preventDefault() event.preventDefault()
return return
if itemThreadId in ThreadListStore.view().selection.ids() if itemThreadId in ThreadListStore.dataSource().selection.ids()
dragThreadIds = ThreadListStore.view().selection.ids() dragThreadIds = ThreadListStore.dataSource().selection.ids()
else else
dragThreadIds = [itemThreadId] dragThreadIds = [itemThreadId]
@ -138,12 +138,12 @@ class ThreadList extends React.Component
@setState(style: desired) @setState(style: desired)
_threadsForKeyboardAction: -> _threadsForKeyboardAction: ->
return null unless ThreadListStore.view() return null unless ThreadListStore.dataSource()
focused = FocusedContentStore.focused('thread') focused = FocusedContentStore.focused('thread')
if focused if focused
return [focused] return [focused]
else if ThreadListStore.view().selection.count() > 0 else if ThreadListStore.dataSource().selection.count() > 0
return ThreadListStore.view().selection.items() return ThreadListStore.dataSource().selection.items()
else else
return null return null
@ -209,7 +209,7 @@ class ThreadList extends React.Component
task = removeMethod task = removeMethod
threads: threads threads: threads
fromView: FocusedPerspectiveStore.current() fromPerspective: FocusedPerspectiveStore.current()
Actions.queueTask(task) Actions.queueTask(task)
Actions.popSheet() Actions.popSheet()
@ -220,7 +220,7 @@ class ThreadList extends React.Component
if threads if threads
task = TaskFactory.taskForArchiving task = TaskFactory.taskForArchiving
threads: threads threads: threads
fromView: FocusedPerspectiveStore.current() fromPerspective: FocusedPerspectiveStore.current()
Actions.queueTask(task) Actions.queueTask(task)
Actions.popSheet() Actions.popSheet()
@ -230,28 +230,28 @@ class ThreadList extends React.Component
if threads if threads
task = TaskFactory.taskForMovingToTrash task = TaskFactory.taskForMovingToTrash
threads: threads threads: threads
fromView: FocusedPerspectiveStore.current() fromPerspective: FocusedPerspectiveStore.current()
Actions.queueTask(task) Actions.queueTask(task)
Actions.popSheet() Actions.popSheet()
_onSelectRead: => _onSelectRead: =>
view = ThreadListStore.view() dataSource = ThreadListStore.dataSource()
items = view.itemsCurrentlyInViewMatching (item) -> not item.unread items = dataSource.itemsCurrentlyInViewMatching (item) -> not item.unread
view.selection.set(items) dataSource.selection.set(items)
_onSelectUnread: => _onSelectUnread: =>
view = ThreadListStore.view() dataSource = ThreadListStore.dataSource()
items = view.itemsCurrentlyInViewMatching (item) -> item.unread items = dataSource.itemsCurrentlyInViewMatching (item) -> item.unread
view.selection.set(items) dataSource.selection.set(items)
_onSelectStarred: => _onSelectStarred: =>
view = ThreadListStore.view() dataSource = ThreadListStore.dataSource()
items = view.itemsCurrentlyInViewMatching (item) -> item.starred items = dataSource.itemsCurrentlyInViewMatching (item) -> item.starred
view.selection.set(items) dataSource.selection.set(items)
_onSelectUnstarred: => _onSelectUnstarred: =>
view = ThreadListStore.view() dataSource = ThreadListStore.dataSource()
items = view.itemsCurrentlyInViewMatching (item) -> not item.starred items = dataSource.itemsCurrentlyInViewMatching (item) -> not item.starred
view.selection.set(items) dataSource.selection.set(items)
module.exports = ThreadList module.exports = ThreadList

View file

@ -108,9 +108,9 @@ class MultiselectActionBar extends React.Component
</div> </div>
_renderActions: => _renderActions: =>
return <div></div> unless @state.view return <div></div> unless @state.dataSource
<InjectedComponentSet matching={role:"#{@props.collection}:BulkAction"} <InjectedComponentSet matching={role:"#{@props.collection}:BulkAction"}
exposedProps={selection: @state.view.selection, items: @state.items} /> exposedProps={selection: @state.dataSource.selection, items: @state.items} />
_label: => _label: =>
if @state.items.length > 1 if @state.items.length > 1
@ -122,11 +122,11 @@ class MultiselectActionBar extends React.Component
_getStateFromStores: (props) => _getStateFromStores: (props) =>
props ?= @props props ?= @props
view = props.dataStore.view() dataSource = props.dataStore.dataSource()
items = view?.selection.items() ? [] items = dataSource?.selection.items() ? []
return { return {
view: view dataSource: dataSource
items: items items: items
} }
@ -134,7 +134,7 @@ class MultiselectActionBar extends React.Component
@setState(@_getStateFromStores()) @setState(@_getStateFromStores())
_onClearSelection: => _onClearSelection: =>
@state.view.selection.clear() @state.dataSource.selection.clear()
module.exports = MultiselectActionBar module.exports = MultiselectActionBar

View file

@ -198,8 +198,8 @@ class MultiselectList extends React.Component
state = @state ? {} state = @state ? {}
layoutMode = WorkspaceStore.layoutMode() layoutMode = WorkspaceStore.layoutMode()
view = props.dataStore?.view() dataSource = props.dataStore?.dataSource()
return {} unless view return {} unless dataSource
# Do we need to re-compute columns? Don't do this unless we really have to, # Do we need to re-compute columns? Don't do this unless we really have to,
# it will cause a re-render of the entire ListTabular. To know whether our # it will cause a re-render of the entire ListTabular. To know whether our
@ -213,19 +213,19 @@ class MultiselectList extends React.Component
computedColumns = state.computedColumns computedColumns = state.computedColumns
if layoutMode is 'list' if layoutMode is 'list'
handler = new MultiselectListInteractionHandler(view, props.collection) handler = new MultiselectListInteractionHandler(dataSource, props.collection)
else else
handler = new MultiselectSplitInteractionHandler(view, props.collection) handler = new MultiselectSplitInteractionHandler(dataSource, props.collection)
dataSource: view dataSource: dataSource
handler: handler handler: handler
columns: props.columns columns: props.columns
computedColumns: computedColumns computedColumns: computedColumns
layoutMode: layoutMode layoutMode: layoutMode
selectedIds: view.selection.ids() selectedIds: dataSource.selection.ids()
focusedId: FocusedContentStore.focusedId(props.collection) focusedId: FocusedContentStore.focusedId(props.collection)
keyboardCursorId: FocusedContentStore.keyboardCursorId(props.collection) keyboardCursorId: FocusedContentStore.keyboardCursorId(props.collection)
loaded: view.loaded() loaded: dataSource.loaded()
empty: view.empty() empty: dataSource.empty()
module.exports = MultiselectList module.exports = MultiselectList

View file

@ -8,7 +8,7 @@ CategoryStore = require '../stores/category-store'
class TaskFactory class TaskFactory
taskForApplyingCategory: ({threads, fromView, category, exclusive}) => taskForApplyingCategory: ({threads, fromPerspective, category, exclusive}) =>
# TODO Can not apply to threads across more than one account for now # TODO Can not apply to threads across more than one account for now
account = AccountStore.accountForItems(threads) account = AccountStore.accountForItems(threads)
return unless account? return unless account?
@ -21,7 +21,7 @@ class TaskFactory
else else
labelsToRemove = [] labelsToRemove = []
if exclusive if exclusive
currentLabel = CategoryStore.byId(account, fromView?.categoryId()) currentLabel = CategoryStore.byId(account, fromPerspective?.categoryId())
currentLabel ?= CategoryStore.getStandardCategory(account, "inbox") currentLabel ?= CategoryStore.getStandardCategory(account, "inbox")
labelsToRemove = [currentLabel] labelsToRemove = [currentLabel]
@ -30,7 +30,7 @@ class TaskFactory
labelsToRemove: labelsToRemove labelsToRemove: labelsToRemove
labelsToAdd: [category] labelsToAdd: [category]
taskForRemovingCategory: ({threads, fromView, category, exclusive}) => taskForRemovingCategory: ({threads, fromPerspective, category, exclusive}) =>
# TODO Can not apply to threads across more than one account for now # TODO Can not apply to threads across more than one account for now
account = AccountStore.accountForItems(threads) account = AccountStore.accountForItems(threads)
return unless account? return unless account?
@ -42,7 +42,7 @@ class TaskFactory
else else
labelsToAdd = [] labelsToAdd = []
if exclusive if exclusive
currentLabel = CategoryStore.byId(account, fromView?.categoryId()) currentLabel = CategoryStore.byId(account, fromPerspective?.categoryId())
currentLabel ?= CategoryStore.getStandardCategory(account, "inbox") currentLabel ?= CategoryStore.getStandardCategory(account, "inbox")
labelsToAdd = [currentLabel] labelsToAdd = [currentLabel]
@ -51,21 +51,21 @@ class TaskFactory
labelsToRemove: [category] labelsToRemove: [category]
labelsToAdd: labelsToAdd labelsToAdd: labelsToAdd
taskForArchiving: ({threads, fromView}) => taskForArchiving: ({threads, fromPerspective}) =>
category = @_getArchiveCategory(threads) category = @_getArchiveCategory(threads)
@taskForApplyingCategory({threads, fromView, category, exclusive: true}) @taskForApplyingCategory({threads, fromPerspective, category, exclusive: true})
taskForUnarchiving: ({threads, fromView}) => taskForUnarchiving: ({threads, fromPerspective}) =>
category = @_getArchiveCategory(threads) category = @_getArchiveCategory(threads)
@taskForRemovingCategory({threads, fromView, category, exclusive: true}) @taskForRemovingCategory({threads, fromPerspective, category, exclusive: true})
taskForMovingToTrash: ({threads, fromView}) => taskForMovingToTrash: ({threads, fromPerspective}) =>
category = @_getTrashCategory(threads) category = @_getTrashCategory(threads)
@taskForApplyingCategory({threads, fromView, category, exclusive: true}) @taskForApplyingCategory({threads, fromPerspective, category, exclusive: true})
taskForMovingFromTrash: ({threads, fromView}) => taskForMovingFromTrash: ({threads, fromPerspective}) =>
category = @_getTrashCategory(threads) category = @_getTrashCategory(threads)
@taskForRemovingCategory({threads, fromView, category, exclusive: true}) @taskForRemovingCategory({threads, fromPerspective, category, exclusive: true})
taskForInvertingUnread: ({threads}) => taskForInvertingUnread: ({threads}) =>
unread = _.every threads, (t) -> _.isMatch(t, {unread: false}) unread = _.every threads, (t) -> _.isMatch(t, {unread: false})