-
Notifications
You must be signed in to change notification settings - Fork 140
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
♻️ factorize LifeCycle and simplify its types #2165
Conversation
In typescript, "instantiation expression" is value with a parametric type that appear outside of a call expression, for example `Array<number>` but not `Array<number>()`. As they transpile to a simple identifier, they can be considered as pure.
LifeCycle events cannot be parametric anymore, so this commit replaces `notify<Foo>(...)` with `satisfies Foo` which provides the same guarantees.
packages/logs/src/domain/logsCollection/console/consoleCollection.ts
Outdated
Show resolved
Hide resolved
|
Codecov Report
@@ Coverage Diff @@
## main #2165 +/- ##
==========================================
+ Coverage 93.72% 93.74% +0.02%
==========================================
Files 198 199 +1
Lines 6089 6078 -11
Branches 1357 1355 -2
==========================================
- Hits 5707 5698 -9
+ Misses 382 380 -2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Motivation
The
LifeCycle
implementation was duplicated in Logs and RUM, because we used function overload to have proper typings and those cannot be abstracted away.The typings around LifeCycle was a bit noisy, as each function signature needed to be repeated for each event type, and the data associated needed to be repeated for each function.
Changes
Instead of function overloads, use an
EventMap
based implementation, similar to the pattern used by the TypeScript libraries to type event listeners.This allows to factorize the LifeCycle code between RUM and Logs and simplify typings.
Also I added simple unit tests around LifeCycles.
Testing
I have gone over the contributing documentation.