Skip to content

Add smaller operator creation function. #5739

@benlesh

Description

@benlesh

This work is blocked on finishing #5729 reviews and landing it... but the crux of it is simple enough... this pattern exists in all operators:

export function someOperator<A, B>(...args: any[]): OperatorFunction(A, B) {
  return (source: Observable<A>) => lift(source, function (this: Subscriber<B>, liftedSource: Observable<A>) { 
      // Do things here and maybe return teardown.
  });
}

The idea is to go through and replace the return here with a helper that does this wiring for us:

function operate<A, B>(init: (subscriber: Subscriber<B>, liftedSource: Observable<A>) => TeardownLogic) {
   return (source: Observable<A>) => wrappedLift(source, init);
}

usage:

export function someOperator<A, B>(...args: any[]): OperatorFunction(A, B) {
  return operate((subscriber, liftedSource) => { 
      // Do things here and maybe return teardown.
  });
}

Then use it in each operator to further reduce size. It may also help with readability? Either way, comments will be required.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions