Skip to content

Commit 17e491f

Browse files
committed
Created helper function folder for creating history and removed focus component function invocation upon switching class/state
1 parent 3e390e5 commit 17e491f

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

src/components/LeftColExpansionPanel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
144144
checked={stateful}
145145
onChange={e => {
146146
toggleComponentState(id);
147-
changeFocusComponent({ title });
147+
// changeFocusComponent({ title });
148148
}}
149149
value='stateful'
150150
color='primary'
@@ -168,7 +168,7 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
168168
checked={classBased}
169169
onChange={e => {
170170
toggleComponentClass(id);
171-
changeFocusComponent({ title });
171+
// changeFocusComponent({ title });
172172
}}
173173
value='classBased'
174174
color='primary'

src/utils/componentReducer.util.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ComponentsInt,
1111
PropInt
1212
} from './Interfaces';
13+
import { createHistory } from './helperFunctions'
1314

1415
//this is the default values for any component added to the app.
1516

@@ -32,25 +33,6 @@ const initialComponentState: ComponentInt = {
3233
focusChildId: 0
3334
};
3435

35-
/*Helper function that copies the state to be added on to the history
36-
By clearing the history data out of each stored step of the timeline,
37-
you can avoid repetitive nesting that maxes out the memory allocated to electron
38-
(usually happens at around 7-10 steps without using this method)*/
39-
const createHistory = (state: ApplicationStateInt) => {
40-
const stateCopy = cloneDeep(state);
41-
const historyCopy = cloneDeep(state.history);
42-
historyCopy.push({ ...stateCopy, history: [] });
43-
const history = historyCopy;
44-
const historyIndex = state.historyIndex + 1;
45-
const future: [] = [];
46-
47-
return {
48-
history,
49-
historyIndex,
50-
future
51-
};
52-
};
53-
5436
export const addComponent = (
5537
state: ApplicationStateInt,
5638
{ title }: { title: string }

src/utils/helperFunctions.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { ApplicationStateInt } from './Interfaces';
2+
import cloneDeep from './cloneDeep';
3+
4+
/*Helper function that copies the state to be added on to the history
5+
By clearing the history data out of each stored step of the timeline,
6+
you can avoid repetitive nesting that maxes out the memory allocated to electron
7+
(usually happens at around 7-10 steps without using this method)*/
8+
export const createHistory = (state: ApplicationStateInt) => {
9+
const stateCopy = cloneDeep(state);
10+
const historyCopy = cloneDeep(state.history);
11+
historyCopy.push({ ...stateCopy, history: [] });
12+
const history = historyCopy;
13+
const historyIndex = state.historyIndex + 1;
14+
const future: [] = [];
15+
16+
return {
17+
history,
18+
historyIndex,
19+
future,
20+
};
21+
};

0 commit comments

Comments
 (0)