首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

redux-0.5.3.zip

前端 21.01KB 13 需要积分: 1
立即下载

资源介绍:

一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
React Redux ========================= Official React bindings for [Redux](https://github.com/gaearon/redux). Performant and flexible. [![npm version](https://img.shields.io/npm/v/react-redux.svg?style=flat-square)](https://www.npmjs.com/package/react-redux) [![npm downloads](https://img.shields.io/npm/dm/react-redux.svg?style=flat-square)](https://www.npmjs.com/package/react-redux) [![redux channel on slack](https://img.shields.io/badge/slack-redux@reactiflux-61DAFB.svg?style=flat-square)](http://www.reactiflux.com) >**Note: There is a project called `redux-react` on NPM that is [completely unrelated](https://github.com/cgarvis/redux-react/issues/1) to the official bindings. This documentation (and any other official Redux documentation) is for `react-redux`.** ## Table of Contents - [React Native](#react-native) - [Quick Start](#quick-start) - [API](#api) - [``](#provider-store) - [`connect([mapStateToProps], [mapDispatchToProps], [mergeProps])`](#connectmapstatetoprops-mapdispatchtoprops-mergeprops) - [License](#license) ## React Native What you get from `react-redux` is for React. For React Native, import from `react-redux/native` instead. ## Quick Start React bindings for Redux embrace the idea of [dividing “smart” and “dumb” components](https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0). It is advisable that only top-level components of your app (such as route handlers, for example) are aware of Redux. Components below them should be “dumb” and receive all data via props.
Location Use React-Redux To read data, they To change data, they
“Smart” Components Top level, route handlers Yes Subscribe to Redux state Dispatch Redux actions
“Dumb” Components Middle and leaf components No Read data from props Invoke callbacks from props
### “Dumb” component is unaware of Redux Let’s say we have a `` “dumb” component with a number `value` prop, and an `onIncrement` function prop that it will call when user presses an “Increment” button: ```js import { Component } from 'react'; export default class Counter extends Component { render() { return ( ); } } ``` ### “Smart” component is `connect()`-ed to Redux Here’s how we hook it up to the Redux Store. We will use `connect()` function provided by `react-redux` to turn a “dumb” `Counter` into a smart component. The `connect()` function lets you specify *which exactly* state from the Redux store your component wants to track. This lets you subscribe on any level of granularity. ##### `containers/CounterContainer.js` ```js import { Component } from 'react'; import { connect } from 'react-redux'; import Counter from '../components/Counter'; import { increment } from '../actionsCreators'; // Which part of the Redux global state does our component want to receive as props? function mapStateToProps(state) { return { value: state.counter }; } // Which action creators does it want to receive by props? function mapDispatchToProps(dispatch) { return { onIncrement: () => dispatch(increment()) }; } export default connect( mapStateToProps, mapDispatchToProps )(Counter); // You can also pass an object instead of defining `mapDispatchToProps`: // export default connect(mapStateToProps, CounterActionCreators)(Counter); // Or you can pass `dispatch` down as a prop if you omit `mapDispatchToProps`: // export default connect(mapStateToProps)(Counter); // See more recipes in detailed connect() examples below. ``` Whether to put `connect()` call in the same file as the “dumb” component, or separately, is up to you. Ask yourself whether you'd want to reuse this component but bind it to different data, or not. ### Nesting You can have many `connect()`-ed components in your app at any depth, and you can even nest them. It is however preferable that you try to only `connect()` top-level components such as route handlers, so the data flow in your application stays predictable. ### Support for Decorators You might have noticed that we used parens twice. This is called partial applications, and it lets people use ES7 decorator proposal syntax: ```js // Unstable syntax! It might change or break in production. @connect(mapStateToProps) export default class CounterContainer { ... } ``` Don’t forget decorators are experimental! And they desugar to function calls anyway as example above demonstrates. ### Additional Flexibility This the most basic usage, but `connect()` supports many other different patterns: just passing the vanilla `dispatch()` function down, binding multiple action creators, putting them as `actions` prop, selecting parts of state and binding action creators depending on `props`, and so on. Check out `connect()` docs below to learn more. ### Injecting Redux Store Finally, how do we actually hook it up to a Redux store? We need to create the store somewhere at the root of our component hierarchy. For client apps, the root component is a good place. For server rendering, you can do this in the request handler. The trick is to wrap the whole view hierarchy into `{() => ... }` where `Provider` is imported from `react-redux`. One gotcha is that **the child of `Provider` must be a function**. This is to work around an issue with how context (undocumented feature we have to rely on to pass Redux data to components below) works in React 0.13. In React 0.14, you will be able to put your view hierarchy in `` without wrapping it into a function. ```js import { Component } from 'react'; import { Provider } from 'react-redux'; class App extends Component { render() { // ... } } const targetEl = document.getElementById('root'); React.render(( {() => } ), targetEl); ``` ## API ### `` Makes Redux store available to the `connect()` calls in the component hierarchy below. You can’t use `connect()` without wrapping the root component in ``. #### Props * `store`: (*[Redux Store](http://gaearon.github.io/redux/docs/api/Store.html)*): The single Redux store in your application. * `children`: (*Function*): Unlike most React components, `` accepts a [function as a child](#child-must-be-a-function) with your root component. This is a temporary workaround for a React 0.13 context issue, which will be fixed when React 0.14 comes out. #### Example ##### Vanilla React ```js React.render( {() => } , rootEl ); ``` ##### React Router 0.13 ```js Router.run(routes, Router.HistoryLocation, (Handler) => { React.render( {() => } , targetEl ); }); ``` ##### React Router 1.0 ```js React.render( {() => ...} , targetEl ); ``` ### `connect([mapStateToProps], [mapDispatchToProps], [mergeProps])` Connects a React component to a Redux store. #### Arguments * [`mapStateToProps(state): stateProps`] \(*Function*): If specified, the component will subscribe to Redux store updates. Any time it updates, `mapStateToProps` will be called. Its result must be a plain object, and it will be merged into the component’s props. If you omit it, the component will not be subscribed to the Redux store. * [

资源文件列表:

redux-0.5.3.zip 大约有38个文件
  1. redux-0.5.3/
  2. redux-0.5.3/.babelrc 35B
  3. redux-0.5.3/.eslintignore 16B
  4. redux-0.5.3/.eslintrc 473B
  5. redux-0.5.3/.gitignore 55B
  6. redux-0.5.3/.npmignore 13B
  7. redux-0.5.3/CHANGELOG.md 156B
  8. redux-0.5.3/CODE_OF_CONDUCT.md 1.39KB
  9. redux-0.5.3/LICENSE.md 1.05KB
  10. redux-0.5.3/README.md 13.55KB
  11. redux-0.5.3/native.js 41B
  12. redux-0.5.3/package.json 1.87KB
  13. redux-0.5.3/src/
  14. redux-0.5.3/src/components/
  15. redux-0.5.3/src/components/createAll.js 253B
  16. redux-0.5.3/src/components/createConnect.js 5.02KB
  17. redux-0.5.3/src/components/createProvider.js 942B
  18. redux-0.5.3/src/index.js 131B
  19. redux-0.5.3/src/native.js 138B
  20. redux-0.5.3/src/utils/
  21. redux-0.5.3/src/utils/createStoreShape.js 212B
  22. redux-0.5.3/src/utils/isPlainObject.js 641B
  23. redux-0.5.3/src/utils/shallowEqual.js 496B
  24. redux-0.5.3/src/utils/shallowEqualScalar.js 757B
  25. redux-0.5.3/src/utils/wrapActionCreators.js 175B
  26. redux-0.5.3/test/
  27. redux-0.5.3/test/components/
  28. redux-0.5.3/test/components/Provider.spec.js 2.05KB
  29. redux-0.5.3/test/components/connect.spec.js 16.88KB
  30. redux-0.5.3/test/components/jsdomReact.js 194B
  31. redux-0.5.3/test/utils/
  32. redux-0.5.3/test/utils/isPlainObject.spec.js 591B
  33. redux-0.5.3/test/utils/shallowEqual.spec.js 1.27KB
  34. redux-0.5.3/test/utils/shallowEqualScalar.spec.js 1.96KB
  35. redux-0.5.3/test/utils/wrapActionCreators.js 841B
  36. redux-0.5.3/webpack.config.base.js 612B
  37. redux-0.5.3/webpack.config.development.js 328B
  38. redux-0.5.3/webpack.config.production.js 442B
0评论
提交 加载更多评论
其他资源 redux-0.5.2.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-0.5.1.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-0.6.2.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-0.6.0.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
algorithm-journey-main.zip
algorithm-journey-main.zip
algorithm-journey-main.zip algorithm-journey-main.zip algorithm-journey-main.zip
redux-thunk-2.0.0.zip
Redux 的 Thunk 中间件。它允许编写带有内部逻辑的函数,这些函数可以与 Redux 存储的 dispatch 和 getState 方法交互。
redux-4.1.2.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-3.4.0.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management