MCPcopy Index your code
hub / github.com/electrodejs/deprecated-electrode-redux-router-engine

github.com/electrodejs/deprecated-electrode-redux-router-engine @v1.2.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.2.4 ↗ · + Follow
28 symbols 40 edges 7 files 0 documented · 0% updated 8y ago★ 109
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Electrode Redux Router Engine

NPM version Build Status Dependency Status

Handle async data for React Server Side Rendering using react-router, Redux, and the Redux Server Rendering pattern.

Install

$ npm install -save electrode-redux-router-engine

Usage

You need to specify your routes according to react-router's specs.

For example, a file routes.jsx:

import { Route, IndexRoute, Redirect } from "react-router";

export default (
  <Route path="/test" component={Page}>
    <IndexRoute component={Home}/>
    <Redirect from="source" to="target" />
  </Route>
);

For each route, you can add an optional attribute methods to specify the HTTP methods you want the route to allow.

i.e. <Route methods="get,post" path="/form" component={Form}>

If the attribute is not specified then it's defaulted to "get".

And an example using the Redux Async Actions pattern:


const ReduxRouterEngine = require("electrode-redux-router-engine");

function createReduxStore(req, match) {
    // this refs to engine

    const store = configureStore();

    return Promise.all([
      store.dispatch(boostrapApp())
      // dispatch any other asynchronous actions here
    ]).then( () => {
      return store;
    });
}

const routes = require("./routes");

const engine = new ReduxRouterEngine({routes, createReduxStore});

// express or Hapi route handler:

function handler(req, res) {
  engine.render(req)
    .then( (result) => {
      // send full HTML with result back using res
    });
}

API

constructor(options)

Where options could contain the following fields:

  • routes - required The react-router routes
  • createReduxStore - required async callback that returns a promise resolving to the Redux store
    • It should take (req, match) arguments where match is react-router's match result.
    • If it's a function then its this references the engine instance.
  • withIds - optional boolean to indicate whether to render with react-dataids.
  • stringifyPreloadedState optional callback to return string for the preloaded state
  • logError - optional callback to log any error
    • It should take (req, err) arguments
    • If it's a function then its this references the engine instance
  • renderToString - optional callback to provide custom renderToString
    • It should take (req, store, match, withIds) arguments

engine.render(req, options)

Method to render a route.

  • req - express/Hapi request object
  • options - override options passed to constructor
    • withIds
    • stringifyPreloadedState
    • createReduxStore

If everything worked out, then it returns a promise resolving to:

{
  status: 200,
  html: // string from React renderToString,
  prefetch: // string from stringifyPreloadedState
}

If error occured, then it returns a promise resolving to:

{
  status: react-router status or 500,
  message: err.message,
  path: // request path,
  _err: // original error object
}

If no route matched, then it returns a promise resolving to:

{
  status: 404,
  message: `router-resolver: Path <path> not found`
}

If react-router found a redirect route, then it returns a promise resolving to:

{
  status: 302,
  path: // redirect location
}

Built with :heart: by Team Electrode @WalmartLabs.

Core symbols most depended-on inside this repo

render
called by 15
test/routes.jsx
_matchRoute
called by 1
lib/redux-router-engine.js
_handleRender
called by 1
lib/redux-router-engine.js
_renderToString
called by 1
lib/redux-router-engine.js
constructor
called by 0
lib/redux-router-engine.js
render
called by 0
lib/redux-router-engine.js
render
called by 0
test/bad-routes.jsx
render
called by 0
test/bad-routes.jsx

Shape

Class 14
Method 11
Function 3

Languages

TypeScript100%

Modules by API surface

lib/redux-router-engine.js7 symbols
test/routes.jsx6 symbols
test/error-routes.jsx6 symbols
test/bad-routes.jsx6 symbols
test/get-index-routes.jsx2 symbols
test/spec/redux-router-engine.spec.js1 symbols

For agents

$ claude mcp add deprecated-electrode-redux-router-engine \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page