Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. import {addRule} from 'redux-ruleset'
  2.  
  3. addRule({
  4. id: 'PING_PONG',
  5. target:'PING',
  6. consequence: () => ({ type: 'PONG' }),
  7. addWhen: function* (next) {
  8. yield next('START_GAME')
  9. return 'ADD_RULE'
  10. },
  11. addUntil: function* (next) {
  12. yield next('STOP_GAME')
  13. return 'RECREATE_RULE'
  14. }
  15. })
  16.  
  17. // later
  18. dispatch({ type: 'PING' }) // noting happens
  19. dispatch({ type: 'START_GAME' })
  20. dispatch({ type: 'PING' }) // => { type: 'PONG' }
  21. dispatch({ type: 'STOP_GAME' })
  22. dispatch({ type: 'PING' }) // noting happens
  23. dispatch({ type: 'PING' }) // noting happens
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement