Created
September 9, 2019 16:56
-
-
Save studioTeaTwo/f23f7bfed249ffa168330d48ec271a3a to your computer and use it in GitHub Desktop.
return immediately if source response empty array. otherwise adding some rx functions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// return immediately empty if source response empty array. | |
// otherwise adding some functions. | |
const Emptialbe = <T>(source: Observable<T[]>, additional: Observable<T[]>) => { | |
source.pipe( | |
switchMap(array => { | |
if (array.length === 0) { | |
return of(array) | |
} else { | |
return additional(array) | |
} | |
}) | |
) | |
} | |
// example | |
const someApiResponse$ = someApi(); | |
const anotherApiResponse$ = anotherApi(); | |
Emptialbe<string>(apiResponse$, (array) => forkJoin(of(array), anotherApiResponse$) | |
.pipe( | |
map([someApiResponse, anotherApiResponse] => { | |
return mappedValue; | |
}) | |
) | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment