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.
- Host: GitHub
- URL: https://github.com/noderaider/fire-hydrant
- Owner: noderaider
- License: mit
- Created: 2016-05-17T07:28:02.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-05-19T04:06:49.000Z (about 9 years ago)
- Last Synced: 2024-12-15T02:30:29.871Z (5 months ago)
- Topics: deserialization, fire-hydrant, immutables, partial-immutables, serialization, server-side-rendering
- Language: JavaScript
- Homepage: http://fire-hydrant.js.org/
- Size: 136 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fire-hydrant
**lightweight hydration and serialization of state, targeted at Redux Server Side Rendering and ImmutableJS**
[](https://nodei.co/npm/fire-hydrant/)

## 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(