Skip to content

Instantly share code, notes, and snippets.

@killan
Created December 17, 2023 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save killan/1af35301b40ce8c2939ad06c85aab9ca to your computer and use it in GitHub Desktop.
Save killan/1af35301b40ce8c2939ad06c85aab9ca to your computer and use it in GitHub Desktop.
Custom RxJs Pipe Object to Array
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