redux-0.2.2.zip
资源文件列表:

redux-0.2.2/
redux-0.2.2/.babelrc 43B
redux-0.2.2/.eslintrc 349B
redux-0.2.2/.gitignore 40B
redux-0.2.2/.jshintrc 75B
redux-0.2.2/.npmignore 13B
redux-0.2.2/LICENSE 1.05KB
redux-0.2.2/README.md 5.49KB
redux-0.2.2/TODO 148B
redux-0.2.2/examples/
redux-0.2.2/examples/counter/
redux-0.2.2/examples/counter/App.js 273B
redux-0.2.2/examples/counter/Counter.js 456B
redux-0.2.2/examples/counter/actions/
redux-0.2.2/examples/counter/actions/CounterActions.js 542B
redux-0.2.2/examples/counter/actions/index.js 34B
redux-0.2.2/examples/counter/constants/
redux-0.2.2/examples/counter/constants/ActionTypes.js 108B
redux-0.2.2/examples/counter/dispatcher.js 393B
redux-0.2.2/examples/counter/stores/
redux-0.2.2/examples/counter/stores/CounterStore.js 523B
redux-0.2.2/examples/counter/stores/index.js 43B
redux-0.2.2/examples/index.html 157B
redux-0.2.2/examples/index.js 206B
redux-0.2.2/examples/server.js 395B
redux-0.2.2/examples/todo/
redux-0.2.2/examples/todo/App.js 308B
redux-0.2.2/examples/todo/Body.js 273B
redux-0.2.2/examples/todo/Header.js 298B
redux-0.2.2/examples/todo/actions/
redux-0.2.2/examples/todo/actions/index.js 133B
redux-0.2.2/examples/todo/constants/
redux-0.2.2/examples/todo/constants/ActionTypes.js 35B
redux-0.2.2/examples/todo/dispatcher.js 393B
redux-0.2.2/examples/todo/stores/
redux-0.2.2/examples/todo/stores/index.js 383B
redux-0.2.2/examples/webpack.config.js 742B
redux-0.2.2/package.json 1.11KB
redux-0.2.2/scripts/
redux-0.2.2/scripts/build 53B
redux-0.2.2/src/
redux-0.2.2/src/createDispatcher.js 4.28KB
redux-0.2.2/src/index.js 156B
redux-0.2.2/src/observes.js 1.89KB
redux-0.2.2/src/performs.js 1.3KB
redux-0.2.2/src/provides.js 784B
资源介绍:
一个可预测的全局状态管理的 JS 库 A JS library for predictable global state managementClicked: {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 inject 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'; // Prefer to use existing dispatcher const dispatcher = module.hot && module.hot.data && module.hot.data.dispatcher || createDispatcher(); // Pass (potentially hot-reloaded) stores and actions dispatcher.receive(stores, actions); // Store the dispatcher for the next hot reload if (module.hot) { 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 { /* ... */ } ``` ## FAQ ### How does hot reloading work? * http://webpack.github.io/docs/hot-module-replacement.html * http://gaearon.github.io/react-hot-loader/ * those `module.hot` lines in the dispatcher example above ### But you're using strings for injecting actions and store state! I'm not super happy about strings. If you find a better way, let me know and file an issue with your suggestions. ### Can I use this in production? I wouldn't. Many use cases are not be considered yet. If you find some use cases this lib can't handle yet, please file an issue.