Giter VIP home page Giter VIP logo

Comments (10)

headinthebox avatar headinthebox commented on August 18, 2024

Why not. Historically they came from IDisposable, which was used by itself, but that is not the case here.

from rxjs.

benlesh avatar benlesh commented on August 18, 2024

Based on the parts of the discussion in #71, I think this is a solid idea. Can I get more opinions, @trxcllnt? @vsavkin? @staltz?

The proposal is this... the two interfaces:

interface Observer {
  next(value: any): void
  error(err: any): void
  complete(value: any): void
  subscribe(subscription: Subscription)
}

interface Subscription {
  unsubscribe(): void
  isUnsubscribed: boolean
  add(subscription: Subscription)
  remove(subscription: Subscription)
}

be implemented/combined on a single class:

interface Subscriber {
  next(value: any): void
  error(err: any): void
  complete(value: any): void
  subscribe()
  unsubscribe(): void
  isUnsubscribed: boolean
  add(subscription: Subscription)
  remove(subscription: Subscription)
}

Notice the subscribe event has changed, since it doesn't need to pass itself to itself.

from rxjs.

benlesh avatar benlesh commented on August 18, 2024

I'd also love @zenparsing's input, since they are bike shedding the related things in the es-observable spec.

from rxjs.

headinthebox avatar headinthebox commented on August 18, 2024

+1, but call it Observer.

from rxjs.

ktrott avatar ktrott commented on August 18, 2024

RxJS Next meeting notes
(attendees: @Blesh, @jhusain, @trxcllnt, @benjchristensen, @steveorsomethin)
Agreed to move forward with @Blesh proposal

from rxjs.

staltz avatar staltz commented on August 18, 2024

How would this single interface work to support the use case of Observers in the lift operator?

interface Subscriber {
  next(value: any): void // <---- notice the void return
  error(err: any): void
  complete(value: any): void
  subscribe()
  unsubscribe(): void
  isUnsubscribed: boolean
  add(subscription: Subscription)
  remove(subscription: Subscription)
}

The map example from issue #60

class Observable {
  constructor(subscribe) {
    if(subscribe) {
      this.subscribe = subscribe;
    }
  }
  subscribe(observer) {
    return this.source.subscribe(this.observerFactory.create(observer));
  }
  lift(observerFactory) {
    const o = new Observable();
    o.source = this;
    o.observerFactory = observerFactory;
    return o;
  }
  map(selector) {
    return this.lift(new MapObserverFactory(selector));
  }
}

class MapObserverFactory {
  constructor(selector) {
    this.selector = selector;
  }
  create(destination) {
    return new MapObserver(destination, this.selector);
  }
}

class MapObserver {
  constructor(destination, selector) {
    this.selector = selector;
    this.destination = destination;
  }
  next(x) {
    return this.destination.next(this.selector(x)); // <--- notice, not a void return
  }
  throw(e) {
    return this.destination.throw(e);
  }
  return(e) {
    return this.destination.return(e);
  }
}

from rxjs.

staltz avatar staltz commented on August 18, 2024

To clarify a bit: I find it weird when I see an Observer returning a value in next(). An Observer is a consumer/sink, so it shouldn't need to return anything. In RxJava, lift doesn't get an Observer, it gets an Operator, which implements Subscriber and Observer together with Func1.

from rxjs.

benlesh avatar benlesh commented on August 18, 2024

How would this single interface work to support the use case of Observers in the lift operator?

Well, it's it's not really a single interface, it's a single class that implements two interfaces. A Subscriber could be used as an Observer or could be used as a Subscription. The lift implementation shouldn't change much if at all.

I find it weird when I see an Observer returning a value in next()

@staltz ... void return is a void return. It's the result of an absence of a return. Just TypeScript semantics. FWIW: the ES7 Observable spec is bike shedding an interface here that shows next returning any... like you, I'm not sure how that is of value. So it's probably worth adding your voice over there.

from rxjs.

staltz avatar staltz commented on August 18, 2024

void return is a void return. It's the result of an absence of a return. Just TypeScript semantics.

@Blesh I know 🌝

from rxjs.

benlesh avatar benlesh commented on August 18, 2024

Done in master now.

from rxjs.

Related Issues (20)

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.