Skip to content

Commit

Permalink
Merge pull request #6 from german-p/feature/esm
Browse files Browse the repository at this point in the history
Feature/esm
  • Loading branch information
german-p committed Dec 15, 2020
2 parents 5640850 + 4537f00 commit 2df5442
Show file tree
Hide file tree
Showing 9 changed files with 2,942 additions and 4,177 deletions.
7 changes: 7 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"presets": [["@babel/preset-env", {
"targets": {
"browsers": ["last 2 Chrome versions"]
}
}]]
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.nyc_output
dist
dist
coverage
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ cache: npm
script:
- npm run lint
- npm run build
- npm run coverage
- npm run coveralls
4,150 changes: 0 additions & 4,150 deletions package-lock.json

This file was deleted.

19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
{
"name": "react-redux-async-action",
"version": "1.0.1",
"version": "1.1.0",
"description": "Helper methods for dealing with boilerplate of working with react-redux actions that have an eventual outcome",
"main": "dist/index.js",
"module": "dist/index.js",
"module": "dist/index.es.js",
"files": [
"dist"
],
"sideEffects": false,
"scripts": {
"test": "mocha",
"prebuild": "npm run build:clean",
"test": "mocha --require @babel/register",
"prebuild": "yarn build:clean",
"build:clean": "rimraf ./dist",
"build": "rollup -c",
"coverage": "nyc npm test && nyc report --reporter=text-lcov | coveralls",
"coverage": "nyc --require @babel/register --reporter=text mocha",
"coveralls": "nyc yarn test && nyc report --reporter=text-lcov | coveralls",
"lint": "eslint ./src",
"prepublish": "npm run lint && npm run test && npm run build"
"prepare": "yarn lint && yarn test && yarn build"
},
"keywords": [
"react",
Expand All @@ -28,22 +30,23 @@
"devDependencies": {
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"@babel/register": "^7.12.10",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"coveralls": "^3.0.3",
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.17.3",
"mocha": "^6.1.4",
"mocha-lcov-reporter": "^1.3.0",
"nyc": "^14.1.1",
"regenerator-runtime": "^0.13.7",
"rimraf": "^2.6.3",
"rollup": "^1.13.1",
"rollup-plugin-babel": "^4.3.2",
"sinon": "^7.3.2",
"sinon-chai": "^3.3.0"
},
"dependencies": {},
"directories": {
"test": "test"
},
Expand Down
6 changes: 5 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ A set of helper functions to reduce the boilerplate of working with redux action
## Installation:

```
npm install react-redux-async-action
npm install --save react-redux-async-action
```
```
yarn add react-redux-async-action
```


## Motivation

Expand Down
11 changes: 6 additions & 5 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import babel from 'rollup-plugin-babel';

module.exports = {
input: 'src/index.js',
output: {
file: 'dist/index.js',
output: [{
file: 'dist/index.es.js',
format: 'esm',
},
}, {
file: 'dist/index.js',
format: 'cjs',
}],
plugins: [
babel({
exclude: 'node_modules/**',
babelrc: false,
presets: ['@babel/env'],
}),
],
};
15 changes: 4 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

function appendSuffix(action, suffix, error) {
if (typeof action === 'string') return `${action}_${suffix}`;
if (Reflect.has(action, 'type')) {
Expand All @@ -14,15 +13,15 @@ function appendSuffix(action, suffix, error) {
* @param {string|object} action The action constant or an action object
* @returns {string|object} The success variant of the action constant or object
*/
function success(action) { return appendSuffix(action, 'SUCCESS'); }
export function success(action) { return appendSuffix(action, 'SUCCESS'); }

/**
* Takes an action string constant or action object and returns its failure counterpart
* @param {string|object} action The action constant or an action object
* @param {Error} error The error that caused the failure
* @returns {string|object} The failure variant of the action constant or object
*/
function failure(action, error) { return appendSuffix(action, 'FAILURE', error); }
export function failure(action, error) { return appendSuffix(action, 'FAILURE', error); }

/**
* Creates a redux thunk for an action creator and an async call.
Expand All @@ -38,8 +37,8 @@ function failure(action, error) { return appendSuffix(action, 'FAILURE', error);
* (action, error, dispatch)=> {}
* @returns {function} The redux thunk for the action
*/
function asThunk(actionCreator, asyncCall, afterSuccess, afterFailure) {
return payload => async (dispatch) => {
export function asThunk(actionCreator, asyncCall, afterSuccess, afterFailure) {
return (payload) => async (dispatch) => {
const action = actionCreator(payload);
dispatch(action);
let result;
Expand All @@ -54,9 +53,3 @@ function asThunk(actionCreator, asyncCall, afterSuccess, afterFailure) {
if (afterSuccess) afterSuccess(action, result, dispatch);
};
}

module.exports = {
success,
failure,
asThunk,
};
Loading

0 comments on commit 2df5442

Please sign in to comment.