Commit f3002db8 by hfpp2012 yinsigan

redux

1 parent 89a2ec97
...@@ -7,6 +7,7 @@ export const deleteLastElement = () => ({ ...@@ -7,6 +7,7 @@ export const deleteLastElement = () => ({
type: 'DELETE_LAST_ELEMENT' type: 'DELETE_LAST_ELEMENT'
}) })
export const deleteElement = () => ({ export const deleteElement = (element) => ({
type: 'DELETE_ELEMENT' type: 'DELETE_ELEMENT',
element
}) })
...@@ -9,12 +9,6 @@ import * as HeaderGroupActions from '../actions/headergroup' ...@@ -9,12 +9,6 @@ import * as HeaderGroupActions from '../actions/headergroup'
@autobind @autobind
class ElementGroup extends React.Component { class ElementGroup extends React.Component {
deleteElement(element) {
const index = this.state.elements.indexOf(element)
const elements = ReactAddonsUpdate(this.state.elements, { $splice: [[index, 1]] })
this.setState({elements: elements})
}
sidebar() { sidebar() {
return document.getElementById('sidebar') return document.getElementById('sidebar')
} }
...@@ -26,7 +20,7 @@ class ElementGroup extends React.Component { ...@@ -26,7 +20,7 @@ class ElementGroup extends React.Component {
{ {
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={ actions.cloneElement } handleDeleteElement={ this.deleteElement } handleDeleteLastElement={ actions.deleteLastElement } /> <Element meta_element={ element } key={ "key_" + element.id } id={ element.id } name={ element.name } initialPos={ element.initialPos } target_type={ element.target_type } handleCloneElement={ actions.cloneElement } handleDeleteElement={ actions.deleteElement } handleDeleteLastElement={ actions.deleteLastElement } />
) )
}.bind(this)) }.bind(this))
} }
......
...@@ -15,6 +15,12 @@ const headergroup = (state = init_state, action) => { ...@@ -15,6 +15,12 @@ const headergroup = (state = init_state, action) => {
return [ return [
...state.slice(0, -1), ...state.slice(0, -1),
] ]
case 'DELETE_ELEMENT':
const index = state.indexOf(action.element)
return [
...state.slice(0, index),
...state.slice(index + 1)
]
default: default:
return state return state
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!