+64
-3
lines changedFilter options
+64
-3
lines changed Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
1
1
import {
2
2
EDIT_ITEM_EXISTING,
3
3
EDIT_ITEM_UPDATE,
4
-
EDIT_ITEM_STOP
4
+
EDIT_ITEM_APPLY,
5
+
EDIT_ITEM_STOP,
5
6
} from "./editingConstants";
6
7
7
8
@@ -26,6 +27,16 @@ export function editItemAttributes(itemType, itemID, newItemAttributes) {
26
27
};
27
28
}
28
29
30
+
export function applyItemEdits(itemType, itemID) {
31
+
return {
32
+
type : EDIT_ITEM_APPLY,
33
+
payload : {
34
+
itemType,
35
+
itemID
36
+
},
37
+
};
38
+
}
39
+
29
40
export function stopEditingItem(itemType, itemID) {
30
41
return {
31
42
type : EDIT_ITEM_STOP,
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
1
1
export const EDIT_ITEM_EXISTING = "EDIT_ITEM_EXISTING";
2
2
export const EDIT_ITEM_UPDATE = "EDIT_ITEM_UPDATE";
3
+
export const EDIT_ITEM_APPLY = "EDIT_ITEM_APPLY";
3
4
export const EDIT_ITEM_STOP = "EDIT_ITEM_STOP";
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
1
1
import {createReducer} from "common/utils/reducerUtils";
2
2
3
+
import schema from "app/schema";
4
+
3
5
import {
4
6
createEntity,
5
7
updateEntity,
@@ -9,14 +11,17 @@ import {
9
11
import {
10
12
EDIT_ITEM_EXISTING,
11
13
EDIT_ITEM_UPDATE,
12
-
EDIT_ITEM_STOP
14
+
EDIT_ITEM_APPLY,
15
+
EDIT_ITEM_STOP,
13
16
} from "./editingConstants";
14
17
18
+
import {getModelByType} from "common/utils/modelUtils";
15
19
16
20
import {selectEntities} from "features/entities/entitySelectors";
17
21
import {selectEditingEntities} from "./editingSelectors";
18
22
import {
19
23
readEntityData,
24
+
updateEntitiesState,
20
25
updateEditingEntitiesState,
21
26
} from "./editingUtils";
22
27
@@ -34,6 +39,41 @@ export function copyEntity(sourceEntities, destinationEntities, payload) {
34
39
35
40
36
41
42
+
export function updateEditedEntity(sourceEntities, destinationEntities, payload) {
43
+
// Start by reading our "work-in-progress" data
44
+
const readSession = schema.from(sourceEntities);
45
+
46
+
const {itemType, itemID} = payload;
47
+
48
+
// Look up the model instance for the requested item
49
+
const model = getModelByType(readSession, itemType, itemID);
50
+
51
+
52
+
// We of course will be updating our "current" relational data
53
+
let writeSession = schema.from(destinationEntities);
54
+
55
+
const ModelClass = writeSession[itemType];
56
+
57
+
if(ModelClass.hasId(itemID)) {
58
+
// Look up the original Model instance for the top item
59
+
const existingItem = ModelClass.withId(itemID);
60
+
61
+
if(existingItem.updateFrom) {
62
+
// Each model class should know how to properly update itself and its
63
+
// relations from another model of the same type. Ask the original model to
64
+
// update itself based on the "work-in-progress" model, which queues up a
65
+
// series of immutable add/update/delete actions internally
66
+
existingItem.updateFrom(model);
67
+
}
68
+
}
69
+
70
+
// Immutably apply the changes and generate our new "current" relational data
71
+
const updatedEntities = writeSession.reduce();
72
+
return updatedEntities;
73
+
}
74
+
75
+
76
+
37
77
38
78
export function editItemExisting(state, payload) {
39
79
const entities = selectEntities(state);
@@ -59,12 +99,21 @@ export function editItemStop(state, payload) {
59
99
}
60
100
61
101
102
+
export function editItemApply(state, payload) {
103
+
const entities = selectEntities(state);
104
+
const editingEntities = selectEditingEntities(state);
105
+
106
+
const updatedEntities = updateEditedEntity(editingEntities, entities, payload);
107
+
return updateEntitiesState(state, updatedEntities);
108
+
}
109
+
62
110
63
111
64
112
const editingFeatureReducer = createReducer({}, {
65
113
[EDIT_ITEM_EXISTING] : editItemExisting,
66
114
[EDIT_ITEM_UPDATE] : editItemUpdate,
115
+
[EDIT_ITEM_APPLY] : editItemApply,
67
116
[EDIT_ITEM_STOP] : editItemStop,
68
117
});
69
118
70
-
export default editingFeatureReducer;
119
+
export default editingFeatureReducer;
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4