-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(TS): fix type inference for publish variants
- We can never get out of via TypeScript any how. - Resolves a larger issue where operators with a single, static argument and a single generic inferred too strongly from the argument and lost the additional type information from the source.
- Loading branch information
Showing
11 changed files
with
43 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
import { Observable } from '../Observable'; | ||
import { BehaviorSubject } from '../BehaviorSubject'; | ||
import { multicast } from './multicast'; | ||
import { ConnectableObservable } from '../observable/ConnectableObservable'; | ||
import { UnaryFunction } from '../types'; | ||
import { OperatorFunction } from '../types'; | ||
|
||
/** | ||
* @param value | ||
* Multicasts the observable source through an underlying {@link BehaviorSubject}. All subscriptions | ||
* to the resulting observable will subscribe to the underlaying `BehaviorSubject`, the | ||
* resulting observable is a {@link ConnectableObservable}. If you call `connect()` on that observable | ||
* (requires a cast to `ConnectableObservable` in TypeScript), it will subscribe to the source | ||
* observable with the underlying subject and connect that source too all consumers subscribed through the | ||
* subject. Because it's using a `BehaviorSubject`, all new subscriptions will get the most recent value | ||
* that has passed through said subject, _or_ they will get the `initialValue` if no values have | ||
* arrived yet, so long as the published `ConnectableObservable` has been connected. | ||
* | ||
* @param initialValue | ||
* @return {ConnectableObservable<T>} | ||
* @method publishBehavior | ||
* @owner Observable | ||
*/ | ||
export function publishBehavior<T>(value: T): UnaryFunction<Observable<T>, ConnectableObservable<T>> { | ||
return (source: Observable<T>) => multicast(new BehaviorSubject<T>(value))(source) as ConnectableObservable<T>; | ||
export function publishBehavior<T, D>(initialValue: D): OperatorFunction<T, T | D> { | ||
return (source: Observable<T>) => multicast(new BehaviorSubject<T | D>(initialValue))(source); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters