GithubHelp home page GithubHelp logo

Comments (7)

catamphetamine avatar catamphetamine commented on May 28, 2024 1
  // (optional)
  history:
  {
    // (optional)
    // `history` options (like `basename`)
    options: {}

    // (optional)
    // Custom `history` wrapper, like `syncHistoryWithStore` from `react-router-redux`
    wrap: (history, { store }) => history
  }

from react-pages.

catamphetamine avatar catamphetamine commented on May 28, 2024

If someone wants syncHistoryWithStore then they could try to implement that.

Consider client-side:
https://github.com/halt-hammerzeit/react-isomorphic-render/blob/master/source/redux/client/client.js#L44

There history is created and could be wrapped with syncHistoryWithStore immediately.
But the store is created right after and it currently takes an already created history as an argument.

The store creation function doesn't use the history though so it could be replaced with something like:

const history_holder = {}
function get_history() { return history_holder.history }
const store = create_store(..., get_history, ...)
const history = syncHistoryWithStore(create_history(...))
history_holder.history = history

And also history would get replaced with get_history() in the two middlewares:
https://github.com/halt-hammerzeit/react-isomorphic-render/blob/master/source/redux/middleware/history%20middleware.js
https://github.com/halt-hammerzeit/react-isomorphic-render/blob/master/source/redux/middleware/preloading%20middleware.js

So, wrapping with syncHistoryWithStore could be done (on the client side).

As for the server side, history is created here:
https://github.com/halt-hammerzeit/react-isomorphic-render/blob/master/source/page-server/render.js#L47

Again, the same situation: history is created before the store, and the store creation function is passed the history parameter which it doesn't use immediately so it could be analogously replaced with the same get_history() trick.
After the await redux_initialize call the store is available as parameters.store.

So it seems that the wrapping can be done both on client and server.

So if one forks this project, performs the changes, tests it both with javascript enabled and javascript disabled, and in case that works as intended I would think on a new configuration parameter like history.wrap.

I myself am not using react-router-redux, using @withRouter instead.

from react-pages.

catamphetamine avatar catamphetamine commented on May 28, 2024

I was thinking about making this change.
Have you started already?

from react-pages.

lamyat2005 avatar lamyat2005 commented on May 28, 2024

Not yet, much appreciated!

from react-pages.

catamphetamine avatar catamphetamine commented on May 28, 2024

Released [email protected].
Didn't check it so you're gonna be the beta-tester.

from react-pages.

lamyat2005 avatar lamyat2005 commented on May 28, 2024

However one more thing is in order for react-router-redux to work, need to add

import {routerMiddleware} from 'react-router-redux';

const middleware = [
    routerMiddleware(history),
];

applyMiddleware(...middleware)(createStore)(reducers, initialState);

I am not sure in react-isomorphic-render.js

reduxMiddleware: () => [routerMiddleware(history)],

how I can get history? Thanks very much in advance.

from react-pages.

catamphetamine avatar catamphetamine commented on May 28, 2024

How do they pass routerMiddleware(history) to createStore when history itself needs store to be created in the first place as you described in your first post

from react-pages.

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.