Skip to content

Commit 7f81197

Browse files
committed
Extract function '_removeSlotValue' in updateElementReducer
1 parent 81f1a28 commit 7f81197

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/reducers/workspace/updateElementReducer.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -181,27 +181,12 @@ export const unlinkSlots = (workspace, payload) => {
181181
const index = outputSlot.outputElementIds.indexOf(output.elementId)
182182

183183
const outputElement = workspace.entities[output.elementId]
184-
let slots = {}
185-
186-
if(outputElement.componentName == MAIN_BRICK) {
187-
Object.assign(slots, {
188-
outputSlots: outputElement.outputSlots
189-
})
190-
delete slots.outputSlots[output.slotId]['value']
191-
} else {
192-
Object.assign(slots, {
193-
inputSlots: outputElement.inputSlots
194-
})
195-
delete slots.inputSlots[output.slotId]['value']
196-
}
184+
const newOutputElement = _removeSlotValue(outputElement, output.slotId)
197185

198186
return Object.assign({}, workspace, {
199187
entities: {
200188
...workspace.entities,
201-
[outputElement.id]: {
202-
...outputElement,
203-
...slots
204-
},
189+
[outputElement.id]: newOutputElement,
205190
[inputElement.id]: {
206191
...inputElement,
207192
outputSlots: {
@@ -218,3 +203,21 @@ export const unlinkSlots = (workspace, payload) => {
218203
}
219204
})
220205
}
206+
207+
const _removeSlotValue = (element, slotId) => {
208+
var slots = {}
209+
210+
if(element.componentName == MAIN_BRICK) {
211+
Object.assign(slots, {
212+
outputSlots: element.outputSlots
213+
})
214+
delete slots.outputSlots[slotId]['value']
215+
} else {
216+
Object.assign(slots, {
217+
inputSlots: element.inputSlots
218+
})
219+
delete slots.inputSlots[slotId]['value']
220+
}
221+
222+
return Object.assign(element, { ...slots })
223+
}

0 commit comments

Comments
 (0)