Created
September 13, 2015 01:56
-
-
Save bendrucker/c0677e04548c25bcbd08 to your computer and use it in GitHub Desktop.
Here's how I'd build a simple form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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