Create a virtual-dom widget.
$ npm install virtual-widget
// map.js
const virtualWidget = require('virtual-widget')
module.exports = virtualWidget({
init: function (state) {
this.state = state
var elem = document.createElement('div')
this.map = GoogleMap(elem)
this.map.setPosition(this.state.position)
return elem
},
update: function (prev, el) {
this.map = this.map || prev.map
this.map.setPosition(this.state.position)
},
destroy: function (el) {
// clear position
this.state.position.set({ x: 0, y: 0 })
}
})
// view.js
const map = require('./map')
module.exports = view
function view (h, state) {
return h('section.foo', [
map(state)
])
}
Create a new virtual-widget using hooks. The following hooks are available: