Skip to content

Commit

Permalink
Add logic to reset a currently edited item
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Nov 9, 2017
1 parent 6b13991 commit c19cd77
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/features/editing/editingActions.js
Expand Up @@ -3,6 +3,7 @@ import {
EDIT_ITEM_UPDATE,
EDIT_ITEM_APPLY,
EDIT_ITEM_STOP,
EDIT_ITEM_RESET,
} from "./editingConstants";


Expand Down Expand Up @@ -45,4 +46,14 @@ export function stopEditingItem(itemType, itemID) {
itemID
},
};
}

export function resetEditedItem(itemType, itemID) {
return {
type : EDIT_ITEM_RESET,
payload : {
itemType,
itemID,
},
};
}
1 change: 1 addition & 0 deletions src/features/editing/editingConstants.js
Expand Up @@ -2,3 +2,4 @@ export const EDIT_ITEM_EXISTING = "EDIT_ITEM_EXISTING";
export const EDIT_ITEM_UPDATE = "EDIT_ITEM_UPDATE";
export const EDIT_ITEM_APPLY = "EDIT_ITEM_APPLY";
export const EDIT_ITEM_STOP = "EDIT_ITEM_STOP";
export const EDIT_ITEM_RESET = "EDIT_ITEM_RESET";
12 changes: 11 additions & 1 deletion src/features/editing/editingReducer.js
Expand Up @@ -12,7 +12,8 @@ import {
EDIT_ITEM_EXISTING,
EDIT_ITEM_UPDATE,
EDIT_ITEM_APPLY,
EDIT_ITEM_STOP
EDIT_ITEM_STOP,
EDIT_ITEM_RESET,
} from "./editingConstants";

import {getModelByType} from "common/utils/modelUtils";
Expand Down Expand Up @@ -105,12 +106,21 @@ export function editItemApply(state, payload) {
}


export function editItemReset(state, payload) {
const stateWithoutItem = editItemStop(state, payload);
const stateWithCurrentItem = editItemExisting(stateWithoutItem, payload);

return stateWithCurrentItem;
}



const editingFeatureReducer = createReducer({}, {
[EDIT_ITEM_EXISTING] : editItemExisting,
[EDIT_ITEM_UPDATE] : editItemUpdate,
[EDIT_ITEM_APPLY] : editItemApply,
[EDIT_ITEM_STOP] : editItemStop,
[EDIT_ITEM_RESET] : editItemReset,
});

export default editingFeatureReducer;

0 comments on commit c19cd77

Please sign in to comment.