Skip to content

Instantly share code, notes, and snippets.

@theRemix
Last active February 21, 2018 17:43
Show Gist options
  • Save theRemix/a61bf01783d8f7fdd6702e13a7c9582b to your computer and use it in GitHub Desktop.
Save theRemix/a61bf01783d8f7fdd6702e13a7c9582b to your computer and use it in GitHub Desktop.
Submit Form via xhr using state values from onion
// sampleCombine will emit when source stream emits only
// this is correct
function intent (sources$: Sources) {
return sources$.DOM.select('form')
.events('submit', { preventDefault : true })
.compose(sampleCombine(sources$.onion.state$))
.map(([ event, state ]) => ({
url: '/api/endpoint',
category: 'Form',
method: 'POST',
type: 'application/json',
send: {
animal : state.animal.value,
noise : state.noise.value
}
}))
}
// combine will emit on form submit or on state change
// this is incorrect
function intent (sources$: Sources) {
return xs.combine(sources$.onion.state$, sources$.DOM.select('form').events('submit', { preventDefault : true }))
.map(([ state, event ]) => ({
url: '/api/endpoint',
category: 'Form',
method: 'POST',
type: 'application/json',
send: {
animal : state.animal.value,
noise : state.noise.value
}
}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment