Wire in redux-observables and add basic epic
This commit is contained in:
25
src/state/workloads/epics.ts
Normal file
25
src/state/workloads/epics.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { combineEpics, Epic, ofType } from 'redux-observable';
|
||||
import { map, tap, ignoreElements } from 'rxjs/operators';
|
||||
|
||||
import { Action } from '../actions';
|
||||
import { State } from '../reducers';
|
||||
|
||||
|
||||
type AppEpic = Epic<Action, Action, State>;
|
||||
|
||||
|
||||
const logWorkloadSubmissions: AppEpic = (action$, state$) => (
|
||||
action$.pipe(
|
||||
ofType('WORKLOAD_SUBMIT'),
|
||||
map(action => action.payload),
|
||||
tap((payload) => console.log('Workload submitted', payload)),
|
||||
ignoreElements(),
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
export const epics = combineEpics(
|
||||
logWorkloadSubmissions,
|
||||
);
|
||||
|
||||
export default epics;
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './actions';
|
||||
export * from './reducers';
|
||||
export * from './epics';
|
||||
export * from './services';
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { Action } from './actions';
|
||||
import { Status } from './types';
|
||||
|
||||
interface Entry<id extends number> {
|
||||
id: id;
|
||||
interface Entry<Id extends number> {
|
||||
id: Id;
|
||||
completeDate: Date;
|
||||
status: Status;
|
||||
}
|
||||
|
||||
export type Store = {
|
||||
[id in number]: Entry<id>;
|
||||
export type State = {
|
||||
[Id in number]: Entry<Id>;
|
||||
};
|
||||
|
||||
|
||||
const initialState: Store = {};
|
||||
const initialState: State = {};
|
||||
|
||||
export const reducer = (state: Store = initialState, action: Action): Store => {
|
||||
export const reducer = (state: State = initialState, action: Action): State => {
|
||||
switch (action.type) {
|
||||
case 'WORKLOAD_CREATED':
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user