Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
timtamimi committed Aug 11, 2021
1 parent 37eb401 commit a6d9ea6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/digitise/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
'use strict';
const deepMap = require('deep-map');
const reducer = require('./reducer');
const {
getInitialState,
stateManager
} = require('./state-manager');
const statuses = require('./statuses');
const { pickBy, isArray, isObject, mapValues, pick, setWith, find } = require('lodash');
const {
getAddress,
Expand Down Expand Up @@ -229,5 +234,8 @@ module.exports = {
extractData,
prepareData,
filterScalars,
reducer
reducer,
getInitialState,
stateManager,
statuses
};
36 changes: 36 additions & 0 deletions src/digitise/state-manager.js
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
};

0 comments on commit a6d9ea6

Please sign in to comment.