rxjs#withLatestFrom TypeScript Examples
The following examples show how to use
rxjs#withLatestFrom.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: keyboard-event-dispatcher.ts From scion-microfrontend-platform with Eclipse Public License 2.0 | 6 votes |
private installKeystrokeListener(): void {
Beans.get(ContextService).names$()
.pipe(
map(contextNames => Array.from(contextNames)),
filterArray(contextName => contextName.startsWith(KEYSTROKE_CONTEXT_NAME_PREFIX)),
mapArray(keystrokeContextName => keystrokeContextName.substring(KEYSTROKE_CONTEXT_NAME_PREFIX.length)),
mapArray(keystroke => this.observeKeyboardEvent$(keystroke)),
switchMap(keyboardEvents => merge(...keyboardEvents)),
withLatestFrom(Beans.get(ContextService).observe$<OutletContext>(OUTLET_CONTEXT).pipe(filter(Boolean))),
takeUntil(this._destroy$),
)
.subscribe(([event, outletContext]) => runSafe(() => this.onKeyboardEventToPropagate(event, outletContext.uid)));
}
Example #2
Source File: preferred-size-service.ts From scion-microfrontend-platform with Eclipse Public License 2.0 | 6 votes |
/**
* Constructs a function to publish the preferred size to the outlet.
*/
private createPreferredSizePublisher(): PreferredSizePublisher {
const publish$ = new Subject<PreferredSize | null>();
publish$
.pipe(
withLatestFrom(Beans.get(ContextService).observe$<OutletContext>(OUTLET_CONTEXT).pipe(filter(Boolean))),
takeUntil(this._destroy$),
)
.subscribe(([preferredSize, outletContext]) => runSafe(() => {
const topic = RouterOutlets.preferredSizeTopic(outletContext.uid);
Beans.get(MessageClient).publish(topic, preferredSize);
}));
return preferredSize => publish$.next(preferredSize);
}
Example #3
Source File: autocomplete.component.ts From alauda-ui with MIT License | 6 votes |
ngAfterContentInit() {
this.hasVisibleSuggestion$ = this.suggestions.changes.pipe(
startWith(this.suggestions),
switchMap((suggestions: QueryList<SuggestionComponent>) =>
suggestions.length > 0
? combineLatest(suggestions.map(suggestion => suggestion.visible$))
: of([] as boolean[]),
),
map(visible => visible.some(Boolean)),
withLatestFrom(this.directive$$),
map(([hasVisibleSuggestion, directive]) => {
if (hasVisibleSuggestion && directive.defaultFirstSuggestion) {
directive.autoFocusFirstSuggestion();
}
return hasVisibleSuggestion;
}),
distinctUntilChanged(),
debounceTime(0),
tap(() => this.cdr.markForCheck()),
publishRef(),
);
this.hasContent$ = combineLatest([
this.hasVisibleSuggestion$,
this.placeholder.changes.pipe(
startWith(this.placeholder),
map(
(list: QueryList<AutocompletePlaceholderComponent>) => !!list.length,
),
),
]).pipe(
map(
([hasVisibleSuggestion, hasPlaceholder]) =>
hasVisibleSuggestion || hasPlaceholder,
),
);
}