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

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

redux-0.10.0.zip

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

资源介绍:

一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux ========================= [![build status](https://img.shields.io/travis/gaearon/redux.svg?style=flat-square)](https://travis-ci.org/gaearon/redux) [![npm version](https://img.shields.io/npm/v/redux.svg?style=flat-square)](https://www.npmjs.com/package/redux) An experiment in fully hot-reloadable Flux. **The API might change any day.** _**Don't use in production just yet.**_ ## Why another Flux framework? Read **[The Evolution of Flux Frameworks](https://medium.com/@dan_abramov/the-evolution-of-flux-frameworks-6c16ad26bb31)** for some context. ### Design Goals * Hot reloading of everything. * A hook for the future devtools to "commit" a state, and replay actions on top of it during hot reload. * No wrapper calls in your stores and actions. Your stuff is your stuff. * Super easy to test things in isolation without mocks. * I don't mind action constants. Seriously. * Keep Flux lingo. No cursors or observables in core. * Have I mentioned hot reloading yet? ## Demo ``` git clone https://github.com/gaearon/redux.git redux cd redux npm install npm start ``` ## What does it look like? ### Actions ```js // Still using constants... import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../constants/ActionTypes'; // But action creators are pure functions returning actions export function increment() { return { type: INCREMENT_COUNTER }; } export function decrement() { return { type: DECREMENT_COUNTER }; } // Can also be async if you return a function export function incrementAsync() { return dispatch => { setTimeout(() => { // Yay! Can invoke sync or async actions with `dispatch` dispatch(increment()); }, 1000); }; } // Could also read state of a store in the callback form export function incrementIfOdd() { return (dispatch, { counter }) => { if (counter % 2 === 0) { return; } dispatch(increment()); }; } ``` ### Stores ```js // ... too, use constants import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../constants/ActionTypes'; // what's important is that Store is a pure function, // and you can write it anyhow you like. // the Store signature is (state, action) => state, // and the state shape is up to you: you can use primitives, // objects, arrays, or even ImmutableJS objects. export default function counter(state = 0, action) { // this function returns the new state when an action comes switch (action.type) { case INCREMENT_COUNTER: return state + 1; case DECREMENT_COUNTER: return state - 1; default: return state; } // BUT THAT'S A SWITCH STATEMENT! // Right. If you hate 'em, see the FAQ below. } ``` ### Components #### Dumb Components ```js // The dumb component receives everything using props: import React, { PropTypes } from 'react'; export default class Counter { static propTypes = { increment: PropTypes.func.isRequired, decrement: PropTypes.func.isRequired, counter: PropTypes.number.isRequired }; render() { const { increment, decrement, counter } = this.props; return (

Clicked: {counter} times {' '} {' '}

); } } ``` #### Smart Components ```js // The smart component may observe stores using ``, // and bind actions to the dispatcher with `bindActionCreators`. import React from 'react'; import { Connector, bindActionCreators } from 'redux'; import Counter from '../components/Counter'; import * as CounterActions from '../actions/CounterActions'; // You can optionally specify `select` for finer-grained subscriptions // and retrieval. Only when the return value is shallowly different, // will the child component be updated. function select(state) { return { counter: state.counter }; } export default class CounterApp { render() { return ( {({ counter, dispatch }) => /* Yes this is child as a function. */ } ); } } ``` #### Decorators The `@connect` decorator lets you create smart components less verbosely: ```js import React from 'react'; import { connect, bindActionCreators } from 'redux'; import Counter from '../components/Counter'; import * as CounterActions from '../actions/CounterActions'; @connect(state => ({ counter: state.counter })) export default class CounterApp { render() { const { counter, dispatch } = this.props; // Instead of `bindActionCreators`, you may also pass `dispatch` as a prop // to your component and call `dispatch(CounterActions.increment())` return ( ); } } ``` #### Initializing Redux The simplest way to initialize a Redux instance is to give it an object whose values are your Store functions, and whose keys are their names. You may `import *` from the file with all your Store definitions to obtain such an object: ```js import { createRedux, Provider } from 'redux'; import * as stores from '../stores/index'; const redux = createRedux(stores); ``` Then pass `redux` as a prop to `` component in the root component of your app, and you're all set: ```js export default class App { render() { return ( {() => } ); } } ``` #### Running the same code on client and server The `redux` instance returned by `createRedux` also has the `dispatch(action)`, `subscribe()` and `getState()` methods that you may call outside the React components. You may optionally specify the initial state as the second argument to `createRedux`. This is useful for hydrating the state you received from running Redux on the server: ```js // server const redux = createRedux(stores); redux.dispatch(MyActionCreators.doSomething()); // fire action creators to fill the state const state = redux.getState(); // somehow pass this state to the client // client const initialState = window.STATE_FROM_SERVER; const redux = createRedux(stores, initialState); ``` #### Additional customization There is also a longer way to do the same thing, if you need additional customization. This: ```js import { createRedux } from 'redux'; import * as stores from '../stores/index'; const redux = createRedux(stores); ``` is in fact a shortcut for this: ```js import { createRedux, createDispatcher, composeStores } from 'redux'; import thunkMiddleware from 'redux/lib/middleware/thunk'; import * as stores from '../stores/index'; // Compose all your Stores into a single Store function with `composeStores`: const store = composeStores(stores); // Create a Dispatcher function for your composite Store: const dispatcher = createDispatcher( store, getState => [thunkMiddleware(getState)] // Pass the default middleware ); // Create a Redux instance using the dispatcher function: const redux = createRedux(dispatcher); ``` Why would you want to write it longer? Maybe you're an advanced user and want to provide a custom Dispatcher function, or maybe you have a different idea of how to compose your Stores (or you're satisfied with a single Store). Redux lets you do all of this. `createDispatcher()` also gives you the ability to specify middleware -- for example, to add support for promises. [Learn more](https://github.com/gaearon/redux/blob/master/docs/middleware.md) about how to create and use middleware in Redux. When in doubt, use the shorter option! ## FAQ ### How does hot reloading work? * http://webpack.github.io/docs/hot-module-replacement.html * http://gaearon.github.io/react-hot-loader/

