Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/huanghaiyang/flux-dispatcher-packer

flux dispatcher 事件监听器,用于dispatch回调
https://github.com/huanghaiyang/flux-dispatcher-packer

Last synced: 6 days ago
JSON representation

flux dispatcher 事件监听器,用于dispatch回调

Awesome Lists containing this project

README

        

# flux-dispatcher-packer
flux dispatcher 事件监听器,用于dispatch回调

# 安装
```
npm install flux-dispatcher-packer --save
```
# how to use
```javascript
const Dispatcher = require('flux-dispatcher-packer')(require('flux').Dispatcher)
```

```javascript
var flightDispatcher = new Dispatcher();

var CityStore = {
city: null
};

flightDispatcher.register(function(payload) {
if (payload.actionType === 'city-update') {
CityStore.city = payload.selectedCity;
}
});

flightDispatcher.on('afterDispatching', (payload) => {
assert.equal(CityStore.city, payload.selectedCity)
})

flightDispatcher.on('afterDispatching', (payload) => {
assert.equal(CityStore.city, payload.selectedCity)
})

flightDispatcher.dispatch({
actionType: 'city-update',
selectedCity: 'paris'
});

flightDispatcher.unbind('afterDispatching')

assert.equal(_.isUndefined(flightDispatcher.events['afterDispatching']), true)
```