Wire in redux-observables and add basic epic
This commit is contained in:
10
src/state/actions.ts
Normal file
10
src/state/actions.ts
Normal 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
7
src/state/epics.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { combineEpics } from 'redux-observable';
|
||||
|
||||
import { epics as workloadsEpics } from './workloads';
|
||||
|
||||
export const epics = combineEpics(workloadsEpics);
|
||||
|
||||
export default epics;
|
||||
@@ -1 +1,3 @@
|
||||
export * from './reducers';
|
||||
export * from './reducers';
|
||||
export * from './actions';
|
||||
export * from './epics';
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
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