browser-extension-kit
browser-extension-kit copied to clipboard
感觉是挺好的项目,必须会 rxjs 才能用吗?
没写过 angular,感觉 rxjs 挺难的,现在有个场景,两个数据源 subject 都是 array,现在我直接想把两个 array 放一起变成只有一层的 array,数据源变化就更新再放一起
export default class MyBackground extends Background {
@subject('MyBackground::localStorage')
private storageSubject = new Subject<[string, string][]>()
@subject('MyBackground::cookies')
private cookieSubject = new Subject<[string, string][]>()
@observable(['popup', 'contentScript'])
private combinator = this.storageSubject.pipe(
combineLatestWith(this.cookieSubject),
)
}
看了好几天 rxjs,拿到的数据结构是 [[string, string][], undefined],总是嵌套着数组
请问如果 combinator
只要 [string, string][] 的结构应该是咋写
方法有很多,不确定你要如何 merge 2 个 array,以下是个例子
private combinator: Observable<[string, string][]> = combineLatest([
this.storageSubject,
this.cookieSubject
]).pipe(
map(([storage, cookie]) => {
return [...storage, ...cookie]
})
)