Created
September 8, 2015 06:37
-
-
Save theptrk/ea3ff8f754faf3bc6b04 to your computer and use it in GitHub Desktop.
Flux with promises
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
import Alt from 'alt'; | |
const alt = new Alt(); | |
export default alt; |
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
import KaleActions from './KaleActions'; | |
import React from 'react'; | |
export default class KaleForm extends React.Component { | |
render() { | |
return ( | |
<form onSubmit={this.submitFn.bind(this)}> | |
<input type='text' name='kale-dish'/> | |
<input type='text' name='kale-dish-review'/> | |
<input type='submit' value='Submit'/> | |
</form> | |
); | |
} | |
submitFn(data) { | |
return KaleActions.create(data); | |
} | |
} |
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
import alt from '../libs/alt'; | |
class KaleActions { | |
create(data) { | |
return new Promise((resolve, reject) => { | |
var post = $.ajax({ | |
type: 'POST', | |
data: data, | |
url: '/kaleapi', | |
}); | |
post.done((postResponse) => { | |
resolve(postResponse); | |
// dispatch eventually to the store | |
this.dispatch(postResponse); | |
}); | |
post.fail((postError) => { | |
reject(postError); | |
}); | |
}); | |
} | |
} | |
export default alt.createActions(KaleActions); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment