本文整理汇总了TypeScript中rxjs/operators.exhaustMap函数的典型用法代码示例。如果您正苦于以下问题:TypeScript exhaustMap函数的具体用法?TypeScript exhaustMap怎么用?TypeScript exhaustMap使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exhaustMap函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: map
> => (action$, state$, { selectLogFilterQueryAsJson, selectVisibleLogSummary }) => {
const filterQuery$ = state$.pipe(map(selectLogFilterQueryAsJson));
const summaryInterval$ = state$.pipe(
map(selectVisibleLogSummary),
map(({ start, end }) => (start && end ? getLoadParameters(start, end) : null)),
filter(isNotNull)
);
const shouldLoadBetweenNewInterval$ = action$.pipe(
filter(logPositionActions.reportVisibleSummary.match),
filter(
({ payload: { bucketsOnPage, pagesBeforeStart, pagesAfterEnd } }) =>
bucketsOnPage < MINIMUM_BUCKETS_PER_PAGE ||
pagesBeforeStart < MINIMUM_BUFFER_PAGES ||
pagesAfterEnd < MINIMUM_BUFFER_PAGES
),
map(({ payload: { start, end } }) => getLoadParameters(start, end))
);
const shouldLoadWithNewFilter$ = action$.pipe(
filter(logFilterActions.applyLogFilterQuery.match),
withLatestFrom(filterQuery$, (filterQuery, filterQueryString) => filterQueryString)
);
return merge(
shouldLoadBetweenNewInterval$.pipe(
withLatestFrom(filterQuery$),
exhaustMap(([{ start, end, bucketSize }, filterQuery]) => [
loadSummary({
start,
end,
sourceId: 'default',
bucketSize,
filterQuery,
}),
])
),
shouldLoadWithNewFilter$.pipe(
withLatestFrom(summaryInterval$),
exhaustMap(([filterQuery, { start, end, bucketSize }]) => [
loadSummary({
start,
end,
sourceId: 'default',
bucketSize: (end - start) / LOAD_BUCKETS_PER_PAGE,
filterQuery,
}),
])
)
);
};
示例2: exhaustMap2
exhaustMap2() {
const firstInterval = interval(1000).pipe(take(10));
const secondInterval = interval(1000).pipe(take(2));
const exhaustSub = firstInterval
.pipe(
exhaustMap(f => {
console.log(`Emission Corrected of first interval: ${f}`);
return secondInterval;
})
)
/*
When we subscribed to the first interval, it starts to emit a values (starting 0).
This value is mapped to the second interval which then begins to emit (starting 0).
While the second interval is active, values from the first interval are ignored.
We can see this when firstInterval emits number 3,6, and so on...
Output:
Emission of first interval: 0
0
1
Emission of first interval: 3
0
1
Emission of first interval: 6
0
1
Emission of first interval: 9
0
1
*/
.subscribe(s => console.log(s));
}
示例3: map
> => (
action$,
state$,
{ selectMetricTimeUpdatePolicyInterval, selectMetricRangeFromTimeRange }
) => {
const updateInterval$ = state$.pipe(
map(selectMetricTimeUpdatePolicyInterval),
filter(isNotNull)
);
const range$ = state$.pipe(
map(selectMetricRangeFromTimeRange),
filter(isNotNull)
);
return action$.pipe(
filter(startMetricsAutoReload.match),
withLatestFrom(updateInterval$, range$),
exhaustMap(([action, updateInterval, range]) =>
timer(0, updateInterval).pipe(
map(() =>
setRangeTime({
from: moment()
.subtract(range, 'ms')
.valueOf(),
to: moment().valueOf(),
interval: '1m',
})
),
takeUntil(action$.pipe(filter(stopMetricsAutoReload.match)))
)
)
);
};
示例4: it
it('should not break unsubscription chains when result is unsubscribed explicitly', () => {
const x = cold( '--a--b--c--| ');
const xsubs = ' ^ ! ';
const y = cold( '--d--e--f--| ');
const ysubs: string[] = [];
const z = cold( '--g--h--i--| ');
const zsubs = ' ^ ! ';
const e1 = hot('---x---------y-----------------z-------------|');
const e1subs = '^ ! ';
const expected = '-----a--b--c---------------------g- ';
const unsub = ' ! ';
const observableLookup = { x: x, y: y, z: z };
const result = e1.pipe(
mergeMap(x => of(x)),
exhaustMap(value => observableLookup[value]),
mergeMap(x => of(x))
);
expectObservable(result, unsub).toBe(expected);
expectSubscriptions(x.subscriptions).toBe(xsubs);
expectSubscriptions(y.subscriptions).toBe(ysubs);
expectSubscriptions(z.subscriptions).toBe(zsubs);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
示例5: exhaustMap1
exhaustMap1() {
const sourceInterval = interval(1000);
const delayedInterval = sourceInterval.pipe(delay(10), take(4));
const exhaustSub = merge(
// delay 10ms, then start interval emitting 4 values
delayedInterval,
// emit immediately
of(true)
)
.pipe(exhaustMap(_ => sourceInterval.pipe(take(5))))
/*
* The first emitted value (of(true)) will be mapped
* to an interval observable emitting 1 value every
* second, completing after 5.
* Because the emissions from the delayed interval
* fall while this observable is still active they will be ignored.
*
* Contrast this with concatMap which would queue,
* switchMap which would switch to a new inner observable each emission,
* and mergeMap which would maintain a new subscription for each emitted value.
*/
// output: 0, 1, 2, 3, 4
.subscribe(val => console.log(val));
}
示例6: filter
export const createLogPositionEpic = <State>(): Epic<Action, Action, State, {}> => action$ =>
action$.pipe(
filter(startAutoReload.match),
exhaustMap(({ payload }) =>
timer(0, payload).pipe(
map(() => jumpToTargetPositionTime(Date.now())),
takeUntil(action$.pipe(filter(stopAutoReload.match)))
)
)
);
示例7: hot
('should map-and-flatten each item to an Observable', () => {
const e1 = hot('--1-----3--5-------|');
const e1subs = '^ !';
const e2 = cold('x-x-x| ', {x: 10});
const expected = '--x-x-x-y-y-y------|';
const values = {x: 10, y: 30, z: 50};
const result = e1.pipe(exhaustMap(x => e2.map(i => i * +x)));
expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});