Convert dev scripts to use JSX (#7555)

feature/default_network_editable
Whymarrh Whitby 5 years ago committed by GitHub
parent f5c496ffcd
commit 1501742d68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 60
      development/mock-dev.js
  2. 57
      development/selector.js

@ -10,13 +10,13 @@
* without having to re-open the plugin or even re-build it. * without having to re-open the plugin or even re-build it.
*/ */
import React from 'react'
const render = require('react-dom').render const render = require('react-dom').render
const h = require('react-hyperscript')
const Root = require('../ui/app/pages') const Root = require('../ui/app/pages')
const configureStore = require('../ui/app/store/store') const configureStore = require('../ui/app/store/store')
const actions = require('../ui/app/store/actions') const actions = require('../ui/app/store/actions')
const backGroundConnectionModifiers = require('./backGroundConnectionModifiers') const backGroundConnectionModifiers = require('./backGroundConnectionModifiers')
const Selector = require('./selector') import Selector from './selector'
const MetamaskController = require('../app/scripts/metamask-controller') const MetamaskController = require('../app/scripts/metamask-controller')
const firstTimeState = require('../app/scripts/first-time-state') const firstTimeState = require('../app/scripts/first-time-state')
const ExtensionPlatform = require('../app/scripts/platforms/extension') const ExtensionPlatform = require('../app/scripts/platforms/extension')
@ -106,40 +106,38 @@ function startApp () {
body.appendChild(container) body.appendChild(container)
render( render(
h('.super-dev-container', [ <div className="super-dev-container">
<button
h('button', { onClick={(ev) => {
onClick: (ev) => {
ev.preventDefault() ev.preventDefault()
store.dispatch(actions.update('terms')) store.dispatch(actions.update('terms'))
}, }}
style: { style={{
margin: '19px 19px 0px 19px', margin: '19px 19px 0px 19px',
}, }}
}, 'Reset State'), >
Reset State
h(Selector, { </button>
actions, <Selector
selectedKey: selectedView, states={states}
states, selectedKey={selectedView}
store, actions={actions}
modifyBackgroundConnection, store={store}
backGroundConnectionModifiers, modifyBackgroundConnection={modifyBackgroundConnection}
}), backGroundConnectionModifiers={backGroundConnectionModifiers}
/>
h('#app-content', { <div
style: { id="app-content"
style={{
height: '500px', height: '500px',
width: '360px', width: '360px',
boxShadow: 'grey 0px 2px 9px', boxShadow: 'grey 0px 2px 9px',
margin: '20px', margin: '20px',
}, }}
}, [ >
h(Root, { <Root store={store}/>
store: store, </div>
}), </div>,
]), container,
)
]
), container)
} }

@ -1,16 +1,10 @@
const Component = require('react').Component import PropTypes from 'prop-types'
const h = require('react-hyperscript') import React, {Component} from 'react'
const inherits = require('util').inherits
module.exports = NewComponent export default class Selector extends Component {
state = {}
inherits(NewComponent, Component) render () {
function NewComponent () {
Component.call(this)
}
NewComponent.prototype.render = function () {
const props = this.props
const { const {
states, states,
selectedKey, selectedKey,
@ -18,25 +12,38 @@ NewComponent.prototype.render = function () {
store, store,
modifyBackgroundConnection, modifyBackgroundConnection,
backGroundConnectionModifiers, backGroundConnectionModifiers,
} = props } = this.props
const selected = this.state.selected || selectedKey
const state = this.state || {}
const selected = state.selected || selectedKey
return h('select', { return (
style: { <select
margin: '20px 20px 0px', style={{ margin: '20px 20px 0px' }}
}, value={selected}
value: selected, onChange={(event) => {
onChange: (event) => {
const selectedKey = event.target.value const selectedKey = event.target.value
const backgroundConnectionModifier = backGroundConnectionModifiers[selectedKey] const backgroundConnectionModifier = backGroundConnectionModifiers[selectedKey]
modifyBackgroundConnection(backgroundConnectionModifier || {}) modifyBackgroundConnection(backgroundConnectionModifier || {})
store.dispatch(actions.update(selectedKey)) store.dispatch(actions.update(selectedKey))
this.setState({ selected: selectedKey }) this.setState({ selected: selectedKey })
}, }}
}, Object.keys(states).map((stateName) => { >
return h('option', { value: stateName }, stateName) {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…
Cancel
Save