Ich benutze angular 2 mit redux/store zusammen mit redux-observable, um Epen zu bilden. Was ich machen möchte, ist ein allgemeiner Poller, also muss ich nur einmal einen Poller schreiben. Ich habe etwa 25 Dienste und ich würde eher in welcher Art von Aktionen die Aktion Pass hat, und Dienstleistungen werden es ausführen dann den doppelten Code mit und schrieben großen Fall oder wenn Aussagen:Wie man ein EPIC komplett dynamisch macht
Code ich habe bisher:
startPoller: Epic<Action<void>, Action<void>> = action$ =>
action$.ofType(BankActions.DEPOSIT.POLL_DATA)
.switchMap(action =>
Observable.interval(1000)
.takeUntil(action$.ofType(BankActions.DEPOSIT.STOP_POLLING))
.mergeMap(count =>
this.bankService.getDeposit.(action.payload)
.map(payload => ({ type: BankActions.DEPOSIT.POLL_SUCCESS, payload }))
.catch(error => Observable.of({
type: BankActions.DEPOSIT.POLLING_FAILED,
payload: error
}))
)
)
Was ich will, in Pseudo-Code tun:
startPoller: Epic<Action<void>, Action<void>> = action$ =>
action$.ofType(BankActions.DEPOSIT.POLL_DATA || BankActions.WITHDRAW.POLL_DATA || InvestActions.STOCK_PRICE.POLL_DATA)
.switchMap(action =>
Observable.interval(1000)
.takeUntil(action$.ofType(action.STOP_POLLING))
.mergeMap(count =>
this.bankService.getDeposit(action.payload)
.map(payload => ({ type: BankActions.DEPOSIT.POLL_SUCCESS, payload }))
.catch(error => Observable.of({
type: BankActions.DEPOSIT.POLLING_FAILED,
payload: error
}))
)
)
ich vermute, es zu haben, arbeiten muss ich könnte irgendeine Art von Basistyp machen, dass jede Aktion/Service, den Bedarf zu abzufragen braucht würde verlängern dann könnte ich einfach prüfen, ob ifs vom Typ 'PollerService' oder 'PollerEpic' eingeben d dann kann ich das filtern?