javascript 等待合并映射的Observable
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 等待合并映射的Observable相关的知识,希望对你有一定的参考价值。
const ofPermissionType = (
requiredPermissionType,
) => (
filter(({ permissionType }) => (
requiredPermissionType === permissionType
))
)
const fetchPermissionsEpic = (
action$,
state$,
{ ajax },
) => (
action$
.pipe(
ofType(FETCH_PERMISSIONS),
map(props => ({
...props,
accessToken: (
accessTokenSelector(
state$.value,
)
),
})),
mergeMap(({
accessToken,
permissionTypes,
}) => (
from(permissionTypes)
.pipe(
map(permissionType => (
of(permissionType)
.pipe(
takeUntil(
action$
.pipe(
ofType(FETCH_PERMISSIONS),
switchMap(({ permissionTypes }) => (
permissionTypes
)),
ofPermissionType(permissionType),
)
),
switchMap(() => (
ajax({
crossDomain: true,
headers: {
'Authorization': `Bearer ${accessToken}`,
},
url: (
'https://example.com/permissions'
.concat('?')
.concat('permissionType=')
.concat(permissionType)
),
})
.pipe(
pluck('response'),
map(permissionValue => ({
permissionType,
permissionValue,
})),
map(storePermission),
)
)),
)
)),
mergeAll(2),
concat(
of(finishedStoringPermissions())
),
)
)),
)
)
以上是关于javascript 等待合并映射的Observable的主要内容,如果未能解决你的问题,请参考以下文章
javascript 结合合并映射的可观测值的值
rxjs5合并和错误处理
将JavaScript压缩代码映射到源码
Offical Tutorial
如何等待此功能完成?
在映射下一项之前,异步等待映射不等待异步函数在映射函数内部完成