Convert dev scripts to use JSX (#7555)
parent
f5c496ffcd
commit
1501742d68
@ -1,42 +1,49 @@ |
||||
const Component = require('react').Component |
||||
const h = require('react-hyperscript') |
||||
const inherits = require('util').inherits |
||||
import PropTypes from 'prop-types' |
||||
import React, {Component} from 'react' |
||||
|
||||
module.exports = NewComponent |
||||
export default class Selector extends Component { |
||||
state = {} |
||||
|
||||
inherits(NewComponent, Component) |
||||
function NewComponent () { |
||||
Component.call(this) |
||||
} |
||||
|
||||
NewComponent.prototype.render = function () { |
||||
const props = this.props |
||||
const { |
||||
states, |
||||
selectedKey, |
||||
actions, |
||||
store, |
||||
modifyBackgroundConnection, |
||||
backGroundConnectionModifiers, |
||||
} = props |
||||
render () { |
||||
const { |
||||
states, |
||||
selectedKey, |
||||
actions, |
||||
store, |
||||
modifyBackgroundConnection, |
||||
backGroundConnectionModifiers, |
||||
} = this.props |
||||
const selected = this.state.selected || selectedKey |
||||
|
||||
const state = this.state || {} |
||||
const selected = state.selected || selectedKey |
||||
|
||||
return h('select', { |
||||
style: { |
||||
margin: '20px 20px 0px', |
||||
}, |
||||
value: selected, |
||||
onChange: (event) => { |
||||
const selectedKey = event.target.value |
||||
const backgroundConnectionModifier = backGroundConnectionModifiers[selectedKey] |
||||
modifyBackgroundConnection(backgroundConnectionModifier || {}) |
||||
store.dispatch(actions.update(selectedKey)) |
||||
this.setState({ selected: selectedKey }) |
||||
}, |
||||
}, Object.keys(states).map((stateName) => { |
||||
return h('option', { value: stateName }, stateName) |
||||
})) |
||||
return ( |
||||
<select |
||||
style={{ margin: '20px 20px 0px' }} |
||||
value={selected} |
||||
onChange={(event) => { |
||||
const selectedKey = event.target.value |
||||
const backgroundConnectionModifier = backGroundConnectionModifiers[selectedKey] |
||||
modifyBackgroundConnection(backgroundConnectionModifier || {}) |
||||
store.dispatch(actions.update(selectedKey)) |
||||
this.setState({ selected: selectedKey }) |
||||
}} |
||||
> |
||||
{Object.keys(states).map((stateName, index) => { |
||||
return ( |
||||
<option key={index} value={stateName}> |
||||
{stateName} |
||||
</option> |
||||
) |
||||
})} |
||||
</select> |
||||
) |
||||
} |
||||
} |
||||
|
||||
Selector.propTypes = { |
||||
states: PropTypes.object.isRequired, |
||||
selectedKey: PropTypes.string.isRequired, |
||||
actions: PropTypes.object.isRequired, |
||||
store: PropTypes.object.isRequired, |
||||
modifyBackgroundConnection: PropTypes.func.isRequired, |
||||
backGroundConnectionModifiers: PropTypes.object.isRequired, |
||||
} |
||||
|
Loading…
Reference in new issue