Last active
August 6, 2018 17:18
-
-
Save cowboyd/ad4ca858e0fc19fd316593c0366ed8cc to your computer and use it in GitHub Desktop.
Hypothetical React Event Pipeline
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
import { pipe as $, string, preventDefault, blockOn } from 'react-event-pipeline' | |
function onSubmit(form) { | |
return $(preventDefault, blockOn(() => form.isSubmittable), onSave(form.serialized)); | |
} | |
export default function Settings({ flares, knotsPerFlare, onSave }) { | |
return ( | |
<State type={Form} value={{ flares, knotsPerFlare }}> | |
{form => { | |
return ( | |
<form onSubmit={onSubmit(form)}> | |
<label> | |
Number of flares <input type="number" onChange={$(string, form.flares.set)} value={form.flares.state} /> | |
</label> | |
<label> | |
Knots per flare <input type="number" onChange={$(string, form.knotsPerFlare.set)} value={form.knotsPerFlare.state} /> | |
</label> | |
<button type="submit" disabled={form.isUnchanged}>Save</button> | |
</form> | |
) | |
}} | |
</State> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment