-
Notifications
You must be signed in to change notification settings - Fork 0
/
UI.js
52 lines (45 loc) · 1.1 KB
/
UI.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const React = require('react')
const h = require('react-hyperscript')
const debounce = require('debounce')
const CodeMirror = require('react-codemirror2').Controlled
require('codemirror/mode/pug/pug')
module.exports = class extends React.Component {
constructor (props) {
super(props)
this.dsaveUI = debounce(this.saveUI.bind(this), 2000).bind(this)
this.state = {
code: this.props.code,
changed: false
}
}
static getDerivedStateFromProps (props, state) {
if (props.code !== state.code) {
return {
code: state.changed ? state.code : props.code,
changed: false
}
}
return null
}
render () {
return (
h('div', [
h('h1', 'UI'),
h(CodeMirror, {
value: this.state.code,
onBeforeChange: (editor, data, code) => {
this.setState({code, changed: true})
},
onChange: this.dsaveUI,
options: {
viewportMargin: Infinity,
mode: 'pug'
}
})
])
)
}
saveUI (editor, data, uicode) {
this.props.save(uicode)
}
}