I'm trying to create a service that can dynamically filter a stream of Record<string, unkonwn> by it's keys. The idea is I can call like an "addFilter" on the service and pass an observable with a filter which is then stored in an array of observables in the service. Then when the observable of Records notifies in the service, it should enumerate all of the filtered observables in the array and remove them from the stream.
I'm probably WAY off base here, but this is where I am at right now, just creating the actual chain of filters.
chainFilters(filters: Observable<Record<string, unknown>>[]) {
return (source$: Observable<Record<string, unknown>>) => {
var observables = filters.reduce(
(
acc: Observable<Record<string, unknown>>[],
value: Observable<Record<string, unknown>>
) => {
return acc.concat(value);
}, []);
return source$.pipe(???);
}
}
I thought about returning concat(observables) in this case but it says concat is deprecated. No clue where to go from here.
The best example I could find of something remotely similar is here but that doesn't work with RxJS in angular, I'm a little confused about how to translate that.
EDIT: Project is using RxJS 6.5.5
At the request of @maxime1992, am going to try to explain the problem a little more to help with understanding...
So I have a stream of Record<string, unknown> coming from a dynamic array of form fields, form groups, and form arrays, all generated with JSONSchema using Formly that combine to build a multi step wizard of sorts. That in and of itself is not important to except to say that the forms themselves cannot be changed, they just emit the Record<string, unknown> objects. Nested form groups may emit records that contain multiple child "Records."
The problem comes in that although most of those "Records" are valid against the original JSON schema from the db, others are added virtually based on a json config that is merged with the schema before generating the form. Those wont validate against the json schema in the database, and need to get 'plucked' (for lack of a better word), OUT of of the stream before the remainder of the stream is sent to the server to save. So basically there would be ONE subscriber for each plucked record, which would be a separate service that would inject the main service where the stream is coming from, and call an "addFilter" function on that service, with a filter defined by the subscriber. This would put a filter into the array of filters on the main service. Each filter removes the record being filtered from the main stream to used by the subscribing service, and lets the others go through unimpeded.
I am not needing to know how to do all the services, I just am having trouble figuring out how to structure the filter, in a way that can be chained via the array of filters, to remove those records from the main stream.
I hope that helps describe the problem a little more...