-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ (payloadWrapper) helpers to wrappe middlewar
- Loading branch information
1 parent
3dd13fd
commit c286384
Showing
8 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,5 @@ | ||
{ | ||
"name": "trampss-redux-factory/helpers", | ||
"private": true, | ||
"main": "../helpers.js" | ||
} |
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,27 @@ | ||
import path from 'path' | ||
import fs from 'fs' | ||
import babel from 'rollup-plugin-babel' | ||
import commonjs from 'rollup-plugin-commonjs' | ||
import uglify from 'rollup-plugin-uglify' | ||
|
||
const pkg = JSON.parse(fs.readFileSync('./package.json')) | ||
const external = [ | ||
...Object.keys(pkg.dependencies || {}), | ||
...Object.keys(pkg.peerDependencies || {}), | ||
] | ||
|
||
export default { | ||
entry: pkg['jsnext:main'] || `src/${pkg.helpers}`, | ||
dest: pkg.helpers, | ||
sourceMap: path.resolve(pkg.helpers), | ||
moduleName: pkg.amdName || pkg.name, | ||
format: process.env.FORMAT || 'umd', | ||
external, | ||
plugins: [ | ||
babel(), | ||
commonjs({ | ||
include: 'node_modules/**', | ||
}), | ||
uglify(), | ||
], | ||
} |
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,41 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`helpers/payloadWrapper should not wrappe without wrapper function 1`] = ` | ||
Object { | ||
"action": Object { | ||
"payload": "payload", | ||
"type": "TYPE", | ||
}, | ||
"state": Object {}, | ||
} | ||
`; | ||
|
||
exports[`helpers/payloadWrapper should wrappe payload 1`] = ` | ||
Object { | ||
"action": Object { | ||
"payload": "PAYLOAD WRAPPED !", | ||
"type": "TYPE", | ||
}, | ||
"state": Object {}, | ||
} | ||
`; | ||
|
||
exports[`helpers/payloadWrapper should wrappe without type 1`] = ` | ||
Object { | ||
"action": Object { | ||
"payload": "PAYLOAD WRAPPED !", | ||
"type": "TYPE", | ||
}, | ||
"state": Object {}, | ||
} | ||
`; | ||
|
||
exports[`helpers/payloadWrapper should wrappe without type and wrapper function 1`] = ` | ||
Object { | ||
"action": Object { | ||
"payload": "payload", | ||
"type": "TYPE", | ||
}, | ||
"state": Object {}, | ||
} | ||
`; |
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,13 @@ | ||
export const payloadWrapper = actionMatches => wrapper => () => () => (ctx) => { | ||
const { payload, type } = ctx.action | ||
if (!actionMatches || actionMatches.test(type)) { | ||
return { | ||
...ctx, | ||
action: { | ||
...ctx.action, | ||
payload: wrapper ? wrapper(payload) : payload, | ||
}, | ||
} | ||
} | ||
return ctx | ||
} |
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,20 @@ | ||
/* eslint-env jest */ | ||
import { payloadWrapper } from './helpers' | ||
|
||
const ctx = { | ||
action: { | ||
payload: 'payload', | ||
type: 'TYPE', | ||
}, | ||
state: {}, | ||
} | ||
|
||
const actionMatches = /TYPE/ | ||
const wrapper = () => 'PAYLOAD WRAPPED !' | ||
|
||
describe('helpers/payloadWrapper', () => { | ||
it('should wrappe without type and wrapper function', () => expect(payloadWrapper()()()()(ctx)).toMatchSnapshot()) | ||
it('should not wrappe without wrapper function', () => expect(payloadWrapper(actionMatches)()()()(ctx)).toMatchSnapshot()) | ||
it('should wrappe without type', () => expect(payloadWrapper()(wrapper)()()(ctx)).toMatchSnapshot()) | ||
it('should wrappe payload', () => expect(payloadWrapper(actionMatches)(wrapper)()()(ctx)).toMatchSnapshot()) | ||
}) |