Skip to content

Commit

Permalink
Strict typing for middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
peluja1012 committed Jan 24, 2020
1 parent 62d158b commit 03e374f
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Middleware, Dispatch } from 'redux';
import { Dispatch, MiddlewareAPI } from 'redux';
import { CoreStart } from 'kibana/public';
import { AlertData } from '../../../../../endpoint_app_types';
import { GlobalState } from '../reducer';
import { AppAction } from '../action';

export const alertMiddlewareFactory: (
// TODO, move this somewhere
type MiddlewareFactory = (
coreStart: CoreStart
) => Middleware<{}, GlobalState, Dispatch<AppAction>> = coreStart => {
return store => next => async action => {
) => (
api: MiddlewareAPI<Dispatch<AppAction>, GlobalState>
) => (next: Dispatch<AppAction>) => (action: AppAction) => unknown;

export const alertMiddlewareFactory: MiddlewareFactory = coreStart => {
return store => next => async (action: AppAction) => {
next(action);
if (action.type === 'userNavigatedToPage' && action.payload === 'alertsPage') {
const response: AlertData[] = await coreStart.http.get('/api/endpoint/alerts');
Expand Down

0 comments on commit 03e374f

Please sign in to comment.