-
Notifications
You must be signed in to change notification settings - Fork 87
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
refactor: convert analytics module to TypeScript/fp-ts, remove statistics animation on landing page #1361
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
liangyuanruo
changed the title
fix: remove statistics animation on landing page
fix: convert analytics module to TypeScript/fp-ts, remove statistics animation on landing page
Mar 14, 2021
liangyuanruo
changed the title
fix: convert analytics module to TypeScript/fp-ts, remove statistics animation on landing page
refactor: convert analytics module to TypeScript/fp-ts, remove statistics animation on landing page
Mar 14, 2021
liangyuanruo
force-pushed
the
fix/landing
branch
from
March 15, 2021 03:26
d6b0f34
to
71b0792
Compare
- A for Array - E for Either - F for function - TE for TaskEither
mantariksh
reviewed
Mar 15, 2021
mantariksh
approved these changes
Mar 15, 2021
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Migrating Analytics client service to TypeScript
Addresses #1339
Remove statistics animation
Landing page statistics animation is not only tacky, but violates many principles of UI animation:
Solution
First, I removed the browser statistics animation entirely, moving the code for its retrieval to be resolved before the page is mounted. The Analytics client service was also rewritten in TypeScript.
Next, I created a new
/analytics/statistics
API endpoint as an additional optimisation to unify the three API calls to fetch the user, form, and submission counts respectively. Although speed gains ought be minimal due to HTTP/2 multiplexing, it does allow for the frontend and backend to share the newAnalyticStats
type.A fix was also put in MyInfo tests imports, which accidentally imported from the build folder definition instead of source - see 6a9c7c2.
Introducing fp-ts
I decided to introduce
fp-ts
to the module so that we may gain exposure from a wider set of functional programming paradigms beyond the small subset provided byfp-ts
. The analytics module is well-suited as it is relatively small and standalone in nature.Conversion from
neverthrow
tofp-ts
has been relatively straightforward -Result<T, E>
becomesEither<E, A>
andResultAsync<T, E>
becomesTaskEither<E, A>
, with the left and right type parameters swapping sides.Imperative programming style is replaced with constructing a larger function via the
pipe
function, then executing it immediately, almost IIFE-style. The logical fork of an if-else statement is replaced withbimap
, which accepts two map functions for the failure and success case of a TaskEither result. The utility functionResult.combine
to aggregateResult
s is replaced withsequence
, which can convertTaskEither<E, A>[]
toTaskEither<E, A[]>
.