-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Move preferences to redux #5401
Conversation
this.recordedDefaultEditorMode = true; | ||
} | ||
const editorMode = this.props.editorModePreference || 'tinymce'; | ||
if ( ! this.recordedDefaultEditorMode ) { |
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.
This is not quite the same effect as existed previously, as before we had guarded against recording the default mode until after preferences have loaded. With this refactor, we can't guarantee that the recorded mode is in-fact the user preference, as it may simply be the fallback value while preferences are loading.
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! That logic was very well hidden! I rewrite it a bit to behave in the same way and maybe a bit clearer.
case PREFERENCES_RECEIVE: | ||
return false; | ||
case PREFERENCES_FETCH: | ||
return true; |
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.
Don't forget to not persist this
case SERIALIZE:
case DESERIALIZE:
return false;
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.
Done!
We should also be sure to remove the |
Also, I think I will move this in following direction:
|
5b5e5dd
to
4d297b0
Compare
} ); | ||
|
||
it( 'should use DEFAULT_PREFERENCES from constants as a default', () => { | ||
expect( reducer( undefined, {} ).values ).to.deep.equal( DEFAULT_PREFERENCES ); |
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.
.eql
is deep equal, and .equal
checks for reference equality
👍 I took this out for a spin and it works well. Ping me when you add a schema in and I can retest persistence. We should be able to |
Not sure if we have a particular timeline for this, but I'd really like to start investigating some improvements to how we accept preferences in our REST API generally, especially in mind of some of the hacks we've needed to incorporate (including entire preferences payload in update) and to address 2FA authorization stale issues (#202). I guess this may not be a blocker for the pull request, since as long as the action creator and selectors signatures continue to match our intended direction (single preference updating and retrieval) it won't be difficult to change the underlying request/storage behavior. Ref: 600-gh-io |
These issues are out of scope for this PR but +1 for fixing these in follow up PRs. Do we have issues open for some of the API improvements? |
|
||
const values = combineReducers( mapValues( DEFAULT_PREFERENCES, | ||
( value, key ) => createReducerForPreferenceKey( key, value ) | ||
) ); |
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.
Very interesting usage :D
So I'd taken for granted our discussion about the need for Past discussion: |
@aduth : thanks for investigating!
Done. |
👍 Looks good to me. Don't forget to squash. 😄 |
Hmm, testing this live, it doesn't seem that the change in preference takes effect when switching editor tabs after the first refresh. It takes a second refresh in order to stick. |
@@ -884,7 +886,9 @@ export default connect( | |||
receivePost, | |||
editPost, | |||
resetPostEdits, | |||
setEditorPostId | |||
setEditorPostId, | |||
setPreference, |
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.
Not using setPreference
prop?
@artpi reloading a page seems to get rid of my recently selected sites. |
That seems unrelated, I did not touch recentSites, I only introduced a framework. |
Moves Preferences data to redux, as listed in #5046
preferences
redux treeQueryPreferences
componentpost-editor
Nice and shiny readme
Motivation
calypso-labs
to let users enable experimental features and need a place to store dataTesting
Only preference moved is editor mode, so:
CC @rralian @gwwar @mtias @aduth @retrofox