Wire in redux-observables and add basic epic

This commit is contained in:
James Greenaway
2019-01-30 16:01:37 +00:00
parent d03859c220
commit 94423c408a
10 changed files with 87 additions and 21 deletions

10
src/state/actions.ts Normal file
View File

@@ -0,0 +1,10 @@
import * as WorkloadsActions from './workloads/actions';
import { Action as WorkloadsAction } from './workloads/actions';
export type Action = WorkloadsAction;
export const Actions = {
WorkloadsActions,
};
export default Actions;

7
src/state/epics.ts Normal file
View File

@@ -0,0 +1,7 @@
import { combineEpics } from 'redux-observable';
import { epics as workloadsEpics } from './workloads';
export const epics = combineEpics(workloadsEpics);
export default epics;

View File

@@ -1 +1,3 @@
export * from './reducers';
export * from './reducers';
export * from './actions';
export * from './epics';

View File

@@ -1,18 +1,17 @@
import { combineReducers } from 'redux';
import { Action } from './actions';
import {
Store as WorkloadsStore,
Action as WorkloadActions,
State as WorkloadsState,
reducer as workloadReducer,
} from './workloads';
export type Action = WorkloadActions;
export interface Store {
workloads: WorkloadsStore;
export interface State {
workloads: WorkloadsState;
}
export const reducers = combineReducers<Store, Action>({
export const reducers = combineReducers<State, Action>({
workloads: workloadReducer,
});

View 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;

View File

@@ -1,3 +1,4 @@
export * from './actions';
export * from './reducers';
export * from './epics';
export * from './services';

View File

@@ -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 {