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' ...@@ -4,13 +4,10 @@ import ReactAddonsUpdate from 'react-addons-update'
import autobind from 'autobind-decorator' import autobind from 'autobind-decorator'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { cloneElement } from '../actions/headergroup';
@autobind @autobind
class ElementGroup extends React.Component { class ElementGroup extends React.Component {
cloneElement(element) {
const elements = ReactAddonsUpdate(this.state.elements, { $push: [element] })
this.setState({elements: elements})
}
deleteElement(element) { deleteElement(element) {
const index = this.state.elements.indexOf(element) const index = this.state.elements.indexOf(element)
const elements = ReactAddonsUpdate(this.state.elements, { $splice: [[index, 1]] }) const elements = ReactAddonsUpdate(this.state.elements, { $splice: [[index, 1]] })
...@@ -28,13 +25,13 @@ class ElementGroup extends React.Component { ...@@ -28,13 +25,13 @@ class ElementGroup extends React.Component {
} }
render() { render() {
const { elements } = this.props const { elements, cloneElement } = this.props
return ( return (
<div> <div>
{ {
elements.map(function(element) { elements.map(function(element) {
return ( 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)) }.bind(this))
} }
...@@ -48,6 +45,7 @@ const mapStateToProps = (state, ownProps) => ({ ...@@ -48,6 +45,7 @@ const mapStateToProps = (state, ownProps) => ({
}) })
const mapDispatchToProps = (dispatch, ownProps) => ({ const mapDispatchToProps = (dispatch, ownProps) => ({
cloneElement: cloneElement
}) })
const VisibleElementGroup = connect( const VisibleElementGroup = connect(
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!