Skip to content

Commit

Permalink
First step towards storing plans in state.
Browse files Browse the repository at this point in the history
  • Loading branch information
chmac committed May 27, 2020
1 parent 1d2af37 commit a09c00b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/plans/src/services/plans/plans.state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { Plan } from './plans.service';

type PlansState = {
plans: {
[slug: string]: Plan;
};
};

const initialState: PlansState = {
plans: {},
};

const plansSlice = createSlice({
name: 'PLANS/plans',
initialState,
reducers: {
remove: (state, action: PayloadAction<{ slug: string }>) => {
delete state.plans[action.payload.slug];
},
upsert: (state, action: PayloadAction<{ plan: Plan }>) => {
state.plans[action.payload.plan.slug] = action.payload.plan;
},
},
});

const { reducer, actions } = plansSlice;

export const { remove, upsert } = actions;
export default reducer;
2 changes: 2 additions & 0 deletions packages/plans/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import {
import devToolsEnhancer from 'remote-redux-devtools';

import storage from './services/storage/storage.service';
import plans from './services/plans/plans.state';

const REDUX_ROOT_KEY = '__plans' as const;

const reducer = combineReducers({
storage,
plans,
});

export const store = configureStore({
Expand Down

0 comments on commit a09c00b

Please sign in to comment.