Created
December 17, 2023 22:43
-
-
Save killan/1af35301b40ce8c2939ad06c85aab9ca to your computer and use it in GitHub Desktop.
Custom RxJs Pipe Object to Array
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
export function MapElementMapperPipe<T>(source: Observable<T>): Observable<MapElement[]> { | |
return new Observable<MapElement[]>(subscriber => { | |
return source.subscribe({ | |
next(value) { | |
const mapElements: MapElement[] = [] | |
Object.keys(value as Object).forEach((type) => { | |
mapElements.push({ | |
name: type, | |
items: (value as any)[type], | |
open: false | |
}); | |
}); | |
subscriber.next(mapElements) | |
}, | |
error(err) { | |
subscriber.error(err) | |
}, | |
complete() { | |
subscriber.complete() | |
} | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment