1 | module.exports = function stateChangeLogic(stateComparisonResults) {
|
2 | let hitChangingState = false
|
3 | let hitDestroyedState = false
|
4 |
|
5 | const output = {
|
6 | destroy: [],
|
7 | change: [],
|
8 | create: [],
|
9 | }
|
10 |
|
11 | stateComparisonResults.forEach(state => {
|
12 | hitChangingState = hitChangingState || state.stateParametersChanged
|
13 | hitDestroyedState = hitDestroyedState || state.stateNameChanged
|
14 |
|
15 | if (state.nameBefore) {
|
16 | if (hitDestroyedState) {
|
17 | output.destroy.push(state.nameBefore)
|
18 | } else if (hitChangingState) {
|
19 | output.change.push(state.nameBefore)
|
20 | }
|
21 | }
|
22 |
|
23 | if (state.nameAfter && hitDestroyedState) {
|
24 | output.create.push(state.nameAfter)
|
25 | }
|
26 | })
|
27 |
|
28 | return output
|
29 | }
|