rxjs/operators#tap TypeScript Examples
The following examples show how to use
rxjs/operators#tap.
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: app.component.ts From gnosis.1inch.exchange with MIT License | 6 votes |
public onTokenChange(): void {
this.resetToTokenAmount();
this.tokenService.tokenHelper$.pipe(
tap((tokenHelper) => {
const token = tokenHelper.getTokenBySymbol(this.fromTokenSymbol);
this.swapForm.controls.fromAmount.setValue(tokenHelper.toFixedSafe(this.fromAmount, token.decimals), {emitEvent: false});
this.fromAmountBN = tokenHelper.parseUnits(this.fromAmount, token.decimals);
this.updateAmounts.next({
fromAmount: this.fromAmount
});
this.tokenAmountInputValidator.pop();
this.updateFromAmountValidator(tokenHelper);
}),
take(1)
).subscribe();
}
Example #2
Source File: logging.interceptor.ts From 42_checkIn with GNU General Public License v3.0 | 6 votes |
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
const now = Date.now();
return next
.handle()
.pipe(
tap(() =>
this.logger.log(
context.switchToHttp().getRequest().route.path,
context.getHandler().name,
Date.now() - now + 'ms',
),
),
);
}
Example #3
Source File: process-output.ts From nx-plugins with MIT License | 6 votes |
export function log() {
return (source: Observable<ProcessOutput>): Observable<ProcessOutput> =>
source.pipe(
tap(({ type, data }) => {
if (type === 'OUT') {
process.stdout.write(data.toString());
} else {
process.stderr.write(data.toString());
}
}),
);
}
Example #4
Source File: epics.ts From anthem with Apache License 2.0 | 6 votes |
highlightDataIntegrityHelpLabel: EpicSignature = action$ => {
// Scroll to the disclaimer when it is made visible.
const scrollToDisclaimerEpic = action$.pipe(
filter(isActionOf(Actions.displayDataIntegrityHelpLabel)),
delay(500),
tap(() => {
const disclaimer = document.getElementById(
"help-page-data-integrity-disclaimer",
);
if (disclaimer) {
disclaimer.scrollIntoView({ block: "start", behavior: "smooth" });
}
}),
delay(500),
map(() => Actions.toggleDataIntegrityHelpLabel(true)),
);
// Dismiss the tooltip after a delay, once it has been scrolled to.
const dismissTooltipAfterDelay = action$.pipe(
filter(isActionOf(Actions.toggleDataIntegrityHelpLabel)),
pluck("payload"),
filter(Boolean),
delay(2500),
map(() => Actions.toggleDataIntegrityHelpLabel(false)),
);
return merge(scrollToDisclaimerEpic, dismissTooltipAfterDelay);
}
Example #5
Source File: artichoke-api.ts From closer-sdk.js with MIT License | 6 votes |
constructor(
public sessionId: proto.ID,
private websocketClient: WebsocketClient,
private httpClient: HttpClient,
) {
this.connectionEvent = this.websocketClient.connection$.pipe(
tap(event => this.handleDomainEvent(event)),
share()
);
}
Example #6
Source File: settings.service.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 6 votes |
getRecommendedFee(): Observable<string> {
this.settingsStore.updateUIState({ gettingRecommendedFee: true });
return this.stellarSdkService.getRecommendedFee()
.pipe(tap(() => this.settingsStore.updateUIState({ gettingRecommendedFee: false })))
.pipe(catchError(error => {
this.settingsStore.updateUIState({ gettingRecommendedFee: false });
return throwError(error);
}));
}
Example #7
Source File: promo-code-api.service.ts From rubic-app with GNU General Public License v3.0 | 6 votes |
/**
* Validates text promo code.
* @param promoCodeText text to validate.
* @param [autoRevalidateIfAccepted = false] if true and promo code status is accepted, sets interval to refresh promo code data.
* @param [revalidationTimeout = 5000] promo code data refreshing interval.
* @return string promo code with status ('accepted' | 'outdated' | 'wrong' | 'rejected') and additional promo code data.
*/
public validatePromoCode(
promoCodeText: string,
autoRevalidateIfAccepted = false,
revalidationTimeout = PromoCodeApiService.defaultUpdateInterval
): Observable<PromoCode | null> {
return this.getPromoCodeByText(promoCodeText).pipe(
tap(promoCode => {
this.clearInterval();
if (autoRevalidateIfAccepted && promoCode.status === 'accepted') {
this.setInterval(revalidationTimeout);
}
})
);
}
Example #8
Source File: log.interceptor.ts From nestjs-mercurius with MIT License | 6 votes |
intercept(
context: ExecutionContext,
next: CallHandler<any>,
): Observable<any> {
const ctx = GqlExecutionContext.create(context);
this.logger.warn(
`Before - ${ctx.getClass().name}@${ctx.getHandler().name}`,
);
return next
.handle()
.pipe(
tap(() =>
this.logger.warn(
`After - ${ctx.getClass().name}@${ctx.getHandler().name}`,
),
),
);
}
Example #9
Source File: product.service.ts From Angular-ActionStreams with MIT License | 6 votes |
product$ = this.productSelectedAction$
.pipe(
filter(id => !!id),
switchMap(selectedProductId =>
this.http.get<Product>(`${this.productsUrl}/${selectedProductId}`)
.pipe(
tap(response => console.log(JSON.stringify(response))),
map(p => ({ ...p, profit: p.price - p.cost }) as Product),
catchError(this.handleError)
)
));
Example #10
Source File: product-list.component.ts From Angular-HigherOrderMapping with MIT License | 6 votes |
products$ = combineLatest([
this.allProducts$,
this.filterAction$])
.pipe(
// Retain the current filter in a string for binding
tap(([, filter]) => this.listFilter = filter),
// Perform the filtering
map(([products, filter]) => this.performFilter(products, filter)),
);
Example #11
Source File: index.ts From dbm with Apache License 2.0 | 6 votes |
/**
* Write a file, but only if the contents changed
*
* @param file - File
* @param data - File data
*
* @returns File observable
*/
export function write(file: string, data: string): Observable<string> {
let contents = cache.get(file)
if (contents === data) {
return of(file)
} else {
cache.set(file, data)
return defer(() => fs.writeFile(file, data))
.pipe(
mapTo(file),
process.argv.includes("--verbose")
? tap(file => console.log(`${now()} + ${file}`))
: identity
)
}
}
Example #12
Source File: cache-flow.ts From RcloneNg with MIT License | 6 votes |
protected request(pre: CombErr<Tin>): Observable<CombErr<Tout>> {
return iif(
() => this.cacheEnabled() && this.isCached(),
of(this.getCache()),
this.requestCache(pre).pipe(
take(1),
tap(x => {
if (this.cacheEnabled()) this.setCache(x);
})
)
);
}
Example #13
Source File: feature-toggle.directive.ts From canopy with Apache License 2.0 | 6 votes |
ngOnInit(): void {
this.subscription = this.lgFeatureToggleService.toggles$
.pipe(
tap(() => this.viewContainer.clear()),
filter(
(toggles: LgFeatureToggleConfig) =>
(toggles[this.lgFeatureToggle] === undefined && !this.isDefaultHideSet()) ||
toggles[this.lgFeatureToggle],
),
)
.subscribe(() => {
this.viewContainer.createEmbeddedView(this.templateRef);
});
}
Example #14
Source File: coupon.service.ts From mylog14 with GNU General Public License v3.0 | 6 votes |
getLatestBalance() {
const pool$ = this.getPoolCurrentBalance()
.pipe(
first(),
tap(balance => this.poolBalance$.next(balance)),
);
const user$ = this.getUserCurrentBalance()
.pipe(
first(),
tap(balance => this.userBalance$.next(balance)),
);
return forkJoin([pool$, user$]);
}
Example #15
Source File: app.component.ts From Angular-Cookbook with MIT License | 6 votes |
startStream() {
const streamSource = interval(1500).pipe(
map((input) => {
const index = input % this.combinedStreamData.length;
return this.combinedStreamData[index];
})
);
const [moviesStream, cartoonsStream] = partition(
streamSource,
(item) => item.type === 'movie'
);
this.subscription = merge(
moviesStream.pipe(
tap((movie) => {
this.movies.push(movie.title);
})
),
cartoonsStream.pipe(
tap((cartoon) => {
this.cartoons.push(cartoon.title);
})
)
).subscribe((output) => {
console.log(output);
});
}
Example #16
Source File: grocy-api.component.ts From pantry_party with Apache License 2.0 | 6 votes |
ngOnInit(): void {
merge(
this.form.valueChanges,
this.forceCheck
).pipe(
tap(() => this.updateValidationStatus()),
takeUntil(this.ngUnsubscribe),
debounceTime(250),
filter(() => this.form.valid),
tap(() => this.working = true),
switchMap(_ => this.grocyService.getSystemInfo(
this.formControl("url").value,
this.formControl("apiKey").value
).pipe(
map(r => ({result: "success" as "success", resp: r})),
catchError((e: HttpErrorResponse) => of({result: "error" as "error", err: e}))
)),
tap(() => this.working = false)
).subscribe(r => this.renderReturn(r));
if (this.form.valid) {
this.forceCheck.next(true);
}
}
Example #17
Source File: data-studio.service.ts From visualization with MIT License | 6 votes |
constructor(
@Inject(WINDOW) private readonly window: Window,
@Inject(MERMAID) private readonly mermaid: Mermaid,
private readonly alert: AlertService) {
this.initializeMermaid();
const azEvent$ = fromEvent<Event>(this.window, 'message').pipe(
tap(event => {
if (event.data.status === Status.Error) {
this.alert.showError({
status: event.data.status,
errors: event.data.errors,
rawData: JSON.stringify(event.data.rawData)
});
}
})
);
this.status$ = concat(azEvent$.pipe(
map(e => e.data?.status),
));
this.database$ = azEvent$.pipe(
filter(event => event.data?.status === Status.Complete),
map(event => event.data?.chart),
switchMap(r => this.buildSvg(r))
);
this.databaseName$ = azEvent$.pipe(
filter(event => event.data?.status === Status.Complete),
map(event => event.data?.databaseName));
}
Example #18
Source File: keyboard-event-dispatcher.ts From scion-microfrontend-platform with Eclipse Public License 2.0 | 6 votes |
/**
* Applies keystroke flags on each keyboard event emitted by the source Observable.
*
* Note that `preventDefault()` has to be invoked on the original event, which has its `isTrusted` flag set to `true`.
*
* For more information about trusted events
* @see https://www.w3.org/TR/DOM-Level-3-Events/#trusted-events
* @see https://www.chromestatus.com/features#istrusted
*
* @internal
*/
function applyKeystrokeFlags(flags: KeystrokeFlags | undefined): MonoTypeOperatorFunction<KeyboardEvent> {
return tap(keystrokeEvent => {
if (flags?.preventDefault) {
keystrokeEvent.preventDefault();
}
});
}
Example #19
Source File: admin-users.component.ts From App with MIT License | 6 votes |
search(query = ''): Observable<UserStructure[]> {
return this.restService.v2.SearchUsers(query).pipe(
map(res => {
this.total.next(res.total_size);
return this.dataService.add('user', ...res.users);
}),
tap(users => this.users.next(users))
);
}