Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

refactoring ideas #16

Open
hungriesthippo opened this issue Feb 18, 2021 · 1 comment
Open

refactoring ideas #16

hungriesthippo opened this issue Feb 18, 2021 · 1 comment

Comments

@hungriesthippo
Copy link
Contributor

Just want to say this is not a criticism of the code! It's not unmanageable. Mostly I think it's a fun example for a more functional/reactive style.

First: defining the state

{
  inSession: boolean
  cardsToReview: Card[], // current card at 0
  answerRevealed: boolean
}

a sketch of the main loop

state.cardsToReview = loadCards();
while (state.inSession && state.cardsToReview.length) {
  await render(state);
  const card = state.cardsToReview[0];
  let [answerRevealed, signal] = await showAnswerOrSkip(card);
  if (answerRevealed !== state.answerRevealed) {
    state.answerRevealed = answerRevealed
    await render(state);
  }
  signal ||= await getResponse(card);
  updateHistory(card, signal);
  state.cardsToReview.splice(0, 1);  // or pass cardsToReview to updateHistory
  state.answerRevealed = false;
}
render(state);

Let me know what you think. My customization stuff coming soon may help motivate the changes.

@LuccaHellriegel
Copy link
Collaborator

LuccaHellriegel commented Feb 21, 2021

Hey @hungriesthippo,

I just had a call with @aidam38 and we agreed that I would do a minimally-intrusive refactoring/preparing for the script to be able to be unit-tested so we can make future changes with more confidence.
A more functional style is a huge part of that and I plan to extract some pure functions as a first step (+ add npm).

https://github.com/LuccaHellriegel/roamsr/tree/refactoring-for-unit-tests

Maybe we can integrate your ideas after I have put some unit-tests into place so we can be sure that it generally still works?
Happy to chat about possible refactorings.

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

No branches or pull requests

2 participants