Skip to content

Conversation

@anandtiwary
Copy link
Contributor

@anandtiwary anandtiwary commented Feb 10, 2021

Description

Please include a summary of the change, motivation and context.
feat: adding notification operator

Testing

Please describe the tests that you ran to verify your changes. Please summarize what did you test and what needs to be tested e.g. deployed and tested helm chart locally.

Checklist:

  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

Documentation

Make sure that you have documented corresponding changes in this repository or hypertrace docs repo if required.

@anandtiwary anandtiwary marked this pull request as ready for review February 10, 2021 00:06
@anandtiwary anandtiwary requested a review from a team as a code owner February 10, 2021 00:06
@codecov
Copy link

codecov bot commented Feb 10, 2021

Codecov Report

Merging #575 (6887a19) into main (fba66dc) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #575   +/-   ##
=======================================
  Coverage   85.39%   85.40%           
=======================================
  Files         765      765           
  Lines       15712    15719    +7     
  Branches     1996     1996           
=======================================
+ Hits        13418    13425    +7     
  Misses       2261     2261           
  Partials       33       33           
Impacted Files Coverage Δ
...omponents/src/notification/notification.service.ts 96.00% <100.00%> (+1.55%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fba66dc...6887a19. Read the comment docs.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@anandtiwary
Copy link
Contributor Author

anandtiwary commented Feb 10, 2021

Two ways to use this:

  1. observable$.pipe(source => this.notificationService.withNotification(source, 'success', 'failure'), ...<other operators>)
  2. observable$.pipe(this.notificationService.withNotificationOperator('success', 'failure'), ...<other operators>)

With #2, In case operator type definition changes by Rxjs, we would only have to update one function.


public withNotification<T>(source: Observable<T>, successMessage: string, failureMessage: string): Observable<T> {
return source.pipe(
tap(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How difficult is it to make a real operator (I've done it in rxjava where it's pretty confusing, haven't looked in rxjs)? My concern with this one is that it gets awkward to use in a pipe

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I take it back - it looks like rxjs operators are much simpler (should have read your other docs first). Given that, I may suggest switching the names around a bit (so the name looks more like an operator) but otherwise looks good.

something like withNotification -> wrapWithNotification and withNotificationOperator -> withNotification

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I tried building our own operator. I got it to work too, but realized that it still has to go via notification service (since we need injected service). With that in consideration, the native implementation was not providing much value. I switched to the current approach which anyway goes via the service but is much more readable and maintainable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update the name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right - so looking at an example, pipe takes a function of UnaryFunction<Observable<T>, Observable<R>> but the standard lib ones are generally implemented via lift and an operator. I'll have to page back in if there's any benefit to using lift + operator vs pipe, but nothing seems obvious (and if so we can do it without changing the pai.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even their docs examples use pipe - I'd guess lift is the old way of doing it (before they used pipe when everything was on the prototype)
https://reactive.how/rxjs/pipeable-operators

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the pipe approach is pretty popular. rxjs folks are also adding newer apis in 7.x, so this could change too.

The lift approach would require us to build our own operator which comes with additional code.

I think if we are doing something pretty involved then building our own operator makes sense. For something simple, Piggybacking on existing
operators is much cleaner fnow.

@github-actions

This comment has been minimized.

@anandtiwary anandtiwary merged commit 6c2d647 into main Feb 10, 2021
@anandtiwary anandtiwary deleted the notification-update branch February 10, 2021 02:20
@github-actions
Copy link

Unit Test Results

    4 files  ±0  234 suites  ±0   14m 50s ⏱️ + 1m 14s
837 tests +2  837 ✔️ +2  0 💤 ±0  0 ❌ ±0 
841 runs  +2  841 ✔️ +2  0 💤 ±0  0 ❌ ±0 

Results for commit 6c2d647. ± Comparison against base commit fba66dc.

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.

3 participants