Removing needs from `held` when deleting.
@@ -151,7 +151,19 @@ export default function(allNeedsInState = initialState, action = {}) {
);
case actionTypes.needs.delete:
- return allNeedsInState.delete(action.payload.ownNeedUri);
+ return allNeedsInState.delete(action.payload.ownNeedUri).map(need => {
+ const removeHolder = need => {
+ if (need.get("heldBy") == action.payload.ownNeedUri) {
+ return need.delete("heldBy");
+ } else return need;
+ };
+ const removeHeld = need => {
+ return need.updateIn(["holds"], heldItems =>
+ heldItems.filter(heldItem => heldItem != action.payload.ownNeedUri)
+ );
+ };
+ return removeHeld(removeHolder(need));
+ });
case actionTypes.personas.create: {
//FIXME: Please let us use the addNeed method as a single entry point to add Needs(even Personas) to the State
