mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-12-27 10:33:56 +08:00
343bb3163b
Summary: This diff does a couple things: - Undo redo with a new undo/redo store that maintains it's own queue of undo/redo tasks. This queue is separate from the TaskQueue because not all tasks should be considered for undo history! Right now just the AddRemoveTagsTask is undoable. - NylasAPI.makeRequest now returns a promise which resolves with the result or rejects with an error. For things that still need them, there's still `success` and `error` callbacks. I also added `started:(req) ->` which allows you to get the underlying request. - Aborting a NylasAPI request now makes it call it's error callback / promise reject. - You can now run code after perform local has completed using this syntax: ``` task = new AddRemoveTagsTask(focused, ['archive'], ['inbox']) task.waitForPerformLocal().then -> Actions.setFocus(collection: 'thread', item: nextFocus) Actions.setCursorPosition(collection: 'thread', item: nextKeyboard) Actions.queueTask(task) ``` - In specs, you can now use `advanceClock` to get through a Promise.then/catch/finally. Turns out it was using something low level and not using setTimeout(0). - The TaskQueue uses promises better and defers a lot of the complexity around queueState for performLocal/performRemote to a task subclass called APITask. APITask implements "perform" and breaks it into "performLocal" and "performRemote". - All tasks either resolve or reject. They're always removed from the queue, unless they resolve with Task.Status.Retry, which means they internally did a .catch (err) => Promise.resolve(Task.Status.Retry) and they want to be run again later. - API tasks retry until they succeed or receive a NylasAPI.PermanentErrorCode (400,404,500), in which case they revert and finish. - The AddRemoveTags Task can now take more than one thread! This is super cool because you can undo/redo a bulk action and also because we'll probably have a bulk tag modification API endpoint soon. Getting undo / redo working revealed that the thread versioning system we built isn't working because the server was incrementing things by more than 1 at a time. Now we count the number of unresolved "optimistic" changes we've made to a given model, and only accept the server's version of it once the number of optimistic changes is back at zero. Known Issues: - AddRemoveTagsTasks aren't dependent on each other, so if you (undo/redo x lots) and then come back online, all the tasks try to add / remove all the tags at the same time. To fix this we can either allow the tasks to be merged together into a minimal set or make them block on each other. - When Offline, you still get errors in the console for GET requests. Need to catch these and display an offline status bar. - The metadata tasks haven't been updated yet to the new API. Wanted to get it reviewed first! Test Plan: All the tests still pass! Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D1694
82 lines
3 KiB
CoffeeScript
82 lines
3 KiB
CoffeeScript
Utils = require '../src/flux/models/utils'
|
|
|
|
{APIError,
|
|
OfflineError,
|
|
TimeoutError} = require '../src/flux/errors'
|
|
|
|
Exports =
|
|
|
|
React: require 'react'
|
|
BufferedProcess: require '../src/buffered-process'
|
|
BufferedNodeProcess: require '../src/buffered-node-process'
|
|
|
|
# The Task Queue
|
|
Task: require '../src/flux/tasks/task'
|
|
TaskQueue: require '../src/flux/stores/task-queue'
|
|
UndoRedoStore: require '../src/flux/stores/undo-redo-store'
|
|
|
|
# Tasks
|
|
CreateMetadataTask: require '../src/flux/tasks/create-metadata-task'
|
|
DestroyMetadataTask: require '../src/flux/tasks/destroy-metadata-task'
|
|
|
|
# The Database
|
|
DatabaseStore: require '../src/flux/stores/database-store'
|
|
ModelView: require '../src/flux/stores/model-view'
|
|
DatabaseView: require '../src/flux/stores/database-view'
|
|
SearchView: require '../src/flux/stores/search-view'
|
|
|
|
# Actions
|
|
Actions: require '../src/flux/actions'
|
|
|
|
# API Endpoints
|
|
NylasAPI: require '../src/flux/nylas-api'
|
|
EdgehillAPI: require '../src/flux/edgehill-api'
|
|
|
|
# Testing
|
|
NylasTestUtils: require '../spec-nylas/test_utils'
|
|
|
|
# Component Registry
|
|
ComponentRegistry: require '../src/component-registry'
|
|
|
|
# Utils
|
|
Utils: Utils
|
|
MessageUtils: require '../src/flux/models/message-utils'
|
|
|
|
# Mixins
|
|
UndoManager: require '../src/flux/undo-manager'
|
|
|
|
PriorityUICoordinator: require '../src/priority-ui-coordinator'
|
|
|
|
# Stores
|
|
DraftStore: require '../src/flux/stores/draft-store'
|
|
DraftCountStore: require '../src/flux/stores/draft-count-store'
|
|
DraftStoreExtension: require '../src/flux/stores/draft-store-extension'
|
|
MessageStore: require '../src/flux/stores/message-store'
|
|
ContactStore: require '../src/flux/stores/contact-store'
|
|
MetadataStore: require '../src/flux/stores/metadata-store'
|
|
NamespaceStore: require '../src/flux/stores/namespace-store'
|
|
AnalyticsStore: require '../src/flux/stores/analytics-store'
|
|
WorkspaceStore: require '../src/flux/stores/workspace-store'
|
|
FocusedTagStore: require '../src/flux/stores/focused-tag-store'
|
|
FocusedContentStore: require '../src/flux/stores/focused-content-store'
|
|
FocusedContactsStore: require '../src/flux/stores/focused-contacts-store'
|
|
FileUploadStore: require '../src/flux/stores/file-upload-store'
|
|
FileDownloadStore: require '../src/flux/stores/file-download-store'
|
|
UnreadCountStore: require '../src/flux/stores/unread-count-store'
|
|
|
|
# Errors
|
|
APIError: APIError
|
|
OfflineError: OfflineError
|
|
TimeoutError: TimeoutError
|
|
|
|
## TODO move to inside of individual Salesforce package. See https://trello.com/c/tLAGLyeb/246-move-salesforce-models-into-individual-package-db-models-for-packages-various-refactors
|
|
SalesforceAssociation: require '../src/flux/models/salesforce-association'
|
|
SalesforceSearchResult: require '../src/flux/models/salesforce-search-result'
|
|
SalesforceObject: require '../src/flux/models/salesforce-object'
|
|
SalesforceSchema: require '../src/flux/models/salesforce-schema'
|
|
|
|
# Also include all of the model classes
|
|
for key, klass of Utils.modelClassMap()
|
|
Exports[klass.name] = klass
|
|
|
|
module.exports = Exports
|