You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

  1. import { Provider } from 'react-redux';
  2. import configureStore from '../store/configureStore';
  3. import Frontend from '../components/frontend';
  4. import { setTimeline, updateTimeline } from '../actions/timelines';
  5. import { setAccessToken } from '../actions/meta';
  6. import PureRenderMixin from 'react-addons-pure-render-mixin';
  7. const store = configureStore();
  8. const Root = React.createClass({
  9. propTypes: {
  10. token: React.PropTypes.string.isRequired,
  11. timelines: React.PropTypes.object
  12. },
  13. mixins: [PureRenderMixin],
  14. componentWillMount() {
  15. store.dispatch(setAccessToken(this.props.token));
  16. for (var timelineType in this.props.timelines) {
  17. if (this.props.timelines.hasOwnProperty(timelineType)) {
  18. store.dispatch(setTimeline(timelineType, JSON.parse(this.props.timelines[timelineType])));
  19. }
  20. }
  21. if (typeof App !== 'undefined') {
  22. App.timeline = App.cable.subscriptions.create("TimelineChannel", {
  23. connected: function() {},
  24. disconnected: function() {},
  25. received: function(data) {
  26. return store.dispatch(updateTimeline(data.timeline, JSON.parse(data.message)));
  27. }
  28. });
  29. }
  30. },
  31. render () {
  32. return (
  33. <Provider store={store}>
  34. <Frontend />
  35. </Provider>
  36. );
  37. }
  38. });
  39. export default Root;