redux-zero
Advanced tools
Comparing version 4.10.1 to 4.11.0
# Changelog | ||
### 4.11.0 | ||
- Add `combineActions` function | ||
```js | ||
import { combineActions } from 'redux-zero/utils'; | ||
``` | ||
### 4.10.1 | ||
@@ -4,0 +12,0 @@ |
{ | ||
"name": "redux-zero", | ||
"version": "4.10.1", | ||
"version": "4.11.0", | ||
"description": "", | ||
@@ -13,4 +13,6 @@ "main": "dist/redux-zero.js", | ||
"test:watch": "jest --watch", | ||
"format": "prettier --write --no-semi \"src/**/*.ts\" \"src/**/*.tsx\"", | ||
"check": "npm run compile && npm run format && npm run lint && npm run test", | ||
"format": | ||
"prettier --write rollup.config.js \"config/**/*.js\" \"src/**/*.ts\" \"src/**/*.tsx\"", | ||
"check": | ||
"npm run compile && npm run format && npm run lint && npm run test", | ||
"clean": "rimraf dist coverage", | ||
@@ -44,16 +46,8 @@ "prebuild": "npm run check && npm run clean", | ||
"jest": { | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"tsx", | ||
"js" | ||
], | ||
"setupFiles": [ | ||
"<rootDir>/config/testSetup.js" | ||
], | ||
"moduleFileExtensions": ["ts", "tsx", "js"], | ||
"setupFiles": ["<rootDir>/config/testSetup.js"], | ||
"transform": { | ||
"^.+\\.(ts|tsx)$": "<rootDir>/config/preprocessor.js" | ||
}, | ||
"testMatch": [ | ||
"<rootDir>/src/**/*.spec.(ts|tsx)" | ||
] | ||
"testMatch": ["<rootDir>/src/**/*.spec.(ts|tsx)"] | ||
}, | ||
@@ -60,0 +54,0 @@ "devDependencies": { |
@@ -11,7 +11,8 @@ <h1 align="center"> | ||
[![build](https://img.shields.io/travis/concretesolutions/redux-zero/master.svg?style=flat-square)](https://travis-ci.org/concretesolutions/redux-zero) | ||
[![npm](https://img.shields.io/npm/v/redux-zero.svg?style=flat-square)](https://www.npmjs.com/package/redux-zero) | ||
[![downloads](https://img.shields.io/npm/dm/redux-zero.svg?style=flat-square)](https://www.npmjs.com/package/redux-zero) | ||
[![license](https://img.shields.io/github/license/concretesolutions/redux-zero.svg?style=flat-square)]() | ||
[![dependencies](https://img.shields.io/david/concretesolutions/redux-zero.svg?style=flat-square)]() | ||
[![codacy](https://api.codacy.com/project/badge/Grade/a4adf13156bd4441ae132d2d9dc72186)](https://www.codacy.com/app/matheusml/redux-zero?utm_source=github.com&utm_medium=referral&utm_content=concretesolutions/redux-zero&utm_campaign=Badge_Grade) | ||
[![build](https://img.shields.io/travis/concretesolutions/redux-zero/master.svg)](https://travis-ci.org/concretesolutions/redux-zero) | ||
[![npm](https://img.shields.io/npm/v/redux-zero.svg)](https://www.npmjs.com/package/redux-zero) | ||
[![downloads](https://img.shields.io/npm/dm/redux-zero.svg)](https://www.npmjs.com/package/redux-zero) | ||
[![license](https://img.shields.io/github/license/concretesolutions/redux-zero.svg)]() | ||
[![dependencies](https://img.shields.io/david/concretesolutions/redux-zero.svg)]() | ||
@@ -24,2 +25,3 @@ | ||
- [Example](#example) | ||
- [Actions](#actions) | ||
- [Async](#async) | ||
@@ -163,2 +165,3 @@ - [Middleware](#middleware) | ||
- [React-Router](https://github.com/concretesolutions/redux-zero/tree/master/examples/react/react-router) | ||
- [Material-UI](https://github.com/concretesolutions/redux-zero/tree/master/examples/react/material-ui-counter) | ||
- [Preact](https://github.com/concretesolutions/redux-zero/tree/master/examples/preact/counter) | ||
@@ -170,2 +173,72 @@ - [React Native](https://github.com/concretesolutions/redux-zero/tree/master/examples/react-native/counter) | ||
## Actions | ||
There are tree gotchas with Redux Zero's actions: | ||
- Passing arguments | ||
- Combining actions | ||
- Binding actions outside your application scope | ||
### Passing arguments | ||
Here's how you can pass arguments to actions: | ||
```js | ||
const Component = ({ count, incrementOf }) => ( | ||
<h1 onClick={() => incrementOf(10)}>{count}</h1> | ||
) | ||
const mapToProps = ({ count }) => ({ count }) | ||
const actions = store => ({ | ||
incrementOf: (state, value) => ({ count: state.count + value }) | ||
}) | ||
const ConnectedComponent = connect(mapToProps, actions)(Component) | ||
const App = () => ( | ||
<Provider store={store}> | ||
<ConnectedComponent /> | ||
</Provider> | ||
) | ||
``` | ||
### Combining actions | ||
There's an utility function to combine actions on Redux Zero: | ||
```js | ||
import { connect } from "redux-zero/react"; | ||
import { combineActions } from "redux-zero/utils"; | ||
import Component from "./Component"; | ||
import firstActions from "../../actions/firstActions"; | ||
import secondActions from "../../actions/secondActions"; | ||
export default connect( | ||
({ params, moreParams }) => ({ params, moreParams }), | ||
combineActions(firstActions, secondActions) | ||
)(Component); | ||
``` | ||
### Binding actions outside your application scope | ||
If you need to bind the actions to an external listener outside the application scope, here's a simple way to do it: | ||
On this example we listen to push notifications that sends data to our React Native app. | ||
```js | ||
import firebase from 'react-native-firebase'; | ||
import { bindActions } from 'redux-zero/utils'; | ||
import store from '../store'; | ||
import actions from '../actions'; | ||
const messaging = firebase.messaging(); | ||
const boundActions = bindActions(actions, store); | ||
messaging.onMessage((payload) => { | ||
boundActions.saveMessage(payload); | ||
}); | ||
``` | ||
## Async | ||
@@ -172,0 +245,0 @@ |
import bindActions from "./bindActions"; | ||
export { bindActions }; | ||
import combineActions from "./combineActions"; | ||
export { bindActions, combineActions }; |
@@ -35,2 +35,43 @@ 'use strict'; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
var __assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
var combineActions = function () { | ||
var actions = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
actions[_i] = arguments[_i]; | ||
} | ||
return function () { | ||
var actionsParams = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
actionsParams[_i] = arguments[_i]; | ||
} | ||
return actions.reduce(function (acc, action) { return (__assign({}, acc, typeof action === "function" ? action.apply(void 0, actionsParams) : action)); }, {}); | ||
}; | ||
}; | ||
exports.bindActions = bindActions; | ||
exports.combineActions = combineActions; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e["redux-zero"]={})}(this,function(e){"use strict";function t(e,t){if(null!=t){if(t.then)return t.then(e.setState);e.setState(t)}}e.bindActions=function(e,n){e="function"==typeof e?e(n):e;var o={};for(var i in e)!function(i){o[i]=function(){for(var o=[],f=0;f<arguments.length;f++)o[f]=arguments[f];var r=e[i];return"function"==typeof n.middleware?n.middleware(n,r,o):t(n,r.apply(void 0,[n.getState()].concat(o)))}}(i);return o},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e["redux-zero"]={})}(this,function(e){"use strict";function t(e,t){if(null!=t){if(t.then)return t.then(e.setState);e.setState(t)}}var n=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++){t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e};e.bindActions=function(e,n){e="function"==typeof e?e(n):e;var o={};for(var r in e)!function(r){o[r]=function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];var f=e[r];return"function"==typeof n.middleware?n.middleware(n,f,o):t(n,f.apply(void 0,[n.getState()].concat(o)))}}(r);return o},e.combineActions=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(){for(var t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];return e.reduce(function(e,o){return n({},e,"function"==typeof o?o.apply(void 0,t):o)},{})}},Object.defineProperty(e,"__esModule",{value:!0})}); |
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
62543
45
904
346