@codetanzania/emis-api-states
Advanced tools
Comparing version 0.9.0 to 0.9.1
@@ -0,1 +1,21 @@ | ||
#### 0.9.1 (2019-03-01) | ||
##### Chores | ||
* **build:** bundle library for version 0.9.1 ([4ded80cd](https://github.com/CodeTanzania/emis-api-states/commit/4ded80cd5ae67eab0b43a370ecbfce2cc741d732)) | ||
* **package.json:** update package version to 0.9.1 ([c537e7b2](https://github.com/CodeTanzania/emis-api-states/commit/c537e7b2c448b7b542dd2f6a35fc871477811772)) | ||
##### Documentation Changes | ||
* **readme:** add size property to store structure section ([400cd04b](https://github.com/CodeTanzania/emis-api-states/commit/400cd04b217481dacae60bf2007701cf51459b48)) | ||
* ***:** ensure consistency on code documentation ([98de4a9b](https://github.com/CodeTanzania/emis-api-states/commit/98de4a9b57cb42aa89db52efaa265693d605f238)) | ||
##### Bug Fixes | ||
* **slice factory:** add missing returned results size in the store ([25d17f94](https://github.com/CodeTanzania/emis-api-states/commit/25d17f94438e2c38c1150630050647eff526e305)) | ||
##### Refactors | ||
* ***:** cleanup documentation and remove unused codes ([b7484ebf](https://github.com/CodeTanzania/emis-api-states/commit/b7484ebf9dbe3510f267c88130b4238daf3acf92)) | ||
#### 0.9.0 (2019-02-19) | ||
@@ -2,0 +22,0 @@ |
246
es/index.js
@@ -8,6 +8,6 @@ import forIn from 'lodash/forIn'; | ||
import { Provider, connect } from 'react-redux'; | ||
import { pluralize, singularize } from 'inflection'; | ||
import merge from 'lodash/merge'; | ||
import { combineReducers } from 'redux'; | ||
import { createSlice, configureStore } from 'redux-starter-kit'; | ||
import { pluralize, singularize } from 'inflection'; | ||
import upperFirst from 'lodash/upperFirst'; | ||
@@ -25,3 +25,3 @@ import camelCase from 'lodash/camelCase'; | ||
* | ||
* @param {...string} words - list of words to join and camelize | ||
* @param {...string} words list of words to join and camelize | ||
* @returns {string} camelCase of joined words | ||
@@ -40,2 +40,72 @@ * | ||
/** | ||
* @function | ||
* @name wrapActionsWithDispatch | ||
* @description Wrap actions with dispatch function. Make users to just | ||
* invoke actions without have to dispatch them. | ||
* | ||
* @param {Object} actions list of redux actions | ||
* @param {Function} dispatch store dispatch function | ||
* @returns {Object} map of redux action wrapped with dispatch function | ||
* | ||
* @version 0.1.0 | ||
* @since 0.1.0 | ||
*/ | ||
function wrapActionsWithDispatch(actions, dispatch) { | ||
var wrappedActions = {}; | ||
forIn(actions, function (fn, key) { | ||
wrappedActions[key] = function () { | ||
return dispatch(fn.apply(undefined, arguments)); | ||
}; | ||
}); | ||
return wrappedActions; | ||
} | ||
/** | ||
* @function | ||
* @name extractReducers | ||
* @description Extract all resource reducers into a single object | ||
* | ||
* @param {string[]} resources list of exposed API resources | ||
* @param {Object[]} slices list of resource slices | ||
* @returns {Object} map of all resources reducers | ||
* | ||
* @version 0.1.0 | ||
* @since 0.1.0 | ||
*/ | ||
function extractReducers(resources, slices) { | ||
var reducers = {}; | ||
// reducers | ||
resources.forEach(function (resource) { | ||
reducers[pluralize(resource)] = slices[resource].reducer; | ||
}); | ||
return reducers; | ||
} | ||
/** | ||
* @function | ||
* @name extractActions | ||
* @description Extracts all actions from all slices into into a single object | ||
* | ||
* @param {string[]} resources list of api resources | ||
* @param {Object[]} slices list of all resources slices | ||
* @returns {Object} map of all resources actions | ||
* | ||
* @version 0.1.0 | ||
* @since 0.1.0 | ||
*/ | ||
function extractActions(resources, slices) { | ||
var actions = {}; | ||
resources.forEach(function (resource) { | ||
actions[resource] = slices[resource].actions; | ||
}); | ||
return actions; | ||
} | ||
var defineProperty = function (obj, key, value) { | ||
@@ -71,3 +141,3 @@ if (key in obj) { | ||
* | ||
* @param {string} resourceName - Resource name | ||
* @param {string} resourceName Resource name | ||
* @returns {Object} Resource reducers | ||
@@ -101,2 +171,3 @@ * | ||
total: action.payload.total, | ||
size: action.payload.size, | ||
loading: false | ||
@@ -156,2 +227,3 @@ }); | ||
pages: 1, | ||
size: 0, | ||
loading: false, | ||
@@ -172,5 +244,5 @@ posting: false, | ||
* | ||
* @param {string} sliceName - Slice name which will results to be reducer name | ||
* @param {Object} initialState - Optional override of default initial state | ||
* @param {Object} reducers - Optional override of default reducers | ||
* @param {string} sliceName Slice name which will results to be reducer name | ||
* @param {Object} initialState Optional override of default initial state | ||
* @param {Object} reducers Optional override of default reducers | ||
* @returns {Object} slice resource slice | ||
@@ -210,47 +282,2 @@ * | ||
* @function | ||
* @name mapSliceReducers | ||
* @description Extract all resource reducers into a single object | ||
* | ||
* @param {Array<string>} resources list of api resources | ||
* @param {Object} slices resources slice | ||
* @returns {Object} reducers list of api reducers | ||
* | ||
* @version 0.1.0 | ||
* @since 0.1.0 | ||
*/ | ||
function mapSliceReducers(resources, slices) { | ||
var reducers = {}; | ||
// reducers | ||
resources.forEach(function (resource) { | ||
reducers[pluralize(resource)] = slices[resource].reducer; | ||
}); | ||
return reducers; | ||
} | ||
/** | ||
* @function | ||
* @name mapSliceActions | ||
* @description Extracts all actions into one object | ||
* | ||
* @param {Array<string>} resources list of api resources | ||
* @param {Object} slices resources slice | ||
* @returns {Object} actions list of api actions | ||
* | ||
* @version 0.1.0 | ||
* @since 0.1.0 | ||
*/ | ||
function mapSliceActions(resources, slices) { | ||
var actions = {}; | ||
resources.forEach(function (resource) { | ||
actions[resource] = slices[resource].actions; | ||
}); | ||
return actions; | ||
} | ||
/** | ||
* @function | ||
* @name createResourcesSlices | ||
@@ -281,5 +308,5 @@ * @description Create slices from all EMIS resources | ||
* | ||
* @param {Object} state - previous app state value | ||
* @param {Object} action - dispatched action object | ||
* @returns {Object} - updated app state | ||
* @param {Object} state previous app state value | ||
* @param {Object} action dispatched action object | ||
* @returns {Object} updated app state | ||
* | ||
@@ -309,10 +336,9 @@ * @version 0.1.0 | ||
// all resources exposed by this library | ||
var resources = ['activity', 'adjustment', 'agency', 'alert', 'assessment', 'district', 'feature', 'incident', 'incidentType', 'indicator', 'item', 'plan', 'procedure', 'question', 'questionnaire', 'region', 'resource', 'role', 'focalPerson', 'stock', 'warehouse', 'alertSource']; | ||
var resources = ['activity', 'adjustment', 'agency', 'alert', 'alertSource', 'assessment', 'district', 'feature', 'incident', 'incidentType', 'indicator', 'item', 'plan', 'procedure', 'question', 'questionnaire', 'region', 'resource', 'role', 'focalPerson', 'stock', 'warehouse']; | ||
var slices = createResourcesSlices(resources); | ||
var reducers = mapSliceReducers(resources, slices); | ||
var allReducers = merge({}, reducers, { app: app }); | ||
var reducers = merge({}, extractReducers(resources, slices), { app: app }); | ||
var rootReducer = combineReducers(allReducers); | ||
var rootReducer = combineReducers(reducers); | ||
@@ -324,3 +350,3 @@ var store = configureStore({ | ||
var actions = mapSliceActions(resources, slices, store.dispatch); | ||
var actions = extractActions(resources, slices, store.dispatch); | ||
@@ -398,3 +424,3 @@ var dispatch = store.dispatch; | ||
* from the API fails | ||
* @returns {Function} Thunk function | ||
* @returns {Function} Thunk function | ||
* | ||
@@ -431,8 +457,8 @@ * @version 0.1.0 | ||
* | ||
* @param {Object} param Resource object to be created/Saved | ||
* @param {Function} onSuccess Callback to be executed when posting a | ||
* @param {Object} param Resource object to be created/Saved | ||
* @param {Function} onSuccess Callback to be executed when posting a | ||
* resource succeed | ||
* @param {Function} onError Callback to be executed when posting | ||
* @param {Function} onError Callback to be executed when posting | ||
* resource fails | ||
* @returns {Function} Thunk function | ||
* @returns {Function} Thunk function | ||
* | ||
@@ -471,8 +497,8 @@ * @version 0.1.0 | ||
* | ||
* @param {Object} param Resource object to be updated | ||
* @param {Function} onSuccess Callback to be executed when updating a | ||
* @param {Object} param Resource object to be updated | ||
* @param {Function} onSuccess Callback to be executed when updating a | ||
* resource succeed | ||
* @param {Function} onError Callback to be executed when updating a | ||
* @param {Function} onError Callback to be executed when updating a | ||
* resource fails | ||
* @returns {Function} Thunk function | ||
* @returns {Function} Thunk function | ||
* | ||
@@ -511,8 +537,8 @@ * @version 0.1.0 | ||
* | ||
* @param {string} id Resource unique identification | ||
* @param {Function} onSuccess Callback to be executed when updating a | ||
* @param {string} id Resource unique identification | ||
* @param {Function} onSuccess Callback to be executed when updating a | ||
* resource succeed | ||
* @param {Function} onError Callback to be executed when updating a | ||
* @param {Function} onError Callback to be executed when updating a | ||
* resource fails | ||
* @returns {Function} Thunk function | ||
* @returns {Function} Thunk function | ||
* | ||
@@ -584,8 +610,8 @@ * @version 0.1.0 | ||
* | ||
* @param {Object} filter Resource filter criteria object | ||
* @param {Function} onSuccess Callback to be executed when filtering | ||
* @param {Object} filter Resource filter criteria object | ||
* @param {Function} onSuccess Callback to be executed when filtering | ||
* resources succeed | ||
* @param {Function} onError Callback to be executed when filtering | ||
* @param {Function} onError Callback to be executed when filtering | ||
* resources fails | ||
* @returns {Function} Thunk function | ||
* @returns {Function} Thunk function | ||
* | ||
@@ -609,7 +635,7 @@ * @version 0.1.0 | ||
* | ||
* @param {Function} onSuccess Callback to be executed when refreshing | ||
* @param {Function} onSuccess Callback to be executed when refreshing | ||
* resources succeed | ||
* @param {Function} onError Callback to be executed when refreshing | ||
* @param {Function} onError Callback to be executed when refreshing | ||
* resources fails | ||
* @returns {Function} Thunk function | ||
* @returns {Function} Thunk function | ||
* | ||
@@ -642,7 +668,7 @@ * @version 0.1.0 | ||
* @param {string} query Search query string | ||
* @param {Function} onSuccess Callback to be executed when searching | ||
* @param {Function} onSuccess Callback to be executed when searching | ||
* resources succeed | ||
* @param {Function} onError Callback to be executed when searching | ||
* @param {Function} onError Callback to be executed when searching | ||
* resources fails | ||
* @returns {Function} Thunk function | ||
* @returns {Function} Thunk function | ||
* | ||
@@ -669,8 +695,8 @@ * @version 0.1.0 | ||
* | ||
* @param {Object} order sort order object | ||
* @param {Function} onSuccess Callback to be executed when sorting | ||
* @param {Object} order sort order object | ||
* @param {Function} onSuccess Callback to be executed when sorting | ||
* resources succeed | ||
* @param {Function} onError Callback to be executed when sorting | ||
* @param {Function} onError Callback to be executed when sorting | ||
* resources fails | ||
* @returns {Function} Thunk function | ||
* @returns {Function} Thunk function | ||
* | ||
@@ -698,7 +724,7 @@ * @version 0.1.0 | ||
* @param {number} page paginate to page | ||
* @param {Function} onSuccess Callback to be executed when paginating | ||
* @param {Function} onSuccess Callback to be executed when paginating | ||
* resources succeed | ||
* @param {Function} onError Callback to be executed when paginating | ||
* @param {Function} onError Callback to be executed when paginating | ||
* resources fails | ||
* @returns {Function} Thunk function | ||
* @returns {Function} Thunk function | ||
* | ||
@@ -725,8 +751,8 @@ * @version 0.1.0 | ||
* | ||
* @param {Function} onSuccess Callback to be executed when filters are | ||
* @param {Function} onSuccess Callback to be executed when filters are | ||
* cleared and resources data is reloaded successfully | ||
* @param {Function} onError Callback to be executed when filters are | ||
* @param {Function} onError Callback to be executed when filters are | ||
* cleared and resources data fails to reload | ||
* @param {string[]} keep list of filter names to be kept | ||
* @returns {Function} Thunk Function | ||
* @param {string[]} keep list of filter names to be kept | ||
* @returns {Function} Thunk Function | ||
* | ||
@@ -757,7 +783,7 @@ * @version 0.1.0 | ||
* | ||
* @param {Function} onSuccess Callback to be executed when sort are | ||
* @param {Function} onSuccess Callback to be executed when sort are | ||
* cleared and resources data is reloaded successfully | ||
* @param {Function} onError Callback to be executed when sort are | ||
* @param {Function} onError Callback to be executed when sort are | ||
* cleared and resources data fails to reload | ||
* @returns {Function} Thunk function | ||
* @returns {Function} Thunk function | ||
* | ||
@@ -788,6 +814,6 @@ * @version 0.1.0 | ||
* | ||
* @param {string} resource - Resource Name | ||
* @param {Object} actions - Resources actions | ||
* @param {Function} dispatch - Store action dispatcher | ||
* @param {Object} thunks - Custom thunks to override/extends existing thunks | ||
* @param {string} resource Resource Name | ||
* @param {Object} actions Resources actions | ||
* @param {Function} dispatch Store action dispatcher | ||
* @param {Object} thunks Custom thunks to override/extends existing thunks | ||
* @returns {Object} wrapped resource actions with dispatching ability | ||
@@ -819,11 +845,3 @@ * | ||
var wrappedDispatchThunkActions = {}; | ||
forIn(allActions, function (fn, key) { | ||
wrappedDispatchThunkActions[key] = function () { | ||
return dispatch(fn.apply(undefined, arguments)); | ||
}; | ||
}); | ||
return wrappedDispatchThunkActions; | ||
return wrapActionsWithDispatch(allActions, dispatch); | ||
} | ||
@@ -1400,4 +1418,4 @@ | ||
* | ||
* @param {Object} props - react nodes | ||
* @param {Object} props.children - react nodes | ||
* @param {Object} props react nodes | ||
* @param {Object} props.children react nodes | ||
* @returns {Object} Store provider | ||
@@ -1434,5 +1452,5 @@ * @version 0.1.0 | ||
* | ||
* @param {Object} component - react node | ||
* @param {Object|Function} stateToProps - states to inject into props | ||
* @returns {Object} - React component which is injected with props | ||
* @param {Object} component react node | ||
* @param {Object|Function} stateToProps states to inject into props | ||
* @returns {Object} React component which is injected with props | ||
* | ||
@@ -1439,0 +1457,0 @@ * @version 0.1.0 |
{ | ||
"name": "@codetanzania/emis-api-states", | ||
"version": "0.9.0", | ||
"version": "0.9.1", | ||
"description": "EMIS Redux state management library", | ||
@@ -124,10 +124,6 @@ "main": "lib/index.js", | ||
"commitlint": { | ||
"extends": [ | ||
"@commitlint/config-conventional" | ||
] | ||
"extends": ["@commitlint/config-conventional"] | ||
}, | ||
"lint-staged": { | ||
"src/**/*.js": [ | ||
"npm run lint" | ||
] | ||
"src/**/*.js": ["npm run lint"] | ||
}, | ||
@@ -134,0 +130,0 @@ "husky": { |
@@ -85,2 +85,3 @@ # EMIS API States | ||
total: 0, | ||
size: 0, | ||
pages: 1, | ||
@@ -99,2 +100,3 @@ loading: false, | ||
total: 0, | ||
size: 0, | ||
pages: 1, | ||
@@ -101,0 +103,0 @@ loading: false, |
import { singularize } from 'inflection'; | ||
import forIn from 'lodash/forIn'; | ||
import get from 'lodash/get'; | ||
import merge from 'lodash/merge'; | ||
import upperFirst from 'lodash/upperFirst'; | ||
import camelize from '../helpers'; | ||
import { camelize, wrapActionsWithDispatch } from '../utils'; | ||
import createThunkFor from './thunk'; | ||
@@ -16,6 +15,6 @@ | ||
* | ||
* @param {string} resource - Resource Name | ||
* @param {Object} actions - Resources actions | ||
* @param {Function} dispatch - Store action dispatcher | ||
* @param {Object} thunks - Custom thunks to override/extends existing thunks | ||
* @param {string} resource Resource Name | ||
* @param {Object} actions Resources actions | ||
* @param {Function} dispatch Store action dispatcher | ||
* @param {Object} thunks Custom thunks to override/extends existing thunks | ||
* @returns {Object} wrapped resource actions with dispatching ability | ||
@@ -62,9 +61,3 @@ * | ||
const wrappedDispatchThunkActions = {}; | ||
forIn(allActions, (fn, key) => { | ||
wrappedDispatchThunkActions[key] = (...params) => dispatch(fn(...params)); | ||
}); | ||
return wrappedDispatchThunkActions; | ||
return wrapActionsWithDispatch(allActions, dispatch); | ||
} |
@@ -5,3 +5,3 @@ import { pluralize, singularize } from 'inflection'; | ||
import { createSlice } from 'redux-starter-kit'; | ||
import camelize from '../helpers'; | ||
import { camelize } from '../utils'; | ||
@@ -13,3 +13,3 @@ /** | ||
* | ||
* @param {string} resourceName - Resource name | ||
* @param {string} resourceName Resource name | ||
* @returns {Object} Resource reducers | ||
@@ -42,2 +42,3 @@ * | ||
total: action.payload.total, | ||
size: action.payload.size, | ||
loading: false, | ||
@@ -97,2 +98,3 @@ }), | ||
pages: 1, | ||
size: 0, | ||
loading: false, | ||
@@ -113,5 +115,5 @@ posting: false, | ||
* | ||
* @param {string} sliceName - Slice name which will results to be reducer name | ||
* @param {Object} initialState - Optional override of default initial state | ||
* @param {Object} reducers - Optional override of default reducers | ||
* @param {string} sliceName Slice name which will results to be reducer name | ||
* @param {Object} initialState Optional override of default initial state | ||
* @param {Object} reducers Optional override of default reducers | ||
* @returns {Object} slice resource slice | ||
@@ -118,0 +120,0 @@ * |
@@ -8,3 +8,3 @@ import { httpActions as client } from '@codetanzania/emis-api-client'; | ||
import isFunction from 'lodash/isFunction'; | ||
import camelize from '../helpers'; | ||
import { camelize } from '../utils'; | ||
import { actions } from '../store'; | ||
@@ -89,3 +89,3 @@ | ||
* from the API fails | ||
* @returns {Function} Thunk function | ||
* @returns {Function} Thunk function | ||
* | ||
@@ -130,8 +130,8 @@ * @version 0.1.0 | ||
* | ||
* @param {Object} param Resource object to be created/Saved | ||
* @param {Function} onSuccess Callback to be executed when posting a | ||
* @param {Object} param Resource object to be created/Saved | ||
* @param {Function} onSuccess Callback to be executed when posting a | ||
* resource succeed | ||
* @param {Function} onError Callback to be executed when posting | ||
* @param {Function} onError Callback to be executed when posting | ||
* resource fails | ||
* @returns {Function} Thunk function | ||
* @returns {Function} Thunk function | ||
* | ||
@@ -182,8 +182,8 @@ * @version 0.1.0 | ||
* | ||
* @param {Object} param Resource object to be updated | ||
* @param {Function} onSuccess Callback to be executed when updating a | ||
* @param {Object} param Resource object to be updated | ||
* @param {Function} onSuccess Callback to be executed when updating a | ||
* resource succeed | ||
* @param {Function} onError Callback to be executed when updating a | ||
* @param {Function} onError Callback to be executed when updating a | ||
* resource fails | ||
* @returns {Function} Thunk function | ||
* @returns {Function} Thunk function | ||
* | ||
@@ -230,8 +230,8 @@ * @version 0.1.0 | ||
* | ||
* @param {string} id Resource unique identification | ||
* @param {Function} onSuccess Callback to be executed when updating a | ||
* @param {string} id Resource unique identification | ||
* @param {Function} onSuccess Callback to be executed when updating a | ||
* resource succeed | ||
* @param {Function} onError Callback to be executed when updating a | ||
* @param {Function} onError Callback to be executed when updating a | ||
* resource fails | ||
* @returns {Function} Thunk function | ||
* @returns {Function} Thunk function | ||
* | ||
@@ -316,8 +316,8 @@ * @version 0.1.0 | ||
* | ||
* @param {Object} filter Resource filter criteria object | ||
* @param {Function} onSuccess Callback to be executed when filtering | ||
* @param {Object} filter Resource filter criteria object | ||
* @param {Function} onSuccess Callback to be executed when filtering | ||
* resources succeed | ||
* @param {Function} onError Callback to be executed when filtering | ||
* @param {Function} onError Callback to be executed when filtering | ||
* resources fails | ||
* @returns {Function} Thunk function | ||
* @returns {Function} Thunk function | ||
* | ||
@@ -345,7 +345,7 @@ * @version 0.1.0 | ||
* | ||
* @param {Function} onSuccess Callback to be executed when refreshing | ||
* @param {Function} onSuccess Callback to be executed when refreshing | ||
* resources succeed | ||
* @param {Function} onError Callback to be executed when refreshing | ||
* @param {Function} onError Callback to be executed when refreshing | ||
* resources fails | ||
* @returns {Function} Thunk function | ||
* @returns {Function} Thunk function | ||
* | ||
@@ -381,7 +381,7 @@ * @version 0.1.0 | ||
* @param {string} query Search query string | ||
* @param {Function} onSuccess Callback to be executed when searching | ||
* @param {Function} onSuccess Callback to be executed when searching | ||
* resources succeed | ||
* @param {Function} onError Callback to be executed when searching | ||
* @param {Function} onError Callback to be executed when searching | ||
* resources fails | ||
* @returns {Function} Thunk function | ||
* @returns {Function} Thunk function | ||
* | ||
@@ -414,8 +414,8 @@ * @version 0.1.0 | ||
* | ||
* @param {Object} order sort order object | ||
* @param {Function} onSuccess Callback to be executed when sorting | ||
* @param {Object} order sort order object | ||
* @param {Function} onSuccess Callback to be executed when sorting | ||
* resources succeed | ||
* @param {Function} onError Callback to be executed when sorting | ||
* @param {Function} onError Callback to be executed when sorting | ||
* resources fails | ||
* @returns {Function} Thunk function | ||
* @returns {Function} Thunk function | ||
* | ||
@@ -449,7 +449,7 @@ * @version 0.1.0 | ||
* @param {number} page paginate to page | ||
* @param {Function} onSuccess Callback to be executed when paginating | ||
* @param {Function} onSuccess Callback to be executed when paginating | ||
* resources succeed | ||
* @param {Function} onError Callback to be executed when paginating | ||
* @param {Function} onError Callback to be executed when paginating | ||
* resources fails | ||
* @returns {Function} Thunk function | ||
* @returns {Function} Thunk function | ||
* | ||
@@ -480,8 +480,8 @@ * @version 0.1.0 | ||
* | ||
* @param {Function} onSuccess Callback to be executed when filters are | ||
* @param {Function} onSuccess Callback to be executed when filters are | ||
* cleared and resources data is reloaded successfully | ||
* @param {Function} onError Callback to be executed when filters are | ||
* @param {Function} onError Callback to be executed when filters are | ||
* cleared and resources data fails to reload | ||
* @param {string[]} keep list of filter names to be kept | ||
* @returns {Function} Thunk Function | ||
* @param {string[]} keep list of filter names to be kept | ||
* @returns {Function} Thunk Function | ||
* | ||
@@ -517,7 +517,7 @@ * @version 0.1.0 | ||
* | ||
* @param {Function} onSuccess Callback to be executed when sort are | ||
* @param {Function} onSuccess Callback to be executed when sort are | ||
* cleared and resources data is reloaded successfully | ||
* @param {Function} onError Callback to be executed when sort are | ||
* @param {Function} onError Callback to be executed when sort are | ||
* cleared and resources data fails to reload | ||
* @returns {Function} Thunk function | ||
* @returns {Function} Thunk function | ||
* | ||
@@ -524,0 +524,0 @@ * @version 0.1.0 |
import forIn from 'lodash/forIn'; | ||
import get from 'lodash/get'; | ||
@@ -15,4 +16,4 @@ import isFunction from 'lodash/isFunction'; | ||
* | ||
* @param {Object} props - react nodes | ||
* @param {Object} props.children - react nodes | ||
* @param {Object} props react nodes | ||
* @param {Object} props.children react nodes | ||
* @returns {Object} Store provider | ||
@@ -43,5 +44,5 @@ * @version 0.1.0 | ||
* | ||
* @param {Object} component - react node | ||
* @param {Object|Function} stateToProps - states to inject into props | ||
* @returns {Object} - React component which is injected with props | ||
* @param {Object} component react node | ||
* @param {Object|Function} stateToProps states to inject into props | ||
* @returns {Object} React component which is injected with props | ||
* | ||
@@ -48,0 +49,0 @@ * @version 0.1.0 |
@@ -1,3 +0,1 @@ | ||
import { pluralize } from 'inflection'; | ||
import forIn from 'lodash/forIn'; | ||
import merge from 'lodash/merge'; | ||
@@ -7,2 +5,3 @@ import { combineReducers } from 'redux'; | ||
import createResourceFor from './factories/slice'; | ||
import { extractActions, extractReducers } from './utils'; | ||
@@ -16,69 +15,2 @@ /* application action types */ | ||
* @function | ||
* @name wrapActionsWithDispatch | ||
* @description Wrap actions with dispatch function | ||
* | ||
* @param {Object} actions list of api actions | ||
* @param {Function} dispatch store dispatch | ||
* @returns {Object} actions list of wrapped api actions with dispatch ability | ||
* | ||
* @version 0.1.0 | ||
* @since 0.1.0 | ||
*/ | ||
export function wrapActionsWithDispatch(actions, dispatch) { | ||
const wrappedActions = {}; | ||
forIn(actions, (fn, key) => { | ||
wrappedActions[key] = payload => dispatch(fn(payload)); | ||
}); | ||
return wrappedActions; | ||
} | ||
/** | ||
* @function | ||
* @name mapSliceReducers | ||
* @description Extract all resource reducers into a single object | ||
* | ||
* @param {Array<string>} resources list of api resources | ||
* @param {Object} slices resources slice | ||
* @returns {Object} reducers list of api reducers | ||
* | ||
* @version 0.1.0 | ||
* @since 0.1.0 | ||
*/ | ||
export function mapSliceReducers(resources, slices) { | ||
const reducers = {}; | ||
// reducers | ||
resources.forEach(resource => { | ||
reducers[pluralize(resource)] = slices[resource].reducer; | ||
}); | ||
return reducers; | ||
} | ||
/** | ||
* @function | ||
* @name mapSliceActions | ||
* @description Extracts all actions into one object | ||
* | ||
* @param {Array<string>} resources list of api resources | ||
* @param {Object} slices resources slice | ||
* @returns {Object} actions list of api actions | ||
* | ||
* @version 0.1.0 | ||
* @since 0.1.0 | ||
*/ | ||
export function mapSliceActions(resources, slices) { | ||
const actions = {}; | ||
resources.forEach(resource => { | ||
actions[resource] = slices[resource].actions; | ||
}); | ||
return actions; | ||
} | ||
/** | ||
* @function | ||
* @name createResourcesSlices | ||
@@ -109,5 +41,5 @@ * @description Create slices from all EMIS resources | ||
* | ||
* @param {Object} state - previous app state value | ||
* @param {Object} action - dispatched action object | ||
* @returns {Object} - updated app state | ||
* @param {Object} state previous app state value | ||
* @param {Object} action dispatched action object | ||
* @returns {Object} updated app state | ||
* | ||
@@ -161,6 +93,5 @@ * @version 0.1.0 | ||
const reducers = mapSliceReducers(resources, slices); | ||
const allReducers = merge({}, reducers, { app }); | ||
const reducers = merge({}, extractReducers(resources, slices), { app }); | ||
const rootReducer = combineReducers(allReducers); | ||
const rootReducer = combineReducers(reducers); | ||
@@ -172,4 +103,4 @@ export const store = configureStore({ | ||
export const actions = mapSliceActions(resources, slices, store.dispatch); | ||
export const actions = extractActions(resources, slices, store.dispatch); | ||
export const { dispatch } = store; |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
202638
4547
251