More renaming of view => data source

This commit is contained in:
Ben Gotow 2016-01-14 15:04:17 -08:00
parent d78e61839d
commit 8957c560f5
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)
task = TaskFactory.taskForArchiving
threads: [@props.thread],
fromView: FocusedPerspectiveStore.current()
fromPerspective: FocusedPerspectiveStore.current()
Actions.queueTask(task)
Actions.popSheet()
e.stopPropagation()

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -198,8 +198,8 @@ class MultiselectList extends React.Component
state = @state ? {}
layoutMode = WorkspaceStore.layoutMode()
view = props.dataStore?.view()
return {} unless view
dataSource = props.dataStore?.dataSource()
return {} unless dataSource
# 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
@ -213,19 +213,19 @@ class MultiselectList extends React.Component
computedColumns = state.computedColumns
if layoutMode is 'list'
handler = new MultiselectListInteractionHandler(view, props.collection)
handler = new MultiselectListInteractionHandler(dataSource, props.collection)
else
handler = new MultiselectSplitInteractionHandler(view, props.collection)
handler = new MultiselectSplitInteractionHandler(dataSource, props.collection)
dataSource: view
dataSource: dataSource
handler: handler
columns: props.columns
computedColumns: computedColumns
layoutMode: layoutMode
selectedIds: view.selection.ids()
selectedIds: dataSource.selection.ids()
focusedId: FocusedContentStore.focusedId(props.collection)
keyboardCursorId: FocusedContentStore.keyboardCursorId(props.collection)
loaded: view.loaded()
empty: view.empty()
loaded: dataSource.loaded()
empty: dataSource.empty()
module.exports = MultiselectList

View file

@ -8,7 +8,7 @@ CategoryStore = require '../stores/category-store'
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
account = AccountStore.accountForItems(threads)
return unless account?
@ -21,7 +21,7 @@ class TaskFactory
else
labelsToRemove = []
if exclusive
currentLabel = CategoryStore.byId(account, fromView?.categoryId())
currentLabel = CategoryStore.byId(account, fromPerspective?.categoryId())
currentLabel ?= CategoryStore.getStandardCategory(account, "inbox")
labelsToRemove = [currentLabel]
@ -30,7 +30,7 @@ class TaskFactory
labelsToRemove: labelsToRemove
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
account = AccountStore.accountForItems(threads)
return unless account?
@ -42,7 +42,7 @@ class TaskFactory
else
labelsToAdd = []
if exclusive
currentLabel = CategoryStore.byId(account, fromView?.categoryId())
currentLabel = CategoryStore.byId(account, fromPerspective?.categoryId())
currentLabel ?= CategoryStore.getStandardCategory(account, "inbox")
labelsToAdd = [currentLabel]
@ -51,21 +51,21 @@ class TaskFactory
labelsToRemove: [category]
labelsToAdd: labelsToAdd
taskForArchiving: ({threads, fromView}) =>
taskForArchiving: ({threads, fromPerspective}) =>
category = @_getArchiveCategory(threads)
@taskForApplyingCategory({threads, fromView, category, exclusive: true})
@taskForApplyingCategory({threads, fromPerspective, category, exclusive: true})
taskForUnarchiving: ({threads, fromView}) =>
taskForUnarchiving: ({threads, fromPerspective}) =>
category = @_getArchiveCategory(threads)
@taskForRemovingCategory({threads, fromView, category, exclusive: true})
@taskForRemovingCategory({threads, fromPerspective, category, exclusive: true})
taskForMovingToTrash: ({threads, fromView}) =>
taskForMovingToTrash: ({threads, fromPerspective}) =>
category = @_getTrashCategory(threads)
@taskForApplyingCategory({threads, fromView, category, exclusive: true})
@taskForApplyingCategory({threads, fromPerspective, category, exclusive: true})
taskForMovingFromTrash: ({threads, fromView}) =>
taskForMovingFromTrash: ({threads, fromPerspective}) =>
category = @_getTrashCategory(threads)
@taskForRemovingCategory({threads, fromView, category, exclusive: true})
@taskForRemovingCategory({threads, fromPerspective, category, exclusive: true})
taskForInvertingUnread: ({threads}) =>
unread = _.every threads, (t) -> _.isMatch(t, {unread: false})