Permalink
Browse files

Add ability to edit a new entity

  • Loading branch information...
markerikson committed Dec 29, 2017
1 parent 02bd796 commit 1c8e64b3fc736938ba74071f12d9db49873d5680
@@ -1,5 +1,6 @@
import {
EDIT_ITEM_EXISTING,
EDIT_ITEM_NEW,
EDIT_ITEM_UPDATE,
EDIT_ITEM_APPLY,
EDIT_ITEM_STOP,
@@ -17,6 +18,17 @@ export function editExistingItem(itemType, itemID) {
};
}
export function editNewItem(itemType, itemID, newItemAttributes) {
return {
type : EDIT_ITEM_NEW,
payload : {
itemType,
itemID,
newItemAttributes,
}
};
}
export function editItemAttributes(itemType, itemID, newItemAttributes) {
return {
type : EDIT_ITEM_UPDATE,
@@ -1,4 +1,5 @@
export const EDIT_ITEM_EXISTING = "EDIT_ITEM_EXISTING";
export const EDIT_ITEM_NEW = "EDIT_ITEM_NEW";
export const EDIT_ITEM_UPDATE = "EDIT_ITEM_UPDATE";
export const EDIT_ITEM_APPLY = "EDIT_ITEM_APPLY";
export const EDIT_ITEM_STOP = "EDIT_ITEM_STOP";
@@ -10,6 +10,7 @@ import {
import {
EDIT_ITEM_EXISTING,
EDIT_ITEM_NEW,
EDIT_ITEM_UPDATE,
EDIT_ITEM_APPLY,
EDIT_ITEM_STOP,
@@ -67,6 +68,10 @@ export function updateEditedEntity(sourceEntities, destinationEntities, payload)
existingItem.updateFrom(model);
}
}
else {
const itemContents = model.toJSON();
ModelClass.parse(itemContents);
}
// Return the updated "current" relational data.
return writeSession.state;
@@ -84,6 +89,13 @@ export function editItemExisting(state, payload) {
return updateEditingEntitiesState(state, updatedEditingEntities);
}
export function editItemNew(state, payload) {
const editingEntities = selectEditingEntities(state);
const updatedEditingEntities = createEntity(editingEntities, payload);
return updateEditingEntitiesState(state, updatedEditingEntities);
}
export function editItemUpdate(state, payload) {
const editingEntities = selectEditingEntities(state);
@@ -119,6 +131,7 @@ export function editItemReset(state, payload) {
const editingFeatureReducer = createReducer({}, {
[EDIT_ITEM_EXISTING] : editItemExisting,
[EDIT_ITEM_NEW] : editItemNew,
[EDIT_ITEM_UPDATE] : editItemUpdate,
[EDIT_ITEM_APPLY] : editItemApply,
[EDIT_ITEM_STOP] : editItemStop,

0 comments on commit 1c8e64b

Please sign in to comment.