Skip to content

Commit c43bdc8

Browse files
small reducer changes
1 parent a4decf2 commit c43bdc8

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/utils/componentReducer.util.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ export const changeFocusComponent = (state, { title = state.focusComponent.title
383383
);
384384
}
385385

386-
// if no docus child found .. reset
387386
if (!newFocusChild) {
388387
newFocusChild = cloneDeep(state.initialApplicationFocusChild);
389388
}
@@ -400,9 +399,6 @@ export const changeFocusComponent = (state, { title = state.focusComponent.title
400399
};
401400

402401
export const changeFocusChild = (state, { title, childId }) => {
403-
// just finds first child with given title, need to pass in specific childId somehow
404-
// maybe default to title if childId is unknown
405-
console.log('change foc comp reducer: childId: ', childId);
406402
const focComp = state.components.find(comp => comp.title === state.focusComponent.title);
407403
let newFocusChild = focComp.childrenArray.find(child => child.childId === childId);
408404

@@ -430,11 +426,12 @@ export const changeFocusChild = (state, { title, childId }) => {
430426

431427
export const changeComponentFocusChild = (state, { componentId, childId }) => {
432428
const component = state.components.find(comp => comp.id === componentId);
433-
component.focusChildId = childId;
429+
const modifiedComponent = cloneDeep(component);
430+
modifiedComponent.focusChildId = childId;
434431
const components = state.components.filter(comp => comp.id !== componentId);
435432
return {
436433
...state,
437-
components: [component, ...components],
434+
components: [modifiedComponent, ...components],
438435
};
439436
};
440437

@@ -615,7 +612,7 @@ export const addProp = (state, {
615612
nextPropId: selectedComponent.nextPropId + 1,
616613
};
617614

618-
const newComponents = state.components.filter(comp => comp.id != selectedComponent.id);
615+
const newComponents = state.components.filter(comp => comp.id !== selectedComponent.id);
619616
newComponents.push(modifiedComponent);
620617
return {
621618
...state,
@@ -625,18 +622,17 @@ export const addProp = (state, {
625622
};
626623

627624
export const deleteProp = (state, propId) => {
628-
console.log(`Hello. Delete prop talking. propId:${propId}`);
629625
if (!state.focusComponent.id) {
630626
console.log('Delete prop error. no focused component ');
631627
return state;
632628
}
633-
// make a deep copy of focusCOmponent. we are gonne be modifying that copy
629+
634630
const modifiedComponent = cloneDeep(
635631
state.components.find(comp => comp.id === state.focusComponent.id),
636632
);
637633

638634
const indexToDelete = modifiedComponent.props.findIndex(prop => prop.id === propId);
639-
if (indexToDelete < 0) {
635+
if (indexToDelete === -1) {
640636
console.log(`Delete prop Error. Prop id:${propId} not found in ${modifiedComponent.title}`);
641637
return state;
642638
}
@@ -662,7 +658,6 @@ export const updateHtmlAttr = (state, { attr, value }) => {
662658
const modifiedChild = cloneDeep(state.focusChild);
663659
modifiedChild.HTMLInfo[attr] = value;
664660

665-
// make a deep copy of focusCOmponent. we are gonne be modifying that copy
666661
const modifiedComponent = cloneDeep(
667662
state.components.find(comp => comp.id === state.focusComponent.id),
668663
);

0 commit comments

Comments
 (0)