项目作者: huanghaiyang

项目描述 :
flux history
高级语言: JavaScript
项目地址: git://github.com/huanghaiyang/fluxory.git
创建时间: 2016-07-31T17:06:49Z
项目社区:https://github.com/huanghaiyang/fluxory

开源协议:MIT License

下载


fluxory

flux history

install

  1. npm install fluxory --save

how to use

  1. const Dispatcher = require('fluxory')(require('flux').Dispatcher)

api method

  1. back([actiionType])
  2. forward([actionType])
  3. getCurrentPosition([actionType])

mocha test sample

  1. var flightDispatcher = new Dispatcher();
  2. var CityStore = {
  3. city: null
  4. };
  5. var CountryStore = {
  6. country: null
  7. }
  8. flightDispatcher.register(function(payload) {
  9. if (payload.actionType === 'city-update') {
  10. CityStore.city = payload.selectedCity;
  11. } else if (payload.actionType === 'country-update') {
  12. CountryStore.country = payload.selectedCountry;
  13. }
  14. });
  15. flightDispatcher.dispatch({
  16. actionType: 'city-update',
  17. selectedCity: 'paris'
  18. });
  19. assert.equal(CityStore.city, 'paris')
  20. flightDispatcher.dispatch({
  21. actionType: 'city-update',
  22. selectedCity: 'hongkong'
  23. });
  24. assert.equal(CityStore.city, 'hongkong')
  25. flightDispatcher.dispatch({
  26. actionType: 'city-update',
  27. selectedCity: 'beijing'
  28. });
  29. assert.equal(CityStore.city, 'beijing')
  30. flightDispatcher.back()
  31. assert.equal(CityStore.city, 'hongkong')
  32. flightDispatcher.back()
  33. assert.equal(CityStore.city, 'paris')
  34. flightDispatcher.forward()
  35. assert.equal(CityStore.city, 'hongkong')
  36. flightDispatcher.dispatch({
  37. actionType: 'country-update',
  38. selectedCountry: 'china'
  39. });
  40. assert.equal(CountryStore.country, 'china')
  41. flightDispatcher.dispatch({
  42. actionType: 'country-update',
  43. selectedCountry: 'usa'
  44. });
  45. assert.equal(CountryStore.country, 'usa')
  46. flightDispatcher.back()
  47. assert.equal(CountryStore.country, 'china')
  48. flightDispatcher.back('city-update')
  49. assert.equal(CityStore.city, 'hongkong')
  50. flightDispatcher.back('city-update')
  51. assert.equal(CityStore.city, 'paris')
  52. assert.equal(flightDispatcher.getCurrentPosition('country-update'), 1)

for dev

  • install self to test
    1. npm install
  • test
    1. npm test
  • debug
    1. npm run debug