Created
November 18, 2015 20:23
-
-
Save gx0r/4d79f72ea659bd73117c to your computer and use it in GitHub Desktop.
Better requestWithFeedback
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
| var m = require('mithril'); | |
| function requestWithFeedback(args) { | |
| var completed = m.prop(false); | |
| var complete = function() { | |
| completed(true); | |
| } | |
| var data = m.prop(); | |
| args.background = true | |
| if (args.config) { | |
| var suppliedConfig = args.config; | |
| } | |
| args.config = function (xhr) { | |
| xhr.timeout = 30000; | |
| xhr.ontimeout = function() { | |
| complete(); | |
| } | |
| suppliedConfig(xhr); | |
| } | |
| return { | |
| promise: m.request(args).then(function (stuff) { | |
| complete(); | |
| data(stuff); | |
| return stuff; | |
| }), | |
| ready: completed, | |
| data: data | |
| } | |
| } | |
| module.exports = requestWithFeedback; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment