本文整理汇总了TypeScript中rxjs.zip函数的典型用法代码示例。如果您正苦于以下问题:TypeScript zip函数的具体用法?TypeScript zip怎么用?TypeScript zip使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zip函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: updateUserSettings
updateUserSettings(username: string, name: string, email: string, profilePicture?: FormData): Observable<any> {
const body = { name, email };
if (profilePicture) {
return zip(
this.http.put(`${environment.URL}/user/${username}`, body),
this.http.post(`${environment.URL}/user/${username}`, profilePicture),
(r1, r2) => r2
);
} else {
return zip(
this.http.put(`${environment.URL}/user/${username}`, body)
);
}
}
示例2: getWords
private getWords(titles: string[], locale: Locale, source: SearchResultsSource, progressObserver?: Observer<number>) {
let progress = 0;
let rateLimitingDelay = 0;
const getWords = titles.map(title => {
const getWord = of(null).pipe(
delay(rateLimitingDelay), // Adding delay for rate limiting to prevent HTTP error 429 from backend.
mergeMap(_ => this.getWordByLoadingSearchResults(title, locale, source)),
finalize(() => {
if (progressObserver) {
progress++;
progressObserver.next(progress);
}
})
);
rateLimitingDelay += 1000;
return getWord;
});
return zip(...getWords).pipe(
finalize(() => {
if (progressObserver) {
progressObserver.complete();
}
})
);
}
示例3: it
it('should support mixed observables and promises', () => {
const a = Promise.resolve(1); // $ExpectType Promise<number>
const b = of('foo'); // $ExpectType Observable<string>
const c = of(true); // $ExpectType Observable<boolean>
const d = of(['bar']); // $ExpectType Observable<string[]>
const o1 = zip(a, b, c, d); // $ExpectType Observable<[number, string, boolean, string[]]>
});
示例4: zip2
zip2() {
// emit every 1s
const source = interval(1000);
// when one observable completes no more values will be emitted
const example = zip(source, source.pipe(take(2)));
// output: [0,0]...[1,1]
const subscribe = example.subscribe(val => console.log(val));
}
示例5: Image
(() => {
const alertImg = new Image();
alertImg.src = ServerMapTheme.general.common.funcServerMapImagePath(ServerMapTheme.general.common.icon.error);
return zip(
serviceTypeImgLoadEvent$.pipe(pluck('target')),
fromEvent(alertImg, 'load').pipe(pluck('target'))
);
})(),
示例6: sample2
sample2() {
const source = zip(
// emit 'Joe', 'Frank' and 'Bob' in sequence
from(['Joe', 'Frank', 'Bob']),
// emit value every 2s
interval(2000)
);
// sample last emitted value from source every 2.5s
const example = source.pipe(sample(interval(2500)));
// output: ["Joe", 0]...["Frank", 1]...........
const subscribe = example.subscribe(val => console.log(val));
}
示例7: switchMap
switchMap(info => {
const resolveBaseCommitID = resolveDiffRev({
repoPath: info.baseRepoPath,
differentialID: info.differentialID,
diffID: (info.leftDiffID || info.diffID)!,
leftDiffID: info.leftDiffID,
useDiffForBase: Boolean(info.leftDiffID), // if ?vs and base is not `on` i.e. the initial commit)
useBaseForDiff: false,
filePath: info.baseFilePath || info.filePath,
isBase: true,
}).pipe(
map(({ commitID, stagingRepoPath }) => ({
baseCommitID: commitID,
baseRepoPath: stagingRepoPath || info.baseRepoPath,
})),
catchError(err => {
throw err
})
)
const resolveHeadCommitID = resolveDiffRev({
repoPath: info.headRepoPath,
differentialID: info.differentialID,
diffID: info.diffID!,
leftDiffID: info.leftDiffID,
useDiffForBase: false,
useBaseForDiff: false,
filePath: info.filePath,
isBase: false,
}).pipe(
map(({ commitID, stagingRepoPath }) => ({
headCommitID: commitID,
headRepoPath: stagingRepoPath || info.headRepoPath,
})),
catchError(err => {
throw err
})
)
return zip(resolveBaseCommitID, resolveHeadCommitID).pipe(
map(([{ baseCommitID, baseRepoPath }, { headCommitID, headRepoPath }]) => ({
baseCommitID,
headCommitID,
...info,
baseRepoPath,
headRepoPath,
}))
)
}),
示例8: zip1
zip1() {
const sourceOne = of('Hello');
const sourceTwo = of('World!');
const sourceThree = of('Goodbye');
const sourceFour = of('World!');
// wait until all observables have emitted a value then emit all as an array
const example = zip(
sourceOne,
sourceTwo.pipe(delay(1000)),
sourceThree.pipe(delay(2000)),
sourceFour.pipe(delay(3000))
);
// output: ["Hello", "World!", "Goodbye", "World!"]
const subscribe = example.subscribe(val => console.log(val));
}
示例9: stateFn
export function stateFn(initState: AppState, actions: Observable<Action>): Observable<AppState> {
const combine = s => ({
hero: s[0],
currentTask: s[1],
hasActiveTask: s[2],
activeTaskMode: s[3],
});
const appStateObs: Observable<AppState> =
zip(
hero(initState.hero, actions),
currentTask(initState.currentTask, actions),
hasActiveTask(initState.hasActiveTask, actions),
activeTaskMode(initState.activeTaskMode, actions),
).pipe(
map(combine),
);
return wrapIntoBehavior(initState, appStateObs);
}