-
Notifications
You must be signed in to change notification settings - Fork 16
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
Completes removal of callbacks from the setState calls in App.js - replaces PR 206 #208
base: master
Are you sure you want to change the base?
Completes removal of callbacks from the setState calls in App.js - replaces PR 206 #208
Conversation
* adds App.shouldUpdateLessonsProgress(state) * moves update of lessonsProgress from applyStopLessonSideEffects to getFutureStateToStopLesson * stopLesson(): - factored out applyStopLessonSideEffects() - factored out getFutureStateToStopLesson() * isFinished takes state as an argument, instead of using this.state * processBuffer(): - consists of getNewStateAndSideEffectsForBuffer(), application of side-effects and a single setState() call * getNewStateAndSideEffectsForBuffer(): - contains the logic of the past processBuffer function, but does not use the global this.state, instead takes the previous value as an argument and returns the updated value, which is then applied in the setState() call - if the lesson is finished, applies the stop lesson side effects and returns the state for the stopped lesson - getNewStateAndSideEffectsForBuffer is intended to be a pure function - returns a tuple of [newState, sideEffects]
@didoesdigital I've created this new PR by applying a diff of #206 (excluding the submodule) as a single commit on top of the master. If it's easier to view what was done previously commit-by commit, you might have a look at the commits in #206. Otherwise (excluding that this is a single commit and no submodule merge conflict), this PR is identical to 206. I've closed the #206 for clarity. |
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.
@evgenyfadeev Great work on this. Thanks for fixing up the submodule by opening a new PR.
There's a bug in this PR that I can't quite track down. When visiting progress revision lessons such as Your words, Your memorised words, or Your revision words via the links at the top of the Progress page, it doesn't correctly update the lesson. To reproduce an example of the issue:
- Start on the Progress page
- Visit a regular lesson like Introduction
- Visit the Progress page via primary nav
- Visit the memorised words progress revision lesson:
- Expected: Shows "Your memorised words" as the lesson title
- Actual: Continues to show "Introduction" as the lesson title
- If that doesn't consistently reproduce it, then continue: Visit Progress page again
- Visit the seen words progress revision lesson:
- Expected: Shows the lesson title that matches the URL
- Actual: Continues to show the previous lesson's title
I haven't been able to pin down the exact cause. It might be related to changing user settings triggering a late setupLesson()
call with no arguments, or maybe a race condition from setupLesson
being called with the old state from handle lesson after setUpProgressRevisionLesson
calls it with the correct state, or something else. Would you please investigate this further?
this.stopTimer(); | ||
shouldUpdateLessonsProgress(state) { | ||
/* | ||
* Should this also check for /lessons/custom/setup? - see setupLesson() |
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.
Probably no need to check for /setup
here because there's no stop button on the lessons/custom/setup
page to trigger the stop lesson code that usually updates lesson progress info.
processBuffer(actualText, buffer) { | ||
const [newState, sideEffects] = this.getNewStateAndSideEffectsForBuffer(actualText, | ||
buffer, | ||
this.state, |
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.
We should pass in a copy of the state instead of the current state so that we don't mutate state directly with assignments like state.timer = 0;
instead of using setState
to make changes.
* | ||
* @actualText param is not used - probably should be removed | ||
*/ | ||
processBuffer(actualText, buffer) { |
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.
We could add const state = Object.assign({}, this.state);
here and pass in state
instead of this.state
below (see next comment for details)
@didoesdigital I'll investigate, thanks for the details. |
Replaces PR #206
adds App.shouldUpdateLessonsProgress(state)
moves update of lessonsProgress from applyStopLessonSideEffects to getFutureStateToStopLesson
stopLesson():
isFinished takes state as an argument, instead of using this.state
processBuffer():
getNewStateAndSideEffectsForBuffer():