Skip to content

Commit

Permalink
refactor(operate): Tweak init return type so Subscribers and Subscrip…
Browse files Browse the repository at this point in the history
…tions can no longer be returned

This will help force us to make sure we are using the subscriber and subscription chaining in the most efficient way possible. Although it could result in anti-patterns where users return a function that calls unsubscribe on a subscription if we release this to the public.
  • Loading branch information
benlesh committed Sep 23, 2020
1 parent c056a40 commit ee7de5d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/internal/util/lift.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @prettier */
import { Observable } from '../Observable';
import { Subscriber } from '../Subscriber';
import { OperatorFunction, TeardownLogic } from '../types';
import { OperatorFunction } from '../types';

/**
* Used to determine if an object is an Observable with a lift function.
Expand All @@ -14,7 +14,9 @@ export function hasLift(source: any): source is { lift: InstanceType<typeof Obse
* Creates an `OperatorFunction`. Used to define operators throughout the library in a concise way.
* @param init The logic to connect the liftedSource to the subscriber at the moment of subscription.
*/
export function operate<T, R>(init: (liftedSource: Observable<T>, subscriber: Subscriber<R>) => TeardownLogic): OperatorFunction<T, R> {
export function operate<T, R>(
init: (liftedSource: Observable<T>, subscriber: Subscriber<R>) => (() => void) | void
): OperatorFunction<T, R> {
return (source: Observable<T>) => {
if (hasLift(source)) {
return source.lift(function (this: Subscriber<R>, liftedSource: Observable<T>) {
Expand Down

0 comments on commit ee7de5d

Please sign in to comment.