Giter Site home page Giter Site logo

Comments (8)

shairez avatar shairez commented on May 20, 2024 4

Thanks @katharinakoal @NetanelBasal @yjaaidi for your feedback!

Younes - yeah, I agree with returning a promise
That's what was solved by @edbzn 's PR #3

The original observerSpy.onComplete() callback was added because I just didn't think about async-await.
And that's why I love open-source so much 😄

One use case I can think of is maybe older code that doesn't support async-await or promises, but I don't think it's that common, so we might just remove it in the future...

from observer-spy.

NetanelBasal avatar NetanelBasal commented on May 20, 2024 2

I'm not sure what's the use case for this hook. In addition to that, if you add the onComplete hook, it makes sense to be consistent and expose onError and onNext hooks.

from observer-spy.

yjaaidi avatar yjaaidi commented on May 20, 2024 2

Solution: I wouldn't implement this feature. 😁

Alternative: I would replace by it by .whenComplete(): Promise and only document usage for await observer.whenComplete().

Reason: I think that tests should never use callbacks because:

  • they makes tests harder to read
  • most users might forget to call done()
  • allowing callbacks encourages waterfall
  • it kind of breaks one of the purposes of ObserverSpy which is to avoid assertions in the subscribe

If we keep it, I would expect it to be an Observable so I can use it this way observer.onComplete.subscribe(completeObserverSpy) 😜

I might miss some edge case where a callback is easier to read... but I can't figure it out.

from observer-spy.

katharinakoal avatar katharinakoal commented on May 20, 2024 1

I want to add a point to the downsides:
When overloading the constructor, it might be confusing to "guess" how the argument influences the instance.
This could be solved by adding a static factory method like this:
const spy = ObserverSpy.withCompleteCallback(fn)

But then again, it's getting a bit complex. Maybe it's worth it, and I'm just missing some other advantages?

from observer-spy.

edbzn avatar edbzn commented on May 20, 2024

Hi, agree with @yjaaidi about using Promises, it's always better! Maybe we can deprecate the onComplete(fn) overload and remove the callback support later.

from observer-spy.

shairez avatar shairez commented on May 20, 2024

Thanks for the feedback @edbzn !

I thought about maybe another potential reason - whether using promises has any performance implications (microtasks queue wise)

So maybe callbacks, for sync Observables, could have slightly better performance? (not sure, just an unchecked thought) and that could be a reason to keep them...

Any thoughts/insights about that?

from observer-spy.

yjaaidi avatar yjaaidi commented on May 20, 2024

Interesting point 🤔
I don't think that this would have dramatic performance impact. I would worry more about tests that want to check if some operator like observeOn is triggering a microtask or running synchronously... but it's an extreme edge case, in my opinion.

Otherwise, I'd focus more on simplicity and reducing the library's surface than the impact of an almost superfluous teeny-weeny micro tasky 😊

from observer-spy.

shairez avatar shairez commented on May 20, 2024

Finally I had some time to get back to these issues 😅

I'm closing this issue as it seems like the majority thinks it's better to stay with async await (promises).

Thanks everyone for participating!

BTW, You can view the latest release with @ThomasBurleson 's improvements here -

https://github.com/hirezio/observer-spy/releases/tag/v1.4.0

from observer-spy.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.