Comparing version 0.1.4 to 0.1.6
@@ -64,8 +64,8 @@ (function (global, factory) { | ||
/** | ||
* This is a police manager, which is used to register, | ||
* get and run polices over actions and responses | ||
* This is a policy manager, which is used to register, | ||
* get and run policies over actions and responses | ||
* | ||
* A police is a middleware, and it should follow the signature bellow | ||
* A policy is a middleware, and it should follow the signature bellow | ||
* store => done => (action, error, response) => done(action, error, response); | ||
* A police must have a applyPoint property. The available apply points are: | ||
* A policy must have a applyPoint property. The available apply points are: | ||
* 'beforeRequest', 'onResponse' | ||
@@ -76,31 +76,31 @@ */ | ||
var globalPolices = {}; | ||
var globalPolicies = {}; | ||
var reset = function reset() { | ||
Object.keys(globalPolices).forEach(function (key) { | ||
delete globalPolices[key]; | ||
Object.keys(globalPolicies).forEach(function (key) { | ||
delete globalPolicies[key]; | ||
}); | ||
}; | ||
var register = function register(name, police) { | ||
var register = function register(name, policy) { | ||
var _Object$assign; | ||
if (globalPolices[name]) { | ||
throw new Error('Called register with police: ' + name + ' more than once'); | ||
if (globalPolicies[name]) { | ||
throw new Error('Called register with policy: ' + name + ' more than once'); | ||
} | ||
if (applyPoints.indexOf(police.applyPoint) < 0) { | ||
var invalid = 'Invalid applyPoint: ' + police.applyPoint + ', provided with police: ' + name + '.'; | ||
if (applyPoints.indexOf(policy.applyPoint) < 0) { | ||
var invalid = 'Invalid applyPoint: ' + policy.applyPoint + ', provided with policy: ' + name + '.'; | ||
var available = 'The apply points available are: ' + applyPoints.join(', '); | ||
throw new Error(invalid + ' ' + available); | ||
} | ||
Object.assign(globalPolices, (_Object$assign = {}, _Object$assign[name] = police, _Object$assign)); | ||
Object.assign(globalPolicies, (_Object$assign = {}, _Object$assign[name] = policy, _Object$assign)); | ||
}; | ||
var get = function get(policeNames) { | ||
var get = function get(policyNames) { | ||
return function (applyPoint) { | ||
var polices = policeNames.map(function (name) { | ||
return globalPolices[name]; | ||
}).filter(function (police) { | ||
return police.applyPoint === applyPoint; | ||
var policies = policyNames.map(function (name) { | ||
return globalPolicies[name]; | ||
}).filter(function (policy) { | ||
return policy.applyPoint === applyPoint; | ||
}); | ||
@@ -110,4 +110,4 @@ | ||
return function (done) { | ||
var chain = polices.map(function (police) { | ||
return police(store); | ||
var chain = policies.map(function (policy) { | ||
return policy(store); | ||
}); | ||
@@ -120,8 +120,8 @@ return redux.compose.apply(undefined, chain)(done); | ||
var getActionPolices = function getActionPolices(polices) { | ||
if (Array.isArray(polices)) { | ||
var policeNames = Object.keys(globalPolices).filter(function (key) { | ||
return polices.indexOf(key) >= 0; | ||
var getActionPolicies = function getActionPolicies(policies) { | ||
if (Array.isArray(policies)) { | ||
var policyNames = Object.keys(globalPolicies).filter(function (key) { | ||
return policies.indexOf(key) >= 0; | ||
}); | ||
return get(policeNames); | ||
return get(policyNames); | ||
} | ||
@@ -131,6 +131,6 @@ return get([]); | ||
var polices = { | ||
globalPolices: globalPolices, | ||
var policies = { | ||
globalPolicies: globalPolicies, | ||
register: register, | ||
getActionPolices: getActionPolices, | ||
getActionPolicies: getActionPolicies, | ||
reset: reset | ||
@@ -169,4 +169,4 @@ }; | ||
if (config.polices) { | ||
action.meta.polices = config.polices; | ||
if (config.policies) { | ||
action.meta.policies = config.policies; | ||
} | ||
@@ -253,3 +253,3 @@ | ||
var fieldsToClean = ['polices', 'url', 'method']; | ||
var fieldsToClean = ['policies', 'url', 'method']; | ||
var cleanMeta = function cleanMeta(meta) { | ||
@@ -328,3 +328,3 @@ return Object.keys(meta).filter(function (key) { | ||
var actionPolices = getActionPolices(action.meta.polices); | ||
var actionPolicies = getActionPolicies(action.meta.policies); | ||
var _action$type = action.type, | ||
@@ -335,3 +335,3 @@ requestType = _action$type[0], | ||
var chain = [actionPolices('beforeRequest'), execAsyncTask(requestType, asyncTask), actionPolices('onResponse')].map(function (middleware) { | ||
var chain = [actionPolicies('beforeRequest'), execAsyncTask(requestType, asyncTask), actionPolicies('onResponse')].map(function (middleware) { | ||
return middleware(store); | ||
@@ -348,3 +348,3 @@ }); | ||
exports.asyncActionHelpers = asyncActionHelpers; | ||
exports.polices = polices; | ||
exports.policies = policies; | ||
exports.createApiActions = createApiActions; | ||
@@ -351,0 +351,0 @@ exports.createAsyncMiddleware = createAsyncMiddleware; |
@@ -1,1 +0,1 @@ | ||
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("redux")):"function"==typeof define&&define.amd?define(["exports","redux"],e):e(r.ReduxArc=r.ReduxArc||{},r.Redux)}(this,function(r,e){"use strict";function t(r,e){var t={};for(var n in r)0>e.indexOf(n)&&Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n]);return t}function n(r,e){return"function"==typeof e.modifier?e.modifier(r):r}function o(r,e){var t={};for(var n in r)0>e.indexOf(n)&&Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n]);return t}function i(r,e,t){function i(t){var i=n(t,r)||{},u=i.payload,c=o(i,["payload"]),f={type:[e.REQUEST,e.RESPONSE],meta:E({},c,{url:a(r.url,c),method:r.method})};return u&&(f.payload=u),r.meta&&(f.meta=E({},r.meta,f.meta)),r.schema&&(f.meta.schema=r.schema),r.polices&&(f.meta.polices=r.polices),f}return Object.defineProperty(i,"name",{value:""+t+e.uppercaseName+" apiCreator",writable:!1}),i}function a(r,e){return r.replace(/(:)([A-Za-z0-9]*)/g,function(t,n,o){var i=typeof e[o];if("string"!==i&&"number"!==i)throw Error("Param "+n+" from url "+r+", not found in params object");return e[o]})}function u(r,e){if(Object.keys(r).forEach(function(t){var n=r[t],o=""+(e&&e.prefix)+s(t);if("string"!=typeof n.url)throw Error("Invalid url, "+n.url+", provided for "+o+", it should be a string");if(/:payload*/g.test(n.url))throw Error("Invalid url, "+n.url+", provided for "+o+", you cannot use payload as a param");if("string"!=typeof n.method||!n.method.length)throw Error("Invalid method, "+n.method+", provided for "+o+", it should be a string");if(n.modifier&&"function"!=typeof n.modifier)throw Error("Invalid modifier handler, "+n.modifier+", provided for "+o+", it should be a function")}),e&&e.prefix&&"string"!=typeof e.prefix)throw Error("Invalid prefix provided to options: "+e.prefix+", it should be a string")}function c(r,e){return function(t){return function(n){return function(o){t.dispatch({type:r,meta:A(o.meta)});var i=x({payload:o.payload},o.meta);return e({getState:t.getState})(function(r,e){return r?n(o,r,null):n(o,null,e)})(i)}}}}function f(r){return function(e){return function(t,n,o){var i={type:r,meta:A(t.meta),payload:o};if(n){var a=x({},i,{error:!0});return e.dispatch(a),n}return e.dispatch(i),o}}}var p=Object.assign||function(r){for(var e=1;arguments.length>e;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r},s=function(r){return r.replace(/([A-Z])/g,"_$1").toUpperCase()},d=function(r,e){return r.reduce(function(r,t){var n,o=s(t);return p({},r,(n={},n[t]={uppercaseName:o,REQUEST:""+e+o+"_REQUEST",RESPONSE:""+e+o+"_RESPONSE"},n))},{})},l=function(r,e,t,n){return Object.keys(r).reduce(function(o,i){var a;return p({},o,(a={},a[i]=n(r[i],e[i],t),a))},{})},y=function(r){return Object.keys(r).reduce(function(e,n){var o,i=r[n],a=i.uppercaseName,u=t(i,["uppercaseName"]);return p({},e,(o={},o[a]=u,o))},{})},v={parseToUppercase:s,createTypes:d,parseOptions:n,createCreators:l,reduceActionTypes:y},m=["beforeRequest","onResponse"],h={},b=function(r){return function(t){var n=r.map(function(r){return h[r]}).filter(function(r){return r.applyPoint===t});return function(r){return function(t){var o=n.map(function(e){return e(r)});return e.compose.apply(void 0,o)(t)}}}},O=function(r){if(Array.isArray(r)){var e=Object.keys(h).filter(function(e){return r.indexOf(e)>=0});return b(e)}return b([])},g={globalPolices:h,register:function(r,e){var t;if(h[r])throw Error("Called register with police: "+r+" more than once");if(0>m.indexOf(e.applyPoint)){var n="Invalid applyPoint: "+e.applyPoint+", provided with police: "+r+".",o="The apply points available are: "+m.join(", ");throw Error(n+" "+o)}Object.assign(h,(t={},t[r]=e,t))},getActionPolices:O,reset:function(){Object.keys(h).forEach(function(r){delete h[r]})}},E=Object.assign||function(r){for(var e=1;arguments.length>e;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r},w=function(r){return"string"==typeof r},j=function(r){return 2===r.length&&r.every(w)},x=Object.assign||function(r){for(var e=1;arguments.length>e;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r},P=["polices","url","method"],A=function(r){return Object.keys(r).filter(function(r){return 0>P.indexOf(r)}).reduce(function(e,t){var n;return x({},e,(n={},n[t]=r[t],n))},{})};r.asyncActionHelpers=v,r.polices=g,r.createApiActions=function(r,e){u(r,e);var t=Object.keys(r),n=d(t,e&&e.prefix);return{creators:l(r,n,e.prefix,i),types:y(n)}},r.createAsyncMiddleware=function(r){if("function"!=typeof r)throw Error("You must provide a asyncTask function to createAsyncMiddleware, with the following signature: \n done => (action, error, response) => done(action, error, response)");return function(t){return function(n){return function(o){var i=o.type,a=o.meta;if(!Array.isArray(i))return n(o);if(!j(i))throw Error("Expected type to be an array of two strings, request and response.");if(!a||"object"!=typeof a)throw Error("Expected meta to be an object");var u=O(o.meta.polices),p=o.type,s=p[0],d=p[1],l=[u("beforeRequest"),c(s,r),u("onResponse")].map(function(r){return r(t)}),y=f(d)(t);return e.compose.apply(void 0,l)(y)(o)}}}},Object.defineProperty(r,"__esModule",{value:!0})}); | ||
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("redux")):"function"==typeof define&&define.amd?define(["exports","redux"],e):e(r.ReduxArc=r.ReduxArc||{},r.Redux)}(this,function(r,e){"use strict";function t(r,e){var t={};for(var n in r)0>e.indexOf(n)&&Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n]);return t}function n(r,e){return"function"==typeof e.modifier?e.modifier(r):r}function o(r,e){var t={};for(var n in r)0>e.indexOf(n)&&Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n]);return t}function i(r,e,t){function i(t){var i=n(t,r)||{},u=i.payload,c=o(i,["payload"]),f={type:[e.REQUEST,e.RESPONSE],meta:E({},c,{url:a(r.url,c),method:r.method})};return u&&(f.payload=u),r.meta&&(f.meta=E({},r.meta,f.meta)),r.schema&&(f.meta.schema=r.schema),r.policies&&(f.meta.policies=r.policies),f}return Object.defineProperty(i,"name",{value:""+t+e.uppercaseName+" apiCreator",writable:!1}),i}function a(r,e){return r.replace(/(:)([A-Za-z0-9]*)/g,function(t,n,o){var i=typeof e[o];if("string"!==i&&"number"!==i)throw Error("Param "+n+" from url "+r+", not found in params object");return e[o]})}function u(r,e){if(Object.keys(r).forEach(function(t){var n=r[t],o=""+(e&&e.prefix)+s(t);if("string"!=typeof n.url)throw Error("Invalid url, "+n.url+", provided for "+o+", it should be a string");if(/:payload*/g.test(n.url))throw Error("Invalid url, "+n.url+", provided for "+o+", you cannot use payload as a param");if("string"!=typeof n.method||!n.method.length)throw Error("Invalid method, "+n.method+", provided for "+o+", it should be a string");if(n.modifier&&"function"!=typeof n.modifier)throw Error("Invalid modifier handler, "+n.modifier+", provided for "+o+", it should be a function")}),e&&e.prefix&&"string"!=typeof e.prefix)throw Error("Invalid prefix provided to options: "+e.prefix+", it should be a string")}function c(r,e){return function(t){return function(n){return function(o){t.dispatch({type:r,meta:A(o.meta)});var i=x({payload:o.payload},o.meta);return e({getState:t.getState})(function(r,e){return r?n(o,r,null):n(o,null,e)})(i)}}}}function f(r){return function(e){return function(t,n,o){var i={type:r,meta:A(t.meta),payload:o};if(n){var a=x({},i,{error:!0});return e.dispatch(a),n}return e.dispatch(i),o}}}var p=Object.assign||function(r){for(var e=1;arguments.length>e;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r},s=function(r){return r.replace(/([A-Z])/g,"_$1").toUpperCase()},d=function(r,e){return r.reduce(function(r,t){var n,o=s(t);return p({},r,(n={},n[t]={uppercaseName:o,REQUEST:""+e+o+"_REQUEST",RESPONSE:""+e+o+"_RESPONSE"},n))},{})},l=function(r,e,t,n){return Object.keys(r).reduce(function(o,i){var a;return p({},o,(a={},a[i]=n(r[i],e[i],t),a))},{})},y=function(r){return Object.keys(r).reduce(function(e,n){var o,i=r[n],a=i.uppercaseName,u=t(i,["uppercaseName"]);return p({},e,(o={},o[a]=u,o))},{})},v={parseToUppercase:s,createTypes:d,parseOptions:n,createCreators:l,reduceActionTypes:y},m=["beforeRequest","onResponse"],h={},b=function(r){return function(t){var n=r.map(function(r){return h[r]}).filter(function(r){return r.applyPoint===t});return function(r){return function(t){var o=n.map(function(e){return e(r)});return e.compose.apply(void 0,o)(t)}}}},O=function(r){if(Array.isArray(r)){var e=Object.keys(h).filter(function(e){return r.indexOf(e)>=0});return b(e)}return b([])},g={globalPolicies:h,register:function(r,e){var t;if(h[r])throw Error("Called register with policy: "+r+" more than once");if(0>m.indexOf(e.applyPoint)){var n="Invalid applyPoint: "+e.applyPoint+", provided with policy: "+r+".",o="The apply points available are: "+m.join(", ");throw Error(n+" "+o)}Object.assign(h,(t={},t[r]=e,t))},getActionPolicies:O,reset:function(){Object.keys(h).forEach(function(r){delete h[r]})}},E=Object.assign||function(r){for(var e=1;arguments.length>e;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r},w=function(r){return"string"==typeof r},j=function(r){return 2===r.length&&r.every(w)},x=Object.assign||function(r){for(var e=1;arguments.length>e;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r},P=["policies","url","method"],A=function(r){return Object.keys(r).filter(function(r){return 0>P.indexOf(r)}).reduce(function(e,t){var n;return x({},e,(n={},n[t]=r[t],n))},{})};r.asyncActionHelpers=v,r.policies=g,r.createApiActions=function(r,e){u(r,e);var t=Object.keys(r),n=d(t,e&&e.prefix);return{creators:l(r,n,e.prefix,i),types:y(n)}},r.createAsyncMiddleware=function(r){if("function"!=typeof r)throw Error("You must provide a asyncTask function to createAsyncMiddleware, with the following signature: \n done => (action, error, response) => done(action, error, response)");return function(t){return function(n){return function(o){var i=o.type,a=o.meta;if(!Array.isArray(i))return n(o);if(!j(i))throw Error("Expected type to be an array of two strings, request and response.");if(!a||"object"!=typeof a)throw Error("Expected meta to be an object");var u=O(o.meta.policies),p=o.type,s=p[0],d=p[1],l=[u("beforeRequest"),c(s,r),u("onResponse")].map(function(r){return r(t)}),y=f(d)(t);return e.compose.apply(void 0,l)(y)(o)}}}},Object.defineProperty(r,"__esModule",{value:!0})}); |
@@ -42,4 +42,4 @@ 'use strict'; | ||
if (config.polices) { | ||
action.meta.polices = config.polices; | ||
if (config.policies) { | ||
action.meta.policies = config.policies; | ||
} | ||
@@ -46,0 +46,0 @@ |
'use strict'; | ||
exports.__esModule = true; | ||
exports.createAsyncMiddleware = exports.createApiActions = exports.polices = exports.asyncActionHelpers = undefined; | ||
exports.createAsyncMiddleware = exports.createApiActions = exports.policies = exports.asyncActionHelpers = undefined; | ||
@@ -10,5 +10,5 @@ var _asyncActionHelpers = require('./asyncActionHelpers'); | ||
var _polices = require('./polices'); | ||
var _policies = require('./policies'); | ||
var _polices2 = _interopRequireDefault(_polices); | ||
var _policies2 = _interopRequireDefault(_policies); | ||
@@ -22,4 +22,4 @@ var _apiActionCreator = require('./apiActionCreator'); | ||
exports.asyncActionHelpers = _asyncActionHelpers2['default']; | ||
exports.polices = _polices2['default']; | ||
exports.policies = _policies2['default']; | ||
exports.createApiActions = _apiActionCreator.createApiActions; | ||
exports.createAsyncMiddleware = _middleware.createAsyncMiddleware; |
@@ -13,3 +13,3 @@ 'use strict'; | ||
var _polices = require('./polices'); | ||
var _policies = require('./policies'); | ||
@@ -32,3 +32,3 @@ /** | ||
var fieldsToClean = ['polices', 'url', 'method']; | ||
var fieldsToClean = ['policies', 'url', 'method']; | ||
var cleanMeta = function cleanMeta(meta) { | ||
@@ -107,3 +107,3 @@ return Object.keys(meta).filter(function (key) { | ||
var actionPolices = (0, _polices.getActionPolices)(action.meta.polices); | ||
var actionPolicies = (0, _policies.getActionPolicies)(action.meta.policies); | ||
var _action$type = action.type, | ||
@@ -114,3 +114,3 @@ requestType = _action$type[0], | ||
var chain = [actionPolices('beforeRequest'), execAsyncTask(requestType, asyncTask), actionPolices('onResponse')].map(function (middleware) { | ||
var chain = [actionPolicies('beforeRequest'), execAsyncTask(requestType, asyncTask), actionPolicies('onResponse')].map(function (middleware) { | ||
return middleware(store); | ||
@@ -117,0 +117,0 @@ }); |
{ | ||
"name": "redux-arc", | ||
"version": "0.1.4", | ||
"version": "0.1.6", | ||
"description": "Declarative way to make api calls in redux", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
# Arc | ||
Arc is a dependency free, 2kb lib to handle async requests in redux. | ||
[](https://travis-ci.org/viniciusdacal/redux-arc) [[](https://www.npmjs.com/package/redux-arc) | ||
[](https://travis-ci.org/viniciusdacal/redux-arc) [](https://www.npmjs.com/package/redux-arc) | ||
## Why | ||
Many applications are built with react and redux. Api calls are critical to this process. With the available alternatives (sagas, observables, etc...), you end up writing and repeating to much code. | ||
Many applications are built with react and redux, and api calls are critical to this process. With the available alternatives, you end up writing and repeating code a lot. | ||
@@ -32,4 +32,6 @@ With a declarative way, you can write less code and make it easier to understand and maintain. All of it leads you to have less bugs and have a better code base. This is powerful and flexible. **We make things easier for you for the most common cases, and we allow you to take full control when you need!** | ||
//provide the params for the url | ||
dispatch(creators.read({ id: '123' })); | ||
//provide the payload for your request | ||
dispatch(creators.create({ payload: { name: 'John Doe' } })); | ||
@@ -146,23 +148,23 @@ | ||
# Polices | ||
We know there are sometimes when you need perform operations changing a request or response. For those cases, you can use polices. | ||
We know there are sometimes when you need perform operations changing a request or response. For those cases, you can use policies. | ||
A police is basically another middleware, as the follow example: | ||
A policy is basically another middleware, as the follow example: | ||
```js | ||
const police store => done => (action, error, response) => | ||
const policy store => done => (action, error, response) => | ||
done(action, error, response); | ||
``` | ||
A police must have an applyPoint attribute, so: | ||
A policy must have an applyPoint attribute, so: | ||
```js | ||
police.applyPoint = 'beforeRequest' // (beforeRequest, onResponse) | ||
policy.applyPoint = 'beforeRequest' // (beforeRequest, onResponse) | ||
``` | ||
You can imagine, in the cases your police has an applyPoint `'beforeRequest'`, you would only have access to `action` object, unless another police create and `error` or `response` in the ``beforeRequest` chain. | ||
You can imagine, in the cases your policy has an applyPoint `'beforeRequest'`, you would only have access to `action` object, unless another policy create and `error` or `response` in the ``beforeRequest` chain. | ||
To use a police, you do as the follow: | ||
To use a policy, you do as the follow: | ||
```js | ||
import { createApiActions, polices } from 'redux-arc'; | ||
import { createApiActions, policies } from 'redux-arc'; | ||
@@ -174,3 +176,3 @@ const { creators, types } = createApiActions( | ||
method: 'put', | ||
polices: ['omitId'], // define polices in your config. | ||
policies: ['omitId'], // define policies in your config. | ||
}, | ||
@@ -181,3 +183,3 @@ }, | ||
// this is the police | ||
// this is the policy | ||
function omitId(options) { | ||
@@ -191,4 +193,4 @@ return store => done => (action, ...params) => { | ||
// you must register your police using polices.register, passing the name and the police. | ||
polices.register('omitId', omitId); | ||
// you must register your policy using policies.register, passing the name and the policy. | ||
policies.register('omitId', omitId); | ||
@@ -200,3 +202,3 @@ ``` | ||
The best way to use a police, is defining it in the action creators config, as we saw above, but if you **need**, you can provide polices when you are calling the action creator, just like this: | ||
The best way to use a policy, is defining it in the action creators config, as we saw above, but if you **need**, you can provide policies when you are calling the action creator, just like this: | ||
@@ -206,3 +208,3 @@ ```js | ||
id: '123', | ||
polices: ['omitId'], | ||
policies: ['omitId'], | ||
})); | ||
@@ -209,0 +211,0 @@ ``` |
@@ -33,4 +33,4 @@ import { | ||
if (config.polices) { | ||
action.meta.polices = config.polices; | ||
if (config.policies) { | ||
action.meta.policies = config.policies; | ||
} | ||
@@ -37,0 +37,0 @@ |
import asyncActionHelpers from './asyncActionHelpers' | ||
import polices from './polices' | ||
import policies from './policies' | ||
import { createApiActions } from './apiActionCreator' | ||
@@ -8,5 +8,5 @@ import { createAsyncMiddleware } from './middleware' | ||
asyncActionHelpers, | ||
polices, | ||
policies, | ||
createApiActions, | ||
createAsyncMiddleware, | ||
}; |
import { checkAction } from './helpers'; | ||
import { compose } from 'redux'; | ||
import { getActionPolices } from './polices'; | ||
import { getActionPolicies } from './policies'; | ||
@@ -21,3 +21,3 @@ /** | ||
const fieldsToClean = ['polices', 'url', 'method'] | ||
const fieldsToClean = ['policies', 'url', 'method'] | ||
const cleanMeta = (meta) => Object.keys(meta) | ||
@@ -84,9 +84,9 @@ .filter((key) => fieldsToClean.indexOf(key) < 0) | ||
const actionPolices = getActionPolices(action.meta.polices); | ||
const actionPolicies = getActionPolicies(action.meta.policies); | ||
const [requestType, responseType] = action.type; | ||
const chain = [ | ||
actionPolices('beforeRequest'), | ||
actionPolicies('beforeRequest'), | ||
execAsyncTask(requestType, asyncTask), | ||
actionPolices('onResponse'), | ||
actionPolicies('onResponse'), | ||
].map(middleware => middleware(store)); | ||
@@ -93,0 +93,0 @@ |
52148
209