-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
[reader] Refactor reader.js #410
Conversation
24h, merging |
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.
Looks good! sorry I got to this late
|
||
|
||
@api.route("/texts/<text_slug>/<section_slug>") | ||
def reader_json(text_slug, section_slug): |
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.
Add a test in test_texts.py?
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, added in #415.
This commit refactors our reader code to better make use of Alpine. The changes here impose a simple reactive dataflow where the source of truth is whatever is stored on the Alpine application object.
Why do this now?
The reader.js code is manageable but just barely so. The current data model makes it difficult to reason about the application state and write tests. By doing more of the heavy lifting in Alpine and its reactive data model, we can simplify several parts of the code while maintaining the same functionality and making it easier to build new features.
Summary of changes
HTML:
x-cloak
,template
, and other Alpine devices to more compactly describe JS-specific logic.texts/section.html
, which we use to initiaiize the Alpine app.reader.js
intotexts/section.html
.JavaScript:
transliterateHTML
andtransliterateStr
functions that depend onthis.script
. Application data is always stored in Devanagari, which means that we can now support scripts like Gurmukhi and Bengali that don't losslessly round-trip. Because of the dependency onthis.script
, these functions will rerun wheneverthis.script
changes.this.uiScript
, since it is no longer necessary.Layout
andScript
.Python:
.asdict()
.CSS:
side-by-side
andin-place
classes and move this logic intoreader.js
Overall:
Differences from prod
Future plans
Test plan
I added unit tests to increase the overall statement coverage for
reader.js
from 30% to 50%. In addition, I tested the following behaviors on dev: