Last active
August 29, 2015 14:25
-
-
Save christianalfoni/7a6f64242af7a8f9c200 to your computer and use it in GitHub Desktop.
How to nest with reactive router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import {Decorator as State} from 'cerebral-react-immutable-store'; | |
import {views} from './constants.js'; | |
import Home from './Home.js'; | |
import Messages from './Messages.js'; | |
@State({view: ['view']}) | |
class App extends React.Component { | |
render() { | |
switch (this.props.view) { | |
case views.HOME: | |
return <Home/>; | |
case views.HOME: | |
return <Messages/>; | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ReactiveRouter from 'reactive-router'; | |
import controller from './controller.js'; | |
import {views} from './constants.js'; | |
import { | |
setMessagesView, | |
setLoadingMessages, | |
getMessages, | |
setMessages, | |
unsetLoadingMessages | |
} from './actions.js'; | |
controller.signal('indexRouted', function setHomeView (args, state) { | |
state.set('url', args.url); | |
state.set('view', views.HOME); | |
}); | |
controller.signal('messageRouted', | |
setMessagesView, | |
setLoadingMessages, | |
[getMessages], | |
setMessages, | |
unsetLoadingMessages | |
); | |
const router = ReactiveRouter({ | |
'/': controller.signals.indexRouted, | |
'/messages': controller.signals.messageRouted | |
'' | |
}); | |
controller.eventEmitter.on('change', function (state) { | |
router.set(state.url); | |
}); | |
controller.eventEmitter.on('remember', function (state) { | |
router.setSilent(state.url); | |
}); | |
export default router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Typo in switch statement :) should be views.MESSAGES?