# uflux **Repository Path**: mirrors_rstacruz/uflux ## Basic Information - **Project Name**: uflux - **Description**: Minimal flux implementation (deprecated) - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-11-23 - **Last Updated**: 2025-08-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README > **Deprecated** — use [redux](https://www.npmjs.com/package/redux) instead; it works pretty much just like uflux and is better supported. ---- # μflux **uflux** - Another implementation for the Flux architecture for React apps that pushes minimalism far. * Store works with immutable objects * Unidirectional flow But also: * Reduced verbosity. no action constants, no action methods. To fire a method, just emit a signal from the disptacher. See [API.md](API.md) for full API documentation. [](https://travis-ci.org/rstacruz/uflux "See test builds") ## Usage When used via npm/bower/browserify/webpack/etc: ```js import { Dispatcher, Store, connectToStores } from 'uflux' ``` ### Composition Your application will be composed of: * One and only one Dispatcher singleton. * Many stores (singletons), each listening to the one Dispatcher. * Many React components, with some listening to changes to one or more stores. ### Dispatcher A disptacher is simply an [EventEmitter]. ```js const App = new Dispatcher() App.on('eventname', function () { ... }) App.emit('eventname') App.emit('eventname', arg1, arg2) ``` [EventEmitter]: http://devdocs.io/iojs/events#events_class_events_eventemitter ### Store A store is an object that keeps a state and listens to dispatcher events. Create a new store using `new Store(dispatcher, initialState, handlers)`. It listens to events from the dispatcher and responds by updating the store's state. Each handler is a pure function that takes in the `state` and returns the new state—no mutation should be done here. ```js const ListStore = new Store(App, { items: [] }, { 'list:add': function (state, item) { return { ...state, items: state.items.concat([ item ]) } } }) App.emit('list:add', '2') ListStore.getState() /* { items: [2] } */ ``` ### Actions To fire an action, just emit directly on your main dispatcher. No need for action methods. ```js App.emit('list:add') ``` If you're firing within an event listener (such as in a store), you can use `emitAfter()` to make the event trigger after all other events have triggered. ```js const DiceStore = new Store(App, { }, { 'dice:roll': function (state) { App.emitAfter('dice:refresh') return { number: Math.floor(Math.random() * 6) + 1 } } }) ``` ### React You can connect a react Component to a store using `connectToStores()`. The state of the store will be available as properties (`this.props`). ```js const ListView = React.createClass({ statics: { getStores () { return [ ListStore ] }, getPropsFromStores() { return ListStore.getState() } }, render () { return