Currently, I have a code snippet that pulls data from a web service:
@Effect()
searchAction$ : Observable<Action> = this._actions$
.ofType(ActionTypes.SEARCH_CASES)
.do(val => this._store.dispatch(new SetLoadingAction(true)))
.map(action => action.payload) // only interested in the payload
.map(payload => new CaseSearchCriteria(payload)) // create search criteria
.switchMap(payload => this._httpSearchCases.searchDiseaseCases(payload)
/*
1. The return from httpCall is IDiseaseControlCaseManagement[]
2. Transform this array into SearchDiseaseCaseResults[]
*/
.do((val) => {
console.log('Type of Value: ', typeof val);
console.log('Is value SearchDiseaseCaseResult? :', val instanceof SearchDiseaseCaseResults);
})
.map(res => new LoadSearchResultsAction(res))
);
I have included comments to briefly explain the desired functionality, and while I am certain there is a ReactiveX operator that can achieve this, I have been unable to identify it.
I attempted to use the .scan
operator by pushing to the accumulator:
.scan((acc: SearchDiseaseCaseResults[], val: IDiseaseControlCaseManagement) => {
acc.push(new SearchDiseaseCaseResults(val));
})
However, TypeScript static analysis indicates that this approach is incorrect:
Error:(32, 31) TS2453:The type argument for type parameter 'R' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'SearchDiseaseCaseResults[]' is not a valid type argument because it is not a supertype of candidate 'void'.
Therefore, I require an operator chain (or method) that will enable me either to:
- Receive an emission of type ObjectA.
- Transform the emission of type ObjectA into an object of type ObjectB.
- Receive emissions of type ObjectB.
- Combine each emission of ObjectB into a single array ObjectB[].
or
- Receive an emission of type ObjectA[].
- Transform the emission of type ObjectA[] into an array of type ObjectB[].