While working on using Epics with the Redux library in Angular 4, I delved into the index.d.ts
file for this library and discovered the following:
export declare interface Epic<T, S> {
(action$: ActionsObservable<T>, store: MiddlewareAPI<S>): Observable<T>;
}
I'm trying to understand the meaning of this syntax. The interface appears to define a function type that takes two parameters — an ActionsObservable<T>
and a MiddlewareAPI<S>
— and returns an Observable<T>
.
If my assumption is correct, why is it defined as an interface?
Although I am currently using this interface based on another developer's template, I am intrigued by its significance. An example of how it is used can be seen here:
getStuff(): Epic<IAction, IAppState> {
return (action$, store): any => action$
.ofType(actions.SOME_ACTION)
.mergeMap((_) => {
return this.apiService.get(`some/api/call/`)
.map((result) => {
return actions.someActionSuccess({data: result});
});
});
}
This sample code aligns with my interpretation as getStuff()
is indeed returning a function with the same signature. However, I want a better understanding rather than just making assumptions!