Mailspring/static
Ben Gotow 343bb3163b feat(offline-mode, undo-redo): Tasks handle network errors better and retry, undo/redo based on tasks
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
2015-07-07 13:38:53 -04:00
..
components feat(offline-mode, undo-redo): Tasks handle network errors better and retry, undo/redo based on tasks 2015-07-07 13:38:53 -04:00
fonts/FontAwesome Restoring SearchBar, adding FontAwesome for icons not designed yet 2015-03-03 09:49:15 -08:00
images fix(reply-dropdown): Improved assets and dropdown styles, hit regions 2015-06-26 15:03:13 -07:00
mixins fix(less): Lint errors preventing successful build 2015-03-05 15:42:38 -08:00
package-template fix(getting-started): New menu item, sample package for devs 2015-07-06 14:23:51 -04:00
sounds feat(notifications): Initial pass at new mail notifications 2015-02-20 12:19:34 -08:00
variables fix(bold-emoji): Render bold emoji-range characters with standard weight font 2015-06-18 11:35:33 -07:00
buttons.less fix(button-borders): Use box-shadow to acheive 0.5px borders 2015-06-19 15:01:13 -07:00
email-frame.less fix(quoted-text): Do not consider gmail_extra quoted text 2015-06-29 17:26:14 -07:00
font-awesome.min.css Restoring SearchBar, adding FontAwesome for icons not designed yet 2015-03-03 09:49:15 -08:00
index.html feature(templates): Pick templates, fill variable regions, Draft extensions 2015-03-20 10:23:50 -07:00
index.js feat(window-manager): Refactor window code, actually destroy main window when logging out 2015-05-14 14:54:29 -07:00
index.less feat(message): New Message List UI 2015-06-22 15:49:52 -07:00
inputs.less feat(theming): Definitely not hacker mode. I don't know what you're talking about. 2015-06-05 11:40:44 -07:00
jasmine.less refactor(*): Remove Atom package dependecies and Atom styles! 2015-02-06 16:57:33 -08:00
linux.less fix(drafts): Various improvements and fixes to drafts, draft state management 2015-02-03 16:24:31 -08:00
normalize.less fix(less): Lint errors preventing successful build 2015-03-05 15:42:38 -08:00
resizable.less button and less changes 2015-03-03 18:09:57 -08:00
selection.less fix(lint): fix linting css errors 2015-03-26 14:49:03 -04:00
type.less feat(composer): add popout icon and header styles 2015-03-10 18:14:53 -07:00
utilities.less fix(less): Lint errors preventing successful build 2015-03-05 15:42:38 -08:00
workspace.less feat(composer): new composer and button styles 2015-06-17 16:03:50 -07:00