-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const { reducer, statuses } = require('@envage/water-abstraction-helpers').digitise; | ||
const { STATUS_IN_PROGRESS } = statuses; | ||
|
||
/** | ||
* Gets initial state for the specified licence row from the permit repo | ||
* @param {Object} licence - row from permit repo data | ||
* @return {Object} initial state for state manager | ||
*/ | ||
const getInitialState = (licence) => { | ||
return { | ||
licence: licence.licence_data_value, | ||
status: STATUS_IN_PROGRESS, | ||
notes: [] | ||
}; | ||
}; | ||
|
||
/** | ||
* Gets final state based on: | ||
* @param {String} initialState - the immutable base licence data from permit repo | ||
* @param {Array} actions - an array of actions describing mutations to the data | ||
* @param {Function} reducer - a function which accepts the state and an action, and returns the next state | ||
*/ | ||
const stateManager = (initialState, actions = []) => { | ||
let state = initialState; | ||
|
||
for (const action of actions) { | ||
state = reducer(state, action); | ||
} | ||
|
||
return state; | ||
}; | ||
|
||
module.exports = { | ||
getInitialState, | ||
stateManager | ||
}; |