Skip to content

Commit

Permalink
chore: add a comment
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed May 20, 2021
1 parent 877b379 commit 854abf6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/internal/operators/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,15 @@ export function share<T>(options: ShareConfig<T>): MonoTypeOperatorFunction<T>;
* @return A function that returns an Observable that mirrors the source.
*/
export function share<T>(options: ShareConfig<T> = {}): MonoTypeOperatorFunction<T> {
return (observable) => {
// It's necessary to use a wrapper here, as the _operator_ must be
// referentially transparent. Otherwise, it cannot be used in calls to the
// static `pipe` function - to create a reusable pipeline.
//
// The _operator function_ - the function returned by the _operator_ - will
// not be referentially transparent - as it shares its source - but the
// _operator function_ is called when the complete pipeline is composed - not
// when the static `pipe` function is called.
return (wrapperSource) => {
const { connector = () => new Subject<T>(), resetOnError = true, resetOnComplete = true, resetOnRefCountZero = true } = options;

let connection: SafeSubscriber<T> | null = null;
Expand Down Expand Up @@ -218,7 +226,7 @@ export function share<T>(options: ShareConfig<T> = {}): MonoTypeOperatorFunction
});
from(source).subscribe(connection);
}
})(observable);
})(wrapperSource);
};
}

Expand Down

0 comments on commit 854abf6

Please sign in to comment.