Last active
February 21, 2018 17:43
-
-
Save theRemix/a61bf01783d8f7fdd6702e13a7c9582b to your computer and use it in GitHub Desktop.
Submit Form via xhr using state values from onion
This file contains hidden or 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
// 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 | |
} | |
})) | |
} |
This file contains hidden or 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
// 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