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

♻️ factorize LifeCycle and simplify its types #2165

Merged
merged 7 commits into from
Apr 13, 2023

Conversation

BenoitZugmeyer
Copy link
Member

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

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

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.
@BenoitZugmeyer BenoitZugmeyer requested a review from a team as a code owner April 12, 2023 12:49
@bits-bot
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ BenoitZugmeyer
❌ desponda
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov-commenter
Copy link

Codecov Report

Merging #2165 (50cf7f1) into main (046e3a5) will increase coverage by 0.02%.
The diff coverage is 95.65%.

@@            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     
Impacted Files Coverage Δ
packages/logs/src/boot/startLogs.ts 86.11% <0.00%> (ø)
packages/core/src/tools/abstractLifeCycle.ts 100.00% <100.00%> (ø)
packages/logs/src/domain/lifeCycle.ts 100.00% <100.00%> (+14.28%) ⬆️
...domain/logsCollection/console/consoleCollection.ts 100.00% <100.00%> (ø)
...c/domain/logsCollection/logger/loggerCollection.ts 100.00% <100.00%> (ø)
...sCollection/networkError/networkErrorCollection.ts 88.70% <100.00%> (ø)
...c/domain/logsCollection/report/reportCollection.ts 100.00% <100.00%> (ø)
...sCollection/runtimeError/runtimeErrorCollection.ts 100.00% <100.00%> (ø)
packages/rum-core/src/domain/lifeCycle.ts 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@BenoitZugmeyer BenoitZugmeyer merged commit daf523f into main Apr 13, 2023
@BenoitZugmeyer BenoitZugmeyer deleted the benoit/factorize-lifecycle branch April 13, 2023 08:14
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.

7 participants