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

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

redux-0.12.0.zip

前端 41.3KB 12 需要积分: 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) Atomic Flux with hot reloading. **The API is likely to change a few times before we reach 1.0.** **Its [surface area](http://www.youtube.com/watch?v=4anAwXYqLG8) is minimal so you can try it in production and report any issues.** # Table of Contents - [Why another Flux framework?](#why-another-flux-framework) - [Philosophy & Design Goals](#philosophy--design-goals) - [Demo](#demo) - [Running TodoMVC](#running-todomvc) - [What does it look like?](#what-does-it-look-like) - [Actions](#actions) - [Stores](#stores) - [Components](#components) - [Dumb Components](#dumb-components) - [Smart Components](#smart-components) - [Decorators](#decorators) - [React Native](#react-native) - [Initializing Redux](#initializing-redux) - [Running the same code on client and server](#running-the-same-code-on-client-and-server) - [Additional customization](#additional-customization) - [FAQ](#faq) - [Any examples with data fetching and `react-router`?](#any-examples-with-data-fetching-and-react-router) - [How does hot reloading work?](#how-does-hot-reloading-work) - [Can I use this in production?](#can-i-use-this-in-production) - [How do I do async?](#how-do-i-do-async) - [But there are switch statements!](#but-there-are-switch-statements) - [What about `waitFor`?](#what-about-waitfor) - [My views aren't updating!](#my-views-arent-updating) - [How do Stores, Actions and Components interact?](#how-do-stores-actions-and-components-interact) - [Discussion](#discussion) - [Inspiration and Thanks](#inspiration-and-thanks) ## Why another Flux framework? Read **[The Evolution of Flux Frameworks](https://medium.com/@dan_abramov/the-evolution-of-flux-frameworks-6c16ad26bb31)** for some context. ### Philosophy & Design Goals * You shouldn't need a book on functional programming to use Redux. * Everything (Stores, Action Creators, configuration) is hot reloadable. * Preserves the benefits of Flux, but adds other nice properties thanks to its functional nature. * Prevents some of the anti-patterns common in Flux code. * Works great in isomoprhic apps because it doesn't use singletons and the data can be rehydrated. * Doesn't care how you store your data: you may use JS objects, arrays, ImmutableJS, etc. * Under the hood, it keeps all your data in a tree, but you don't need to think about it. * Lets you efficiently subscribe to finer-grained updates than individual Stores. * Provides hooks for powerful devtools (e.g. time travel, record/replay) to be implementable without user buy-in. * Provides extension points so it's easy to [support promises](https://github.com/gaearon/redux/issues/99#issuecomment-112212639) or [generate constants](https://gist.github.com/skevy/8a4ffc3cfdaf5fd68739) outside the core. * No wrapper calls in your stores and actions. Your stuff is your stuff. * It's super easy to test things in isolation without mocks. * You can use “flat” Stores, or [compose and reuse Stores](https://gist.github.com/gaearon/d77ca812015c0356654f) just like you compose Components. * The API surface area is minimal. * Have I mentioned hot reloading yet? ## Demo ## Running TodoMVC ``` git clone https://github.com/gaearon/redux.git redux cd redux npm install cd examples/todomvc 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, getState) => { const { counter } = getState(); 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 { bindActionCreators } from 'redux'; import { Connector } from 'redux/react'; 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 { bindActionCreators } from 'redux'; import { connect } from 'redux/react'; 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 ( ); } } ``` ### React Native To use Redux with React Native, just replace imports from `redux/react` with `redux/react-native`: ```js import { bindActionCreators } from 'redux'; import { Provider, Connector } from 'redux/react-native'; ``` ### 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 the

资源文件列表:

redux-0.12.0.zip 大约有95个文件
  1. redux-0.12.0/
  2. redux-0.12.0/.babelrc 35B
  3. redux-0.12.0/.eslintrc 362B
  4. redux-0.12.0/.gitignore 80B
  5. redux-0.12.0/.npmignore 13B
  6. redux-0.12.0/.travis.yml 38B
  7. redux-0.12.0/LICENSE 1.05KB
  8. redux-0.12.0/README.md 16.4KB
  9. redux-0.12.0/TODO 224B
  10. redux-0.12.0/docs/
  11. redux-0.12.0/docs/middleware.md 2.77KB
  12. redux-0.12.0/examples/
  13. redux-0.12.0/examples/todomvc/
  14. redux-0.12.0/examples/todomvc/.babelrc 17B
  15. redux-0.12.0/examples/todomvc/actions/
  16. redux-0.12.0/examples/todomvc/actions/TodoActions.js 498B
  17. redux-0.12.0/examples/todomvc/components/
  18. redux-0.12.0/examples/todomvc/components/Header.js 554B
  19. redux-0.12.0/examples/todomvc/components/MainSection.js 616B
  20. redux-0.12.0/examples/todomvc/components/TodoItem.js 1.63KB
  21. redux-0.12.0/examples/todomvc/components/TodoTextInput.js 1.19KB
  22. redux-0.12.0/examples/todomvc/constants/
  23. redux-0.12.0/examples/todomvc/constants/ActionTypes.js 190B
  24. redux-0.12.0/examples/todomvc/containers/
  25. redux-0.12.0/examples/todomvc/containers/App.js 354B
  26. redux-0.12.0/examples/todomvc/containers/TodoApp.js 692B
  27. redux-0.12.0/examples/todomvc/index.html 178B
  28. redux-0.12.0/examples/todomvc/index.js 162B
  29. redux-0.12.0/examples/todomvc/package.json 962B
  30. redux-0.12.0/examples/todomvc/server.js 420B
  31. redux-0.12.0/examples/todomvc/stores/
  32. redux-0.12.0/examples/todomvc/stores/index.js 44B
  33. redux-0.12.0/examples/todomvc/stores/todos.js 975B
  34. redux-0.12.0/examples/todomvc/webpack.config.js 680B
  35. redux-0.12.0/package.json 1.48KB
  36. redux-0.12.0/scripts/
  37. redux-0.12.0/scripts/browser 293B
  38. redux-0.12.0/scripts/build 140B
  39. redux-0.12.0/scripts/clean 34B
  40. redux-0.12.0/scripts/lint 37B
  41. redux-0.12.0/scripts/prepublish 83B
  42. redux-0.12.0/scripts/test 82B
  43. redux-0.12.0/scripts/test-cov 97B
  44. redux-0.12.0/scripts/test-watch 90B
  45. redux-0.12.0/src/
  46. redux-0.12.0/src/Redux.js 1.24KB
  47. redux-0.12.0/src/components/
  48. redux-0.12.0/src/components/createAll.js 594B
  49. redux-0.12.0/src/components/createConnectDecorator.js 802B
  50. redux-0.12.0/src/components/createConnector.js 2.1KB
  51. redux-0.12.0/src/components/createProvideDecorator.js 581B
  52. redux-0.12.0/src/components/createProvider.js 1.03KB
  53. redux-0.12.0/src/createDispatcher.js 629B
  54. redux-0.12.0/src/createRedux.js 321B
  55. redux-0.12.0/src/entry-react-native.js 36B
  56. redux-0.12.0/src/entry-react.js 29B
  57. redux-0.12.0/src/index.js 392B
  58. redux-0.12.0/src/middleware/
  59. redux-0.12.0/src/middleware/thunk.js 228B
  60. redux-0.12.0/src/react-native.js 158B
  61. redux-0.12.0/src/react.js 151B
  62. redux-0.12.0/src/umd-react.js 50B
  63. redux-0.12.0/src/umd.js 25B
  64. redux-0.12.0/src/utils/
  65. redux-0.12.0/src/utils/bindActionCreators.js 225B
  66. redux-0.12.0/src/utils/composeMiddleware.js 126B
  67. redux-0.12.0/src/utils/composeStores.js 345B
  68. redux-0.12.0/src/utils/getDisplayName.js 119B
  69. redux-0.12.0/src/utils/identity.js 60B
  70. redux-0.12.0/src/utils/isPlainObject.js 146B
  71. redux-0.12.0/src/utils/mapValues.js 165B
  72. redux-0.12.0/src/utils/pick.js 183B
  73. redux-0.12.0/src/utils/shallowEqual.js 496B
  74. redux-0.12.0/src/utils/shallowEqualScalar.js 757B
  75. redux-0.12.0/test/
  76. redux-0.12.0/test/_helpers.js 741B
  77. redux-0.12.0/test/components/
  78. redux-0.12.0/test/components/Connector.spec.js 5.76KB
  79. redux-0.12.0/test/components/Provider.spec.js 1.8KB
  80. redux-0.12.0/test/components/connect.spec.js 1.93KB
  81. redux-0.12.0/test/components/jsdomReact.js 194B
  82. redux-0.12.0/test/components/provide.spec.js 1.73KB
  83. redux-0.12.0/test/composeMiddleware.spec.js 651B
  84. redux-0.12.0/test/composeStores.spec.js 1019B
  85. redux-0.12.0/test/createDispatcher.spec.js 1.39KB
  86. redux-0.12.0/test/createRedux.spec.js 1.98KB
  87. redux-0.12.0/test/getDisplayName.spec.js 410B
  88. redux-0.12.0/test/utils/
  89. redux-0.12.0/test/utils/bindActionCreators.spec.js 1023B
  90. redux-0.12.0/test/utils/identity.spec.js 294B
  91. redux-0.12.0/test/utils/isPlainObject.spec.js 591B
  92. redux-0.12.0/test/utils/mapValues.spec.js 349B
  93. redux-0.12.0/test/utils/pick.spec.js 332B
  94. redux-0.12.0/test/utils/shallowEquality.spec.js 3.18KB
  95. redux-0.12.0/webpack.config.js 859B
0评论
提交 加载更多评论
其他资源 redux-1.0.0-rc.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-0.11.1.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-1.0.0-alpha.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-1.0.0.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-0.11.0.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-0.10.1.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.8.0.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management