Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

evgenyfadeev
Copy link
Contributor

Replaces PR #206

  • 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]

* 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]
@evgenyfadeev
Copy link
Contributor Author

@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.

@evgenyfadeev evgenyfadeev changed the title Completes removal of callbacks from the setState calls in App.js - THIS PR IS A REPLACEMENT OF PR 206 Completes removal of callbacks from the setState calls in App.js - replaces PR 206 Jan 7, 2025
Copy link
Owner

@didoesdigital didoesdigital left a 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()
Copy link
Owner

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,
Copy link
Owner

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) {
Copy link
Owner

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)

@evgenyfadeev
Copy link
Contributor Author

@didoesdigital I'll investigate, thanks for the details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants