Commit 179e0aff by hfpp2012 yinsigan

mapDispatchToProps

1 parent d422a40f
export const toggleTodo = (id) => ({
type: 'TOGGLE_TODO',
id
})
export const cloneElement = (element) => ({
type: 'CLONE_ELEMENT',
element
})
......@@ -4,13 +4,10 @@ import ReactAddonsUpdate from 'react-addons-update'
import autobind from 'autobind-decorator'
import { connect } from 'react-redux'
import { cloneElement } from '../actions/headergroup';
@autobind
class ElementGroup extends React.Component {
cloneElement(element) {
const elements = ReactAddonsUpdate(this.state.elements, { $push: [element] })
this.setState({elements: elements})
}
deleteElement(element) {
const index = this.state.elements.indexOf(element)
const elements = ReactAddonsUpdate(this.state.elements, { $splice: [[index, 1]] })
......@@ -28,13 +25,13 @@ class ElementGroup extends React.Component {
}
render() {
const { elements } = this.props
const { elements, cloneElement } = this.props
return (
<div>
{
elements.map(function(element) {
return (
<Element meta_element={ element } key={ "key_" + element.id } id={ element.id } name={ element.name } initialPos={ element.initialPos } target_type={ element.target_type } handleCloneElement={ this.cloneElement } handleDeleteElement={ this.deleteElement } handleDeleteLastElement={ this.deleteLastElement } />
<Element meta_element={ element } key={ "key_" + element.id } id={ element.id } name={ element.name } initialPos={ element.initialPos } target_type={ element.target_type } handleCloneElement={ cloneElement } handleDeleteElement={ this.deleteElement } handleDeleteLastElement={ this.deleteLastElement } />
)
}.bind(this))
}
......@@ -48,6 +45,7 @@ const mapStateToProps = (state, ownProps) => ({
})
const mapDispatchToProps = (dispatch, ownProps) => ({
cloneElement: cloneElement
})
const VisibleElementGroup = connect(
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!