-
Notifications
You must be signed in to change notification settings - Fork 563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor selected note state from flux to redux #1851
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You picked a hard one to start with 😀
I know we have some poor examples in the code already where our action creators are imperative and they suggest that we should move more logic into the middleware but I don't think there's any need in this PR to make any changes to the middleware - it looked like all of the code there could exist solely in the selectedNote
reducer.
If that doesn't make sense I'd be happy to delve further into it but would you mind trying to make that change here? It will probably feel better after that.
47d68b8
to
044bf8e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we need to rebase this ontop of the changes introduced in #1855.
Specifically noting the need in action-types
where we're introducing a new string action-type export.
This PR moves the selected note state from flux to redux. It also eliminates the need for selectedNoteId in appState.
057fc0a
to
54596f0
Compare
@dmsnell This is ready for more review. |
- Add type annotations where we're introducing new state - Remove references to `noteUpdatedRemotely` - Remove ability to `selectNote(null)` - Remove unused `tags` prop
@belcherj I added a new commit to try out the changes I proposed.
I'll be thoroughly testing this later on but I need a break from it at the moment |
I have tested this a bunch today. I think it is ready to roll. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for everything here; it's really exciting to see state finally cleaning up. According to your own testing please merge at your convenience.
In #1851 we refactored the selected note state but during testing missed a reference to `state.appState.note` which should have been updated to `state.ui.note`. Nothing crashed in the app because it was being used for its truthiness but the result was that when checking if Markdown was enabled for any given note the answer would always end up as "no." In this patch we're restoring the state reference which fixes that bug and restores the preview button in the note toolbar.
In #1851 we refactored the selected note state but during testing missed a reference to `state.appState.note` which should have been updated to `state.ui.note`. Nothing crashed in the app because it was being used for its truthiness but the result was that when checking if Markdown was enabled for any given note the answer would always end up as "no." In this patch we're restoring the state reference which fixes that bug and restores the preview button in the note toolbar.
Resolves #1879 It appears that we removed a flow in #1851 which updated app state in response to updates from the note editor[1]. While this didn't impact the operation of the editor it did present itself as a bug when previewing markdown-rendered notes. The editor is stateful on its own and so continued to function independently of the state of the selected note's content. The preview, however, grabs the contents of the selected note whenever it's activated and then renders those into a DOM node. This means that it showed the old contents of the note unless you navigated to another note and back, which swapped out the selected note with the new updated contents. In this patch, which currently is probably wrong in some way, we're updating the selected note when calling `onChangeContent` so that we don't get out of sync with the data sources. Hopefully at the end of our state cleanup and stabilization project this will disappear but for now this fix catches the gap that left split data sources. Probably there were other bugs we didn't discover as a result of this. Mainly we need to test and audit for traces of cycles/loops in the update so that we don't start spinning or overwriting data we just entered. In my brief testing the easy cases worked as I expected them to simply and singly. [1]: https://github.com/Automattic/simplenote-electron/pull/1851/files#diff-3c87750a7cc32e0127447ffc78f5c0d5L300
* Fix: Update selected note when making changes in the editor view Resolves #1879 It appears that we removed a flow in #1851 which updated app state in response to updates from the note editor[1]. While this didn't impact the operation of the editor it did present itself as a bug when previewing markdown-rendered notes. The editor is stateful on its own and so continued to function independently of the state of the selected note's content. The preview, however, grabs the contents of the selected note whenever it's activated and then renders those into a DOM node. This means that it showed the old contents of the note unless you navigated to another note and back, which swapped out the selected note with the new updated contents. In this patch, which currently is probably wrong in some way, we're updating the selected note when calling `onChangeContent` so that we don't get out of sync with the data sources. Hopefully at the end of our state cleanup and stabilization project this will disappear but for now this fix catches the gap that left split data sources. Probably there were other bugs we didn't discover as a result of this. Mainly we need to test and audit for traces of cycles/loops in the update so that we don't start spinning or overwriting data we just entered. In my brief testing the easy cases worked as I expected them to simply and singly. [1]: https://github.com/Automattic/simplenote-electron/pull/1851/files#diff-3c87750a7cc32e0127447ffc78f5c0d5L300 * Handle tag updates too by always re-selecting note on updates from the server When tags were being updated in the pap they also came through this function but they weren't coming through `onUpdateContent`, meaning that our fix overlooked tags and probably also system tags and the like. In this patch we're no longer selectively updating the note if it has a remote patch (indicating that it came from another device). Instead, we're always updating and selectively setting `hasRemoteUpdate` based on that knowledge. This ensures that we maintain consistency with local updates.
Fix
This PR moves the selected note state from flux to redux. It also eliminates
the need for selectedNoteId in appState.
Test
Review
Only one developer is required to review these changes, but anyone can perform the review.
Release
RELEASE-NOTES.txt
was updated with: