Skip to content
This repository has been archived by the owner on Jan 22, 2020. It is now read-only.

Support redux #171

Merged
merged 2 commits into from
Aug 3, 2016
Merged

Support redux #171

merged 2 commits into from
Aug 3, 2016

Conversation

7aos
Copy link
Contributor

@7aos 7aos commented Aug 2, 2016

This is to bring in redux/react-redux support: #168

  • Initial state: the data passed via res.render is set to be the initial state
  • Store creation: user provide a function through serverconfig or client option to create a store. This function accepts init state and produces store (basically it is a curry function).
  • Store binding: react-redux Provider is used to bind the store to the root element, which can be react-router component if react-router is used or a vanilla react component otherwise.

Store initialization at client side
Redux store create function initStore is passed to react-engine.client via boot options, which is invoked when wrap root component with react-redux Provider. The root component can be either react-router component or a vanilla react component.

Example

var reducer;
...
client.boot({
  ...
  redux: {
    initStore: function(state) {
      return Redux.createStore(reducer, state);
    }
  }
});

Store initialization at server side
Similarly, a create function is needed to initialize the redux store. This function is provided through an optional config.
Sample Kraken config

{
  ...
  "view engines": {
    "jsx": {
      "module": "react-engine/lib/server",
      "renderer": {
        "method": "create",
        "arguments": [
          {
            "routes": "require:./.build/routes/index.js",
            "redux": {
              "initStore": "path:./.build/store/init.js"
            }
          }
        ]
      }
    }
  }
 ...
}

@SOSANA
Copy link

SOSANA commented Aug 4, 2016

@samsel @taosbeta any change we could provide a redux example in this repo?

@7aos
Copy link
Contributor Author

7aos commented Aug 4, 2016 via email

@IRT-fbachmann
Copy link

Can the function initStore be called asynchronously? Especially interesting for server side rendering and prefetching initial state...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants