An open API service indexing awesome lists of open source software.

https://github.com/noderaider/fire-hydrant

Functions to serialize and hydrate state objects, partial immutables, and full immutables.
https://github.com/noderaider/fire-hydrant

deserialization fire-hydrant immutables partial-immutables serialization server-side-rendering

Last synced: 5 months ago
JSON representation

Functions to serialize and hydrate state objects, partial immutables, and full immutables.

Awesome Lists containing this project

README

        

# fire-hydrant

**lightweight hydration and serialization of state, targeted at Redux Server Side Rendering and ImmutableJS**

[![NPM](https://nodei.co/npm/fire-hydrant.png?stars=true&downloads=true)](https://nodei.co/npm/fire-hydrant/)

![dependencies](https://raw.githubusercontent.com/cchamberlain/fire-hydrant/master/public/images/dependencies.png)

## Install

`npm i -S fire-hydrant`

## Documentation

Functions used to store state objects, partial immutables, and full immutables to strings and restore them back to their original state.

## [react-router](https://npmjs.com/package/react-router) and [react-router-redux](https://npmjs.com/package/react-router-redux) with async routes example

#### configureStore.js

```js
import { createStore, applyMiddleware } from 'redux'
import { routerMiddleware } from 'react-router-redux'
import { combineReducers } from 'redux'
import * as reducers from '../reducers'

export default function configureStore(history, initialState) {
const reducer = combineReducers(reducers)
const enhancer = applyMiddleware([ routerMiddleware(history) ])
return createStore(reducer, initialState, enhancer)
}
```

#### createRouter.js

**Plug this router into your server.use()**

```jsx
import React from 'react'
import Router from 'router'
import Immutable from 'immutable'
import { Provider } from 'react-redux'
import { createMemoryHistory, match, RouterContext } from 'react-router'
import { syncHistoryWithStore } from 'react-router-redux'

import { serialize, createInitialState } from 'fire-hydrant'

/** Routes can be direct server defined routes or a webpack bundle */
import routes from './routes'

const InitialState = ({ state }) => {
const serialized = serialize(state, { Immutable })
const __html = `window.__initialState__ = ${serialized}`
return
}

//-- ALTERNATE: Import createInitialState component factory for sanity checks and less boilerplate.
const InitialState = createInitialState({ React, Immutable })

const HTML = ({ content, store }) => {
const state = store ? store.getState() : noop()

return (



Fire Hydrant







)
}

const renderHTML = props => `
${renderToString(