Giter Site home page Giter Site logo

Comments (4)

MrEfrem avatar MrEfrem commented on April 19, 2024

I solved it so far so:
https://github.com/MrEfrem/react-redux-starter-kit/blob/master/src/entry-points/client.js

...
import { fetchComponentData } from '../utils';

const target = document.getElementById('root');
const store  = configureStore(window.__INITIAL_STATE__);

function onRouteEnter(nextState, transition, done) {
  fetchComponentData(store.dispatch, nextState.routes.map(b => b.component), nextState.params)
    .catch(err => {
      if (!__PROD__) {
        window.console.log(err);
      }
    });
  done();
}

const node = (
  <Root store={store}>
    <Router history={createBrowserHistory()}>
      {createRoutes(onRouteEnter)}
    </Router>
  </Root>
);
ReactDOM.render(node, target);

https://github.com/MrEfrem/react-redux-starter-kit/blob/master/src/utils/index.js

export function fetchComponentData (dispatch, components, params) {
  const needs = components.reduce( (prev, current) => {
    return (current.needs || [])
      .concat((current.WrappedComponent ? current.WrappedComponent.needs : []) || [])
      .concat(prev);
  }, []);

  const promises = needs.map(need => dispatch(need(params)));

  return Promise.all(promises);
}

https://github.com/MrEfrem/react-redux-starter-kit/blob/master/server/middleware/render-route.js

export default function *renderRouteMiddleware (next) {
  const props  = yield route(this.request.url);

  let store = configureStore();

  yield fetchComponentData(store.dispatch, props.components, props.params);

  if (config.get('globals').__DEBUG__) {
    store = configureStore(store.getState());
  }

  const markup = ReactDOM.renderToString(
    <Root store={store}>
      <RoutingContext {...props} />
    </Root>
  );

  this.body = renderIntoTemplate(template, markup, store.getState());
}

https://github.com/MrEfrem/react-redux-starter-kit/blob/master/src/routes/index.js

export default (onEnter) => {
  return (
    <Route component={CoreLayout}>
      <Route path='/' component={HomeView} onEnter={onEnter}/>
      <Route path='/test' component={TestView} onEnter={onEnter}/>
    </Route>
  );
};

https://github.com/MrEfrem/react-redux-starter-kit/blob/master/src/views/HomeView.js

import * as CounterActions from '../reducers/counter';

const mapStateToProps = (state) => ({
  counter : state.counter
});
export class HomeView extends React.Component {
  static propTypes = {
    dispatch : React.PropTypes.func,
    counter  : React.PropTypes.number
  }

  constructor () {
    super();
  }

  static needs = [
    CounterActions.setCounter
  ]

from react-redux-starter-kit.

MrEfrem avatar MrEfrem commented on April 19, 2024

I took as a basis from here:
https://github.com/bananaoomarang/chapters

from react-redux-starter-kit.

dvdzkwsk avatar dvdzkwsk commented on April 19, 2024

Wow awesome, this looks great. I'll take a deeper look a bit later when I get a chance. Thanks!

from react-redux-starter-kit.

dvdzkwsk avatar dvdzkwsk commented on April 19, 2024

Might fork the project to provide a better server environment, but for now the starter kit no longer comes with a server, so closing this for now.

from react-redux-starter-kit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.