Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

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

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)
```