我正在尝试创建一个下载资产列表的主题,该列表为每个资产发送操作,如果可能的话,使用主题的主题?
export function onDownloadGuide(action$,store){
return action$.ofType(DOWNLOAD_GUIDE)
.mergeMap(() => downloadGuideAssets().map(res => downloadGuideAssetProgress(res)))
}
function downloadGuideAssets(){
const subject$ = new Subject()
getAssetList().map((asset) => downloadAsset(asset).map(res => {console.log(res);subject$.next(res)}))
return subject$.asObservable()
}
function downloadAsset({id,src}){
const subject$ = new Subject()
window.resolveLocalFileSystemURL(cordova.file.dataDirectory, dirEntry => {
dirEntry.getFile(src.substring(src.lastIndexOf('/')+1),{create:true, exclusive:true}, f => {
fetch(src).then(fetchProgress({onProgress(progress) {console.log('progressevent');subject$.next({id,progress})}}))
.then(res => res.blob())
.then(blob =>
f.createWriter(writer => {
writer.onwriteend = ()=> subject$.next({id,complete:true})
writer.write(blob)
}))
.catch(err => subject$.next({id,error:err}))
}, err => subject$.next({id,error:err}) )
})
return subject$.asObservable()
}
这些文件似乎正在下载等。我可以控制台记录进度 - 当我尝试映射结果时,什么都没有被触发。
这是因为我是从订阅开始的吗?