aboutsummaryrefslogtreecommitdiffstats
path: root/development/selector.js
blob: b58904cdf0a08f6cae0429f5d8b88c3f0884c99d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits

module.exports = NewComponent

inherits(NewComponent, Component)
function NewComponent () {
  Component.call(this)
}

NewComponent.prototype.render = function () {
  const props = this.props
  let { states, selectedKey, actions, store } = props

  const state = this.state || {}
  const selected = state.selected || selectedKey

  return h('select', {
    value: selected,
    onChange:(event) => {
      const selectedKey = event.target.value
      store.dispatch(actions.update(selectedKey))
      this.setState({ selected: selectedKey })
    },
  }, Object.keys(states).map((stateName) => {
    return h('option', { value: stateName }, stateName)
  }))

}