export type BeforeFilter = ( requestUrl : string , options : RequestInit ) => void ; export type AfterFilter = ( response : Response , json : JSON ) => void ; export class MiddlewareStack { private _beforeFilters : BeforeFilter [ ] = [ ] ; private _afterFilters : AfterFilter [ ] = [ ] ; constructor ( before = [ ] , after = [ ] ) { this . _beforeFilters = before ; this . _afterFilters = after ; } get beforeFilters ( ) { return this . _beforeFilters ; } get afterFilters ( ) { return this . _afterFilters ; } beforeFetch ( requestUrl , options ) { this . _beforeFilters . forEach ( filter => { filter ( requestUrl , options ) ; } ) ; } afterFetch ( response , json ) { this . _afterFilters . forEach ( filter => { filter ( response , json ) ; } ) ; } }