react-crossroads
Version:
Client side router for web applications built with React and utilizing the Flux architecture. The backing routing engine is CrossroadsJs.
42 lines (33 loc) • 1.06 kB
text/coffeescript
React = require 'react'
getNextBlockId = do ->
nextBlockId = 1
-> nextBlockId++
BlockRouting =
contextTypes:
router: React.PropTypes.object.isRequired
getInitialState: ->
BlockRouting:
blockId: null
blocked: false
componentWillMount: ->
.router.stores.location.addChangeListener
componentWillUnmount: ->
.router.stores.location.removeChangeListener
handleLocationStateChange: ->
if
BlockRouting:
blockId: .BlockRouting.blockId # TODO: Why do I need to set this?
blocked: .router.stores.location.isBlocked()
toggleBlock: ->
if .BlockRouting.blocked
.router.actions.unblock .BlockRouting.blockId
BlockRouting:
blockId: null
else
BlockRouting:
blockId: getNextBlockId()
.router.actions.block .BlockRouting.blockId
module.exports = BlockRouting