Skip to content

Commit

Permalink
fix(suite): remove immer with Object.freeze from guideReducer as it c…
Browse files Browse the repository at this point in the history
…ontains 'react' structure
  • Loading branch information
vojtatranta committed Feb 24, 2025
1 parent ab425aa commit 960bf1b
Showing 1 changed file with 38 additions and 28 deletions.
66 changes: 38 additions & 28 deletions packages/suite/src/reducers/suite/guideReducer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import produce from 'immer';

import type { ActiveView, GuideCategory, GuideNode } from '@suite-common/suite-types';
import * as indexNodeJSON from '@trezor/suite-data/files/guide/index.json';

Expand All @@ -22,31 +20,43 @@ export const initialState: State = {
currentNode: null,
};

const guideReducer = (state: State = initialState, action: Action): State =>
produce(state, draft => {
switch (action.type) {
case GUIDE.OPEN:
draft.open = true;
break;
case GUIDE.CLOSE:
draft.open = false;
draft.view = 'GUIDE_DEFAULT';
break;
case GUIDE.SET_VIEW:
draft.view = action.payload;
break;
case GUIDE.SET_INDEX_NODE:
draft.indexNode = action.payload;
break;
case GUIDE.UNSET_NODE:
draft.currentNode = null;
break;
case GUIDE.OPEN_NODE:
draft.currentNode = action.payload;
break;
default:
return state;
}
});
// NOTE: we cannot use immer in this reducer, because GuideCategory mimics the react node and immer uses Object.freeze()
const guideReducer = (state: State = initialState, action: Action): State => {
switch (action.type) {
case GUIDE.OPEN:
return {
...state,
open: true,
};
case GUIDE.CLOSE:
return {
...state,
open: false,
view: 'GUIDE_DEFAULT',
};
case GUIDE.SET_VIEW:
return {
...state,
view: action.payload,
};
case GUIDE.SET_INDEX_NODE:
return {
...state,
indexNode: action.payload,
};
case GUIDE.UNSET_NODE:
return {
...state,
currentNode: null,
};
case GUIDE.OPEN_NODE:
return {
...state,
currentNode: action.payload,
};
default:
return state;
}
};

export default guideReducer;

0 comments on commit 960bf1b

Please sign in to comment.