Skip to content

Instantly share code, notes, and snippets.

@tornqvist
Last active December 18, 2017 12:33
Show Gist options
  • Save tornqvist/840a5a60cfce7f2e540b6f85c2a02290 to your computer and use it in GitHub Desktop.
Save tornqvist/840a5a60cfce7f2e540b6f85c2a02290 to your computer and use it in GitHub Desktop.
Choo cache thing
var html = require('choo/html')
var cache = require('choo/cache')
var Nanocomponent = require('nanocomponent')
class Button extends Nanocomponent {
// this is where you'd implement custom gc logic
static discard (instance) {
return !instance.element
}
update (text, onclick) {
return this.isDisabled !== !!onclick
}
createElement (text, onclick) {
this.isDisabled = !!onclick
return html`
<button disabled="${!onclick}" onclick=${onclick}>${text}</button>
`
}
}
module.exports = cache(Button)
var html = require('choo/html')
var button = require('./button')
// button.get('form-button') -> Instance of button with key "form-button"
module.exports = form
function form (isLoading, emit) {
return html`
<form>
${button.render('form-button', 'Click me!', isLoading ? null : onclick)}
</form>
`
function onclick () {
emit('submit')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment