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

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

redux-0.2.1.zip

前端 15.74KB 37 需要积分: 1
立即下载

资源介绍:

一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux ========================= An experiment in fully hot-reloadable Flux. The API might change any day. Don't use in production. ## What's 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 // (wow, much functions, so injectable :doge:) export function incrementAsync() { return dispatch => { setTimeout(() => { dispatch(increment()); }, 1000); }; } ``` ### Stores ```js // ... too, use constants import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../constants/ActionTypes'; // but you can write this part anyhow you like: const initialState = { counter: 0 }; function incremenent({ counter }) { return { counter: counter + 1 }; } function decremenent({ counter }) { return { counter: counter - 1 }; } // what's important is that Store is a pure function too export default function CounterStore(state, action) { // ... that has an initial state if (!state) { return initialState; } // and return the new state when an action comes switch (action.type) { case INCREMENT_COUNTER: return incremenent(state, action); case DECREMENT_COUNTER: return decremenent(state, action); default: return state; } } ``` ### Components #### Observing a Single Store ```js // We're gonna need some decorators import React from 'react'; import { observes } from 'redux'; // Gonna subscribe it @observes('CounterStore') export default class Counter { render() { const { counter } = this.props; // injected by @observes return (

Clicked: {counter} times

); } } ``` #### Observing Many Stores ```js // We're gonna need some decorators import React from 'react'; import { observes } from 'redux'; // With multiple stores, you might want to specify a prop mapper as last argument. // You can also access `props` inside the prop mapper. @observes('CounterStore', 'TodoStore', (state, props) => ({ counter: state.CounterStore.counter, todos: state.TodoStore.todos })) export default class TodosWithCounter { /* ... */ } ``` #### Performing a Single Action ```js // We're gonna need some decorators import React from 'react'; import { performs } from 'redux'; // Gonna subscribe it @performs('increment') export default class IncrementButton { render() { const { increment } = this.props; // injected by @performs return ( ); } } ``` #### Performing Many Actions ```js // We're gonna need some decorators import React from 'react'; import { performs } from 'redux'; // With multiple actions, you might want to specify a prop mapper as last argument. // You can also access `props` inside the prop mapper. @performs('increment', 'decrement', (actions, props) => ({ increment: props.invert ? actions.decrement : actions.increment, decrement: props.invert ? actions.increment : actions.decrement })) export default class IncrementButton { /* .... */ } ``` ### Dispatcher #### Creating a hot-reloadable dispatcher ```js import * as stores from './stores/index'; import * as actions from './actions/index'; import { createDispatcher } from 'redux'; const dispatcher = module.hot && module.hot.data && module.hot.data.dispatcher || createDispatcher(); dispatcher.receive(stores, actions); module.hot.dispose(data => { data.dispatcher = dispatcher; }); export default dispatcher; ``` #### Attaching the dispatcher to the root component ```js import React from 'react'; import { provides } from 'redux'; import dispatcher from './dispatcher'; @provides(dispatcher) export default class App { /* ... */ } ```

资源文件列表:

redux-0.2.1.zip 大约有46个文件
  1. redux-0.2.1/
  2. redux-0.2.1/.babelrc 43B
  3. redux-0.2.1/.eslintrc 349B
  4. redux-0.2.1/.gitignore 40B
  5. redux-0.2.1/.jshintrc 75B
  6. redux-0.2.1/.npmignore 13B
  7. redux-0.2.1/LICENSE 1.05KB
  8. redux-0.2.1/README.md 3.86KB
  9. redux-0.2.1/TODO 219B
  10. redux-0.2.1/examples/
  11. redux-0.2.1/examples/counter/
  12. redux-0.2.1/examples/counter/App.js 273B
  13. redux-0.2.1/examples/counter/Counter.js 456B
  14. redux-0.2.1/examples/counter/actions/
  15. redux-0.2.1/examples/counter/actions/CounterActions.js 371B
  16. redux-0.2.1/examples/counter/actions/index.js 34B
  17. redux-0.2.1/examples/counter/constants/
  18. redux-0.2.1/examples/counter/constants/ActionTypes.js 108B
  19. redux-0.2.1/examples/counter/dispatcher.js 367B
  20. redux-0.2.1/examples/counter/stores/
  21. redux-0.2.1/examples/counter/stores/CounterStore.js 562B
  22. redux-0.2.1/examples/counter/stores/index.js 43B
  23. redux-0.2.1/examples/index.html 157B
  24. redux-0.2.1/examples/index.js 206B
  25. redux-0.2.1/examples/server.js 395B
  26. redux-0.2.1/examples/todo/
  27. redux-0.2.1/examples/todo/App.js 308B
  28. redux-0.2.1/examples/todo/Body.js 273B
  29. redux-0.2.1/examples/todo/Header.js 298B
  30. redux-0.2.1/examples/todo/actions/
  31. redux-0.2.1/examples/todo/actions/index.js 133B
  32. redux-0.2.1/examples/todo/constants/
  33. redux-0.2.1/examples/todo/constants/ActionTypes.js 35B
  34. redux-0.2.1/examples/todo/dispatcher.js 367B
  35. redux-0.2.1/examples/todo/stores/
  36. redux-0.2.1/examples/todo/stores/index.js 398B
  37. redux-0.2.1/examples/webpack.config.js 742B
  38. redux-0.2.1/package.json 1.08KB
  39. redux-0.2.1/scripts/
  40. redux-0.2.1/scripts/build 53B
  41. redux-0.2.1/src/
  42. redux-0.2.1/src/createDispatcher.js 4.03KB
  43. redux-0.2.1/src/index.js 156B
  44. redux-0.2.1/src/observes.js 1.89KB
  45. redux-0.2.1/src/performs.js 1.3KB
  46. redux-0.2.1/src/provides.js 784B
0评论
提交 加载更多评论
其他资源 redux-0.4.0.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-0.3.0.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-0.5.0.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-0.3.1.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
Idea-Tools插件
属于idea的插件,开发者可以通过此插件进行idea的插件开发,并提供完整的插件生命周期管理,方便使用者和开发者管理插件
redux-0.2.0.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-0.1.0.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management
redux-0.1.1.zip
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state management