fix(drafts): Various improvements and fixes to drafts, draft state management
Summary:
This diff contains a few major changes:
1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario:
- View thread with draft, edit draft
- Move to another thread
- Move back to thread with draft
- Move to another thread. Notice that one or more messages from thread with draft are still there.
There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great.
2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here:
- In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI.
- Previously, when you added a contact to To/CC/BCC, this happened:
<input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates
Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state.
To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source!
This diff includes a few minor fixes as well:
1. Draft.state is gone—use Message.object = draft instead
2. String model attributes should never be null
3. Pre-send checks that can cancel draft send
4. Put the entire curl history and task queue into feedback reports
5. Cache localIds for extra speed
6. Move us up to latest React
Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
Message = require ' ../../src/flux/models/message '
Thread = require ' ../../src/flux/models/thread '
2016-01-26 03:35:11 +08:00
Category = require ' ../../src/flux/models/category '
2015-11-06 12:16:01 +08:00
{ Utils } = require ' nylas-exports '
2015-05-20 07:06:59 +08:00
_ = require ' underscore '
fix(drafts): Various improvements and fixes to drafts, draft state management
Summary:
This diff contains a few major changes:
1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario:
- View thread with draft, edit draft
- Move to another thread
- Move back to thread with draft
- Move to another thread. Notice that one or more messages from thread with draft are still there.
There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great.
2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here:
- In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI.
- Previously, when you added a contact to To/CC/BCC, this happened:
<input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates
Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state.
To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source!
This diff includes a few minor fixes as well:
1. Draft.state is gone—use Message.object = draft instead
2. String model attributes should never be null
3. Pre-send checks that can cancel draft send
4. Put the entire curl history and task queue into feedback reports
5. Cache localIds for extra speed
6. Move us up to latest React
Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
describe ' Thread ' , ->
2015-11-06 12:16:01 +08:00
describe ' serialization performance ' , ->
xit ' 1,000,000 iterations ' , ->
iterations = 0
json = ' [{ " client_id " : " local-76c370af-65de " , " server_id " : " f0vkowp7zxt7djue7ifylb940 " , " object " : " thread " , " account_id " : " 1r6w6qiq3sb0o9fiwin6v87dd " , " snippet " : " http://itunestandc.tumblr.com/tagged/itunes-terms-and-conditions/chrono _______________________________________________ http://www.macgroup.com/mailman/listinfo/smartfriends-chat " , " subject " : " iTunes Terms And Conditions as you \' ve never seen them before " , " unread " :true, " starred " :false, " version " :1, " folders " :[], " labels " :[{ " server_id " : " 8cf4fn20k9pjjhjawrv3xrxo0 " , " name " : " all " , " display_name " : " All Mail " , " id " : " 8cf4fn20k9pjjhjawrv3xrxo0 " },{ " server_id " : " f1lq8faw8vv06m67y8f3xdf84 " , " name " : " inbox " , " display_name " : " Inbox " , " id " : " f1lq8faw8vv06m67y8f3xdf84 " }], " participants " :[{ " name " : " Andrew Stadler " , " email " : " stadler@gmail.com " , " thirdPartyData " :{}},{ " name " : " Smart Friends™ Chat " , " email " : " smartfriends-chat@macgroup.com " , " thirdPartyData " :{}}], " has_attachments " :false, " last_message_received_timestamp " :1446600615, " id " : " f0vkowp7zxt7djue7ifylb940 " }] '
start = Date . now ( )
while iterations < 1000000
if _ . isString ( json )
data = JSON . parse ( json )
object = new Thread ( )
object . fromJSON ( data )
object
iterations += 1
console . log ( ( Date . now ( ) - start ) / 1000.0 + " ms per 1000 " )
2016-01-26 03:35:11 +08:00
describe ' sortedCategories ' , ->
sortedForCategoryNames = (inputs) ->
categories = _ . map inputs , (i) ->
new Category ( name: i , displayName: i )
thread = new Thread ( categories: categories )
return thread . sortedCategories ( )
2015-09-02 05:47:22 +08:00
it " puts ' important ' label first, if it ' s present " , ->
inputs = [ ' alphabetically before important ' , ' important ' ]
2016-01-26 03:35:11 +08:00
actualOut = sortedForCategoryNames inputs
2015-09-02 05:47:22 +08:00
expect ( actualOut [ 0 ] . displayName ) . toBe ' important '
it " ignores ' important ' label if not present " , ->
inputs = [ ' not important ' ]
2016-01-26 03:35:11 +08:00
actualOut = sortedForCategoryNames inputs
2015-09-02 05:47:22 +08:00
expect ( actualOut . length ) . toBe 1
expect ( actualOut [ 0 ] . displayName ) . toBe ' not important '
it " doesn ' t display ' sent ' , ' all ' , ' archive ' , or ' drafts ' " , ->
inputs = [ ' sent ' , ' all ' , ' archive ' , ' drafts ' ]
2016-01-26 03:35:11 +08:00
actualOut = sortedForCategoryNames inputs
2015-09-02 05:47:22 +08:00
expect ( actualOut . length ) . toBe 0
it " displays standard category names which aren ' t hidden next, if they ' re present " , ->
inputs = [ ' inbox ' , ' important ' , ' social ' ]
2016-01-26 03:35:11 +08:00
actualOut = _ . pluck sortedForCategoryNames ( inputs ) , ' displayName '
2015-09-02 05:47:22 +08:00
expectedOut = [ ' important ' , ' inbox ' , ' social ' ]
expect ( actualOut ) . toEqual expectedOut
it " ignores standard category names if they aren ' t present " , ->
inputs = [ ' social ' , ' work ' , ' important ' ]
2016-01-26 03:35:11 +08:00
actualOut = _ . pluck sortedForCategoryNames ( inputs ) , ' displayName '
2015-09-02 05:47:22 +08:00
expectedOut = [ ' important ' , ' social ' , ' work ' ]
expect ( actualOut ) . toEqual expectedOut
it " puts user-added categories at the end " , ->
inputs = [ ' food ' , ' inbox ' ]
2016-01-26 03:35:11 +08:00
actualOut = _ . pluck sortedForCategoryNames ( inputs ) , ' displayName '
2015-09-02 05:47:22 +08:00
expectedOut = [ ' inbox ' , ' food ' ]
expect ( actualOut ) . toEqual expectedOut
it " sorts user-added categories by displayName " , ->
inputs = [ ' work ' , ' social ' , ' receipts ' , ' important ' , ' inbox ' ]
2016-01-26 03:35:11 +08:00
actualOut = _ . pluck sortedForCategoryNames ( inputs ) , ' displayName '
2015-09-02 05:47:22 +08:00
expectedOut = [ ' important ' , ' inbox ' , ' receipts ' , ' social ' , ' work ' ]
expect ( actualOut ) . toEqual expectedOut