reffects-batteries
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -95,3 +95,3 @@ import { registerEffectHandler, registerCoeffectHandler, coeffect, dispatch } from 'reffects'; | ||
function httpGet({ url, successEvent, errorEvent = []}) { | ||
function httpGet({ url, successEvent, errorEvent = [], config}) { | ||
return { | ||
@@ -101,3 +101,4 @@ 'http.get': { | ||
successEvent: adaptEvent(successEvent), | ||
errorEvent: adaptEvent(errorEvent) | ||
errorEvent: adaptEvent(errorEvent), | ||
config, | ||
} | ||
@@ -150,2 +151,3 @@ }; | ||
errorEvent = [], | ||
config = {}, | ||
}) { | ||
@@ -160,2 +162,3 @@ httpClient.get({ | ||
}, | ||
config | ||
}); | ||
@@ -162,0 +165,0 @@ }); |
@@ -99,3 +99,3 @@ 'use strict'; | ||
function httpGet({ url, successEvent, errorEvent = []}) { | ||
function httpGet({ url, successEvent, errorEvent = [], config}) { | ||
return { | ||
@@ -105,3 +105,4 @@ 'http.get': { | ||
successEvent: adaptEvent(successEvent), | ||
errorEvent: adaptEvent(errorEvent) | ||
errorEvent: adaptEvent(errorEvent), | ||
config, | ||
} | ||
@@ -154,2 +155,3 @@ }; | ||
errorEvent = [], | ||
config = {}, | ||
}) { | ||
@@ -164,2 +166,3 @@ httpClient.get({ | ||
}, | ||
config | ||
}); | ||
@@ -166,0 +169,0 @@ }); |
@@ -99,3 +99,3 @@ (function (global, factory) { | ||
function httpGet({ url, successEvent, errorEvent = []}) { | ||
function httpGet({ url, successEvent, errorEvent = [], config}) { | ||
return { | ||
@@ -105,3 +105,4 @@ 'http.get': { | ||
successEvent: adaptEvent(successEvent), | ||
errorEvent: adaptEvent(errorEvent) | ||
errorEvent: adaptEvent(errorEvent), | ||
config, | ||
} | ||
@@ -154,2 +155,3 @@ }; | ||
errorEvent = [], | ||
config = {}, | ||
}) { | ||
@@ -164,2 +166,3 @@ httpClient.get({ | ||
}, | ||
config | ||
}); | ||
@@ -166,0 +169,0 @@ }); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("reffects")):"function"==typeof define&&define.amd?define(["exports","reffects"],t):t((e=e||self)["reffects-batteries"]={},e.reffects)}(this,(function(e,t){"use strict";function r(e){t.registerEffectHandler("cookie.set",(function(t){e.set(t)}))}function n(e){t.registerCoeffectHandler("cookie",(function(t){return{cookie:{[t]:e.get(t)}}}))}const o=r,c=n;const s="globals";function u(e,t,r=null){return void 0===t?r:function(e){return Array.isArray(e)?e:e.split(".")}(t).reduce((e,t)=>e&&e[t],e)}function i(e=window){t.registerCoeffectHandler(s,(function(t){return{[s]:{[t]:u(e,t)}}}))}const f=i,a={get:function(e){return t.coeffect(s,e)}};function l(e){return Array.isArray(e)?e:"string"==typeof e?[e]:e.payload?[e.id,e.payload]:[e.id]}const d={get:function({url:e,successEvent:t,errorEvent:r=[]}){return{"http.get":{url:e,successEvent:l(t),errorEvent:l(r)}}},post:function({url:e,body:t,config:r={},successEvent:n=[],errorEvent:o=[],alwaysEvent:c=[]}){return{"http.post":{url:e,body:t,config:r,successEvent:l(n),errorEvent:l(o),alwaysEvent:l(c)}}},put:function({url:e,body:t,successEvent:r=[],errorEvent:n=[]}){return{"http.put":{url:e,body:t,successEvent:l(r),errorEvent:l(n)}}},patch:function({url:e,body:t,successEvent:r=[],errorEvent:n=[]}){return{"http.patch":{url:e,body:t,successEvent:l(r),errorEvent:l(n)}}}};function p(e){t.registerCoeffectHandler("queryParams",(function(t=[]){const r=new URLSearchParams(e.location.search);return{queryParams:t.reduce((function(e,t){const n=r.getAll(t).map((function(e){return decodeURIComponent(e)}));return Object.assign({},e,0===n.length?{[t]:null}:1===n.length?{[t]:n[0]}:{[t]:n})}),{})}}))}const g=p,y={get:function(e){return t.coeffect("queryParams",e)}};e.cookies={get:function(e){return t.coeffect("cookie",e)},set:function(e){return{"cookie.set":e}}},e.globals=a,e.http=d,e.queryParams=y,e.registerCookiesBatteries=function(e){r(e),n(e)},e.registerGetCookieCoeffect=c,e.registerGlobalBatteries=function(e){i(e)},e.registerGlobalCoeffect=f,e.registerHttpBatteries=function(e){!function(e,r=t.dispatch){function n(e,...t){if(!e)return;const[n,...o]=e;r({id:n,payload:t.concat(o)})}t.registerEffectHandler("http.get",(function({url:t,successEvent:r=[],errorEvent:o=[]}){e.get({url:t,successFn(e){n(r,e)},errorFn(e){n(o,e)}})})),t.registerEffectHandler("http.post",(function({url:t,body:r,config:o={},successEvent:c,errorEvent:s,alwaysEvent:u}){e.post({url:t,body:r,config:o,successFn(e){n(c,e)},errorFn(e){n(s,e)},alwaysFn(){n(u)}})})),t.registerEffectHandler("http.put",(function({url:t,body:r,successEvent:o=[],errorEvent:c=[]}){e.put({url:t,body:r,successFn(e){n(o,e)},errorFn(e){n(c,e)}})})),t.registerEffectHandler("http.patch",(function({url:t,body:r,successEvent:o=[],errorEvent:c=[]}){e.patch({url:t,body:r,successFn(e){n(o,e)},errorFn(e){n(c,e)}})}))}(e)},e.registerQueryParamsBatteries=function(e){p(e)},e.registerQueryParamsCoeffect=g,e.registerSetCookieEffect=o,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("reffects")):"function"==typeof define&&define.amd?define(["exports","reffects"],t):t((e=e||self)["reffects-batteries"]={},e.reffects)}(this,(function(e,t){"use strict";function r(e){t.registerEffectHandler("cookie.set",(function(t){e.set(t)}))}function n(e){t.registerCoeffectHandler("cookie",(function(t){return{cookie:{[t]:e.get(t)}}}))}const o=r,c=n;const s="globals";function u(e,t,r=null){return void 0===t?r:function(e){return Array.isArray(e)?e:e.split(".")}(t).reduce((e,t)=>e&&e[t],e)}function i(e=window){t.registerCoeffectHandler(s,(function(t){return{[s]:{[t]:u(e,t)}}}))}const f=i,a={get:function(e){return t.coeffect(s,e)}};function l(e){return Array.isArray(e)?e:"string"==typeof e?[e]:e.payload?[e.id,e.payload]:[e.id]}const d={get:function({url:e,successEvent:t,errorEvent:r=[],config:n}){return{"http.get":{url:e,successEvent:l(t),errorEvent:l(r),config:n}}},post:function({url:e,body:t,config:r={},successEvent:n=[],errorEvent:o=[],alwaysEvent:c=[]}){return{"http.post":{url:e,body:t,config:r,successEvent:l(n),errorEvent:l(o),alwaysEvent:l(c)}}},put:function({url:e,body:t,successEvent:r=[],errorEvent:n=[]}){return{"http.put":{url:e,body:t,successEvent:l(r),errorEvent:l(n)}}},patch:function({url:e,body:t,successEvent:r=[],errorEvent:n=[]}){return{"http.patch":{url:e,body:t,successEvent:l(r),errorEvent:l(n)}}}};function g(e){t.registerCoeffectHandler("queryParams",(function(t=[]){const r=new URLSearchParams(e.location.search);return{queryParams:t.reduce((function(e,t){const n=r.getAll(t).map((function(e){return decodeURIComponent(e)}));return Object.assign({},e,0===n.length?{[t]:null}:1===n.length?{[t]:n[0]}:{[t]:n})}),{})}}))}const p=g,y={get:function(e){return t.coeffect("queryParams",e)}};e.cookies={get:function(e){return t.coeffect("cookie",e)},set:function(e){return{"cookie.set":e}}},e.globals=a,e.http=d,e.queryParams=y,e.registerCookiesBatteries=function(e){r(e),n(e)},e.registerGetCookieCoeffect=c,e.registerGlobalBatteries=function(e){i(e)},e.registerGlobalCoeffect=f,e.registerHttpBatteries=function(e){!function(e,r=t.dispatch){function n(e,...t){if(!e)return;const[n,...o]=e;r({id:n,payload:t.concat(o)})}t.registerEffectHandler("http.get",(function({url:t,successEvent:r=[],errorEvent:o=[],config:c={}}){e.get({url:t,successFn(e){n(r,e)},errorFn(e){n(o,e)},config:c})})),t.registerEffectHandler("http.post",(function({url:t,body:r,config:o={},successEvent:c,errorEvent:s,alwaysEvent:u}){e.post({url:t,body:r,config:o,successFn(e){n(c,e)},errorFn(e){n(s,e)},alwaysFn(){n(u)}})})),t.registerEffectHandler("http.put",(function({url:t,body:r,successEvent:o=[],errorEvent:c=[]}){e.put({url:t,body:r,successFn(e){n(o,e)},errorFn(e){n(c,e)}})})),t.registerEffectHandler("http.patch",(function({url:t,body:r,successEvent:o=[],errorEvent:c=[]}){e.patch({url:t,body:r,successFn(e){n(o,e)},errorFn(e){n(c,e)}})}))}(e)},e.registerQueryParamsBatteries=function(e){g(e)},e.registerQueryParamsCoeffect=p,e.registerSetCookieEffect=o,Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "reffects-batteries", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "", | ||
@@ -16,3 +16,3 @@ "source": "src/index.js", | ||
"jest": "^24.7.1", | ||
"reffects": "^0.1.17", | ||
"reffects": "^0.1.19", | ||
"rollup": "^2.8.1", | ||
@@ -37,3 +37,3 @@ "rollup-plugin-node-resolve": "^5.2.0", | ||
}, | ||
"gitHead": "19147acf8f23230f8aaeeb6e6c988f1d3a3e61f1" | ||
"gitHead": "fb8e6654806ae4dabffcbc01259f5bd989424ad9" | ||
} |
@@ -16,3 +16,3 @@ import { registerEffectHandler, dispatch as reffectsDispatch } from 'reffects'; | ||
export function httpGet({ url, successEvent, errorEvent = []}) { | ||
export function httpGet({ url, successEvent, errorEvent = [], config}) { | ||
return { | ||
@@ -22,3 +22,4 @@ 'http.get': { | ||
successEvent: adaptEvent(successEvent), | ||
errorEvent: adaptEvent(errorEvent) | ||
errorEvent: adaptEvent(errorEvent), | ||
config, | ||
} | ||
@@ -71,2 +72,3 @@ }; | ||
errorEvent = [], | ||
config = {}, | ||
}) { | ||
@@ -81,2 +83,3 @@ httpClient.get({ | ||
}, | ||
config | ||
}); | ||
@@ -83,0 +86,0 @@ }); |
@@ -16,2 +16,3 @@ import { clearHandlers, getEffectHandler } from 'reffects'; | ||
const effectId = 'http.get'; | ||
const config = { headers: { 'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9' } }; | ||
@@ -38,2 +39,3 @@ test('request success', () => { | ||
], | ||
config | ||
}); | ||
@@ -45,2 +47,3 @@ | ||
errorFn: expect.any(Function), | ||
config | ||
}); | ||
@@ -73,2 +76,3 @@ expect(dispatchFake).toHaveBeenCalledTimes(1); | ||
], | ||
config | ||
}); | ||
@@ -80,2 +84,3 @@ | ||
errorFn: expect.any(Function), | ||
config | ||
}); | ||
@@ -88,2 +93,32 @@ expect(dispatchFake).toHaveBeenCalledTimes(1); | ||
test('default config is empty object', () => { | ||
const errorData = 'errorData'; | ||
const fakeHttpClient = { | ||
get: jest.fn().mockImplementation(function get({ errorFn }) { | ||
return errorFn(errorData); | ||
}), | ||
}; | ||
const dispatchFake = jest.fn(); | ||
registerHttpEffect(fakeHttpClient, dispatchFake); | ||
const httpEffectHandler = getEffectHandler(effectId); | ||
const url = 'fakeUrl'; | ||
const errorEventId = 'errorEventId'; | ||
httpEffectHandler({ | ||
url, | ||
errorEvent: [ | ||
errorEventId, | ||
eventRestOfPayload[0], | ||
eventRestOfPayload[1], | ||
], | ||
}); | ||
expect(fakeHttpClient.get).toHaveBeenCalledWith({ | ||
url, | ||
successFn: expect.any(Function), | ||
errorFn: expect.any(Function), | ||
config: {} | ||
}); | ||
}); | ||
test('should create an http.get effect using a builder', () => { | ||
@@ -93,3 +128,4 @@ const httpGetEffect = httpGet({ | ||
successEvent: ['callbackEvent', 'arg1'], | ||
errorEvent: ['failureEvent', 'arg1'] | ||
errorEvent: ['failureEvent', 'arg1'], | ||
config | ||
}); | ||
@@ -101,3 +137,4 @@ | ||
successEvent: ['callbackEvent', 'arg1'], | ||
errorEvent: ['failureEvent', 'arg1'] | ||
errorEvent: ['failureEvent', 'arg1'], | ||
config | ||
} | ||
@@ -112,2 +149,3 @@ }); | ||
errorEvent: { id: 'failureEvent', payload: { arg1: 'arg1' } }, | ||
config | ||
}); | ||
@@ -119,3 +157,4 @@ | ||
successEvent: ['callbackEvent', { arg1: 'arg1' }], | ||
errorEvent: ['failureEvent', { arg1: 'arg1' }] | ||
errorEvent: ['failureEvent', { arg1: 'arg1' }], | ||
config | ||
} | ||
@@ -122,0 +161,0 @@ }); |
Sorry, the diff of this file is not supported yet
71910
1980