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

refactor(Operator): replace operator<T, R> to interface #1825

Merged
merged 1 commit into from Jul 26, 2016

Conversation

kwonoj
Copy link
Member

@kwonoj kwonoj commented Jul 12, 2016

Description:

This PR replaces implementation Operator<T, R> into interface by base implementation Operator::call is not necessarily needed, since creating new operator requires to override it any time. Instead, this PR makes operator as contract interface only.

@tetsuharuohzeki
Copy link
Contributor

I agree this change

@trxcllnt
Copy link
Member

@kwonoj initially I wrote the Operator as a base class because I intended to have a singleton instance on the Observable class's prototype, which would allow us to remove the branching in subscribe. I'd have to circle back around to see if this would hook up the subscription chain in the right order (might require a change in the Subscriber constructor), but if so, it'd look something like this:

export class Operator<T, R> {
  call(subscriber: Subscriber<R>, source: any): TeardownLogic {
    return source._subscribe(subscriber);
  }
}

export class Observable<T> implements Subscribable<T> {
  /* ... */
  subscribe(observerOrNext?: PartialObserver<T> | ((value: T) => void),
            error?: (error: any) => void,
            complete?: () => void): Subscription {

    const sink = toSubscriber(observerOrNext, error, complete);

    sink.add(this.operator.call(sink, this));

    if (sink.syncErrorThrowable) {
      sink.syncErrorThrowable = false;
      if (sink.syncErrorThrown) {
        throw sink.syncErrorValue;
      }
    }

    return sink;
  }
}
Observable.prototype.operator = new Operator<any, any>();

@kwonoj
Copy link
Member Author

kwonoj commented Jul 13, 2016

Maybe I'm not catching all correctly, is it need all implementation of operator have base classes instead of Observable have specific impl for those behaviors like below?

export interface Operator {
  call(...): TearDownLogic
}

class DefaultOperator<any, any> implements Operator {
  call(..): { return source._subscribe(...) };
}

export class Observable {
  private operator = new DefaultOperator();
}

@trxcllnt
Copy link
Member

@kwonoj yes, or even a private operator function on Observable:

export class Observable {
  private operator(source): TeardownLogic {
    // `this` refers to the Subscriber, because
    // Observable does `this.operator.call(sink, this)`
    return source._subscribe(this); 
  }
}

@kwonoj kwonoj force-pushed the interface-operator branch 2 times, most recently from 68b5cd9 to ae0c163 Compare July 26, 2016 21:03
@kwonoj
Copy link
Member Author

kwonoj commented Jul 26, 2016

Rebased. I think this change can be checked in and @trxcllnt 's change can follow later. Suggestions? /cc @trxcllnt , @jayphelps

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 96.722% when pulling ae0c163 on kwonoj:interface-operator into 8f0dc01 on ReactiveX:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 96.722% when pulling ae0c163 on kwonoj:interface-operator into 8f0dc01 on ReactiveX:master.

- remove base implemetation to call(), not being used
@coveralls
Copy link

coveralls commented Jul 26, 2016

Coverage Status

Coverage increased (+0.01%) to 96.722% when pulling ae0c163 on kwonoj:interface-operator into 8f0dc01 on ReactiveX:master.

@jayphelps
Copy link
Member

jayphelps commented Jul 26, 2016

LGTM

@jayphelps jayphelps merged commit e366734 into ReactiveX:master Jul 26, 2016
@kwonoj kwonoj deleted the interface-operator branch July 26, 2016 22:16
@kwonoj
Copy link
Member Author

kwonoj commented Jul 26, 2016

cool, thanks @jayphelps ! :)

@lock
Copy link

lock bot commented Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants