Skip to content

Instantly share code, notes, and snippets.

@bendrucker
Created September 13, 2015 01:56
Show Gist options
  • Save bendrucker/c0677e04548c25bcbd08 to your computer and use it in GitHub Desktop.
Save bendrucker/c0677e04548c25bcbd08 to your computer and use it in GitHub Desktop.
Here's how I'd build a simple form
var Struct = require('observ-struct')
var Email = require('email-input')
var Password = require('password-input') // doesn't actually exist yet
var value = require('observ-value')
var h = require('virtual-dom/h')
var when = require('value-when')
function LoginForm (data) {
data = data || {}
return State({
email: Email(data.email),
password: Password(data.password)
})
}
LoginForm.valid = valid
function valid (state) {
state = value(state)
return state.email.valid && state.password.valid
}
LoginForm.render = function render (state) {
return h('form', [
Email.render(state.email),
Password.render(state.email),
h('button', {
type: 'submit',
attributes: {
disabled: when(valid(state), '')
}
})
])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment