Skip to content

Instantly share code, notes, and snippets.

@gx0r
Created November 18, 2015 20:23
Show Gist options
  • Select an option

  • Save gx0r/4d79f72ea659bd73117c to your computer and use it in GitHub Desktop.

Select an option

Save gx0r/4d79f72ea659bd73117c to your computer and use it in GitHub Desktop.
Better requestWithFeedback
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