Created
April 5, 2021 13:49
-
-
Save jcampuza/be032d511aba26b3a8b6eef1063bc3db to your computer and use it in GitHub Desktop.
Combine Latest that functions with a keyed object
This file contains hidden or 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
const combineLatestObj = <T>( | |
obj: T, | |
): Observable<{ [K in keyof T]: ObservedValueOf<T[K]> }> => { | |
const keys = Object.keys(obj); | |
const values = Object.values(obj); | |
return combineLatest(values).pipe( | |
map( | |
(observedValues) => | |
keys.reduce((result, key, i) => { | |
(result as any)[key] = observedValues[i]; | |
return result; | |
}, {}) as { | |
[K in keyof T]: ObservedValueOf<T[K]>; | |
}, | |
), | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment