Skip to content

Instantly share code, notes, and snippets.

@christianalfoni
Last active August 29, 2015 14:25
Show Gist options
  • Save christianalfoni/7a6f64242af7a8f9c200 to your computer and use it in GitHub Desktop.
Save christianalfoni/7a6f64242af7a8f9c200 to your computer and use it in GitHub Desktop.
How to nest with reactive router
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/>;
}
}
}
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;
@idream3
Copy link

idream3 commented Jul 26, 2015

Typo in switch statement :) should be views.MESSAGES?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment