Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yesmeck/redux-polymorphic
Reuse your reduers
https://github.com/yesmeck/redux-polymorphic
Last synced: about 1 month ago
JSON representation
Reuse your reduers
- Host: GitHub
- URL: https://github.com/yesmeck/redux-polymorphic
- Owner: yesmeck
- Created: 2016-01-12T17:23:43.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-07-19T16:09:21.000Z (over 8 years ago)
- Last Synced: 2024-11-01T12:05:12.100Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 19.5 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Redux Polymorphic
**Deprecated, see https://github.com/erikras/multireducer**
Another attempt to reuse your reduers, inspired from [multireducer](https://github.com/erikras/multireducer)
## Installation
```
npm i --save redux-polymorphic
```## How It Works
**STEP 1:**
```javascript
import { polymorphicReducer } from 'redux-polymorphic'
// In case you are using Immutable.js, you can:
// import { polymorphicReducer } from 'redux-polymorphic/immutable'
import list from './reduers/list'const reducer = combineReducers({
list: polymorphicReducer({
proposed: list,
scheduled: list,
active: list,
complete: list
})
})
```**STEP 2:**
```javascript
import React, { Component, PropTypes } from 'react'
import { bindActionCreators } from 'redux-polymorphic'
import { connect } from 'react-redux'
import { add, remove } from './actions/list'class TodoListComponent extends Component {
static propTypes = {
list: PropTypes.array.isRequired
}render() {
const { add, list, remove } = this.props
return (
add('New Item')}>Add
{list.map((item, index) =>
- )}
{item}
( remove(item)}>X)
)
}
}ListComponent = connect(
(state, { as }) => ({
list: state.list[as]
}),
(dispatch, { as }) => bindActionCreators({ add, remove }, dispatch, as)
)(ListComponent)export default ListComponent
```**STEP 3:**
```javascript
render() {
return (
Lists
)
}
```### Manually dispatch
```javascript
import { polymorphicDispatch } from 'redux-polymorphic'
import { add, remove } from './actions/list'polymorphicDispatch(dispatch, 'tom')(add)
```