资源文件列表:

redux-0.10.0.zip 大约有76个文件
  1. redux-0.10.0/
  2. redux-0.10.0/.babelrc 43B
  3. redux-0.10.0/.eslintrc 368B
  4. redux-0.10.0/.gitignore 50B
  5. redux-0.10.0/.jshintrc 75B
  6. redux-0.10.0/.npmignore 13B
  7. redux-0.10.0/.travis.yml 38B
  8. redux-0.10.0/LICENSE 1.05KB
  9. redux-0.10.0/README.md 11.02KB
  10. redux-0.10.0/TODO 224B
  11. redux-0.10.0/docs/
  12. redux-0.10.0/docs/middleware.md 2.71KB
  13. redux-0.10.0/examples/
  14. redux-0.10.0/examples/actions/
  15. redux-0.10.0/examples/actions/CounterActions.js 559B
  16. redux-0.10.0/examples/actions/TodoActions.js 133B
  17. redux-0.10.0/examples/components/
  18. redux-0.10.0/examples/components/AddTodo.js 327B
  19. redux-0.10.0/examples/components/Counter.js 598B
  20. redux-0.10.0/examples/components/TodoList.js 302B
  21. redux-0.10.0/examples/constants/
  22. redux-0.10.0/examples/constants/ActionTypes.js 145B
  23. redux-0.10.0/examples/containers/
  24. redux-0.10.0/examples/containers/App.js 474B
  25. redux-0.10.0/examples/containers/CounterApp.js 487B
  26. redux-0.10.0/examples/containers/TodoApp.js 668B
  27. redux-0.10.0/examples/index.html 157B
  28. redux-0.10.0/examples/index.js 126B
  29. redux-0.10.0/examples/server.js 420B
  30. redux-0.10.0/examples/stores/
  31. redux-0.10.0/examples/stores/counter.js 291B
  32. redux-0.10.0/examples/stores/index.js 62B
  33. redux-0.10.0/examples/stores/todos.js 325B
  34. redux-0.10.0/examples/webpack.config.js 742B
  35. redux-0.10.0/package.json 1.66KB
  36. redux-0.10.0/react-native.js 36B
  37. redux-0.10.0/react.js 29B
  38. redux-0.10.0/scripts/
  39. redux-0.10.0/scripts/build 65B
  40. redux-0.10.0/src/
  41. redux-0.10.0/src/Redux.js 1.17KB
  42. redux-0.10.0/src/components/
  43. redux-0.10.0/src/components/createAll.js 594B
  44. redux-0.10.0/src/components/createConnectDecorator.js 748B
  45. redux-0.10.0/src/components/createConnector.js 1.87KB
  46. redux-0.10.0/src/components/createProvideDecorator.js 527B
  47. redux-0.10.0/src/components/createProvider.js 939B
  48. redux-0.10.0/src/createDispatcher.js 556B
  49. redux-0.10.0/src/createRedux.js 321B
  50. redux-0.10.0/src/index.js 275B
  51. redux-0.10.0/src/middleware/
  52. redux-0.10.0/src/middleware/thunk.js 228B
  53. redux-0.10.0/src/react-native.js 158B
  54. redux-0.10.0/src/react.js 151B
  55. redux-0.10.0/src/utils/
  56. redux-0.10.0/src/utils/bindActionCreators.js 230B
  57. redux-0.10.0/src/utils/composeMiddleware.js 116B
  58. redux-0.10.0/src/utils/composeStores.js 239B
  59. redux-0.10.0/src/utils/getDisplayName.js 119B
  60. redux-0.10.0/src/utils/shallowEqual.js 606B
  61. redux-0.10.0/src/utils/shallowEqualScalar.js 747B
  62. redux-0.10.0/test/
  63. redux-0.10.0/test/_helpers.js 741B
  64. redux-0.10.0/test/bindActionCreators.spec.js 1019B
  65. redux-0.10.0/test/components/
  66. redux-0.10.0/test/components/Connector.spec.js 4.29KB
  67. redux-0.10.0/test/components/Provider.spec.js 1.79KB
  68. redux-0.10.0/test/components/connect.spec.js 1.58KB
  69. redux-0.10.0/test/components/provide.spec.js 1.38KB
  70. redux-0.10.0/test/compose.spec.js 601B
  71. redux-0.10.0/test/composeStores.spec.js 702B
  72. redux-0.10.0/test/createDispatcher.spec.js 1.34KB
  73. redux-0.10.0/test/createRedux.spec.js 1.58KB
  74. redux-0.10.0/test/getDisplayName.spec.js 410B
  75. redux-0.10.0/test/utils/
  76. redux-0.10.0/test/utils/bindActionCreators.spec.js 1.17KB
0评论
提交 加载更多评论
其他资源 redux-0.8.2.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-0.8.1.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-0.8.0.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-0.9.0.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-0.7.0.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-0.6.1.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-0.6.0.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-0.6.2.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management