Skip to content

Commit

Permalink
combined two iterations into one
Browse files Browse the repository at this point in the history
added null defaults
removed unused var
removed unnecessary destructuring to object
  • Loading branch information
nils committed Jun 9, 2022
1 parent a9b3ff9 commit b83e8e2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
16 changes: 10 additions & 6 deletions src/reducers/helpers/combine-shapes.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ const combineShapes = ({
),
};

return shapes.splice({
start: shapes.indexOf(shape2),
deleteCount: 1,
}).map(
(shape) => shape === shape1 ? newShape : shape
);
return shapes.reduce((newShapes, shape, idx, key) => {
switch (true) {
case shape === shape2:
return newShapes;
case shape === shape1:
return newShapes.append([key], newShape);
default:
return newShapes.append([key], shape);
}
}, List());
};

combineShapes.JoinTypes = JoinTypes;
Expand Down
4 changes: 2 additions & 2 deletions src/reducers/root-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ export const initialState = {
enabled: false,
height: 0,
width: 0,
x: 0,
y: 0,
x: null,
y: null,
},
uiOptions: {
vertexRadius: 6.5,
Expand Down
1 change: 0 additions & 1 deletion src/tools/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ const ListPrototype = Object.create({}, {
const deleteCount = options?.deleteCount ?? 0;
const newKeys = options?.newKeys ? Array.from(options.newKeys) : [];
const { keys, values } = this;
const uniqueKeys = [...keys, ...newKeys];

for (let i = 0, l = newValues.length; i < l; i++) {
newKeys[i] = newKeys[i] ?? uniqueKey([...keys, ...newKeys]);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/combine-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
*/
const combineReducers = (...reducers) => (inState, action) => reducers.reduce(
(outState, reducer) => ({ ...reducer(outState, action) }),
(outState, reducer) => (reducer(outState, action)),
inState
);

Expand Down

0 comments on commit b83e8e2

Please sign in to comment.