Skip to content

Instantly share code, notes, and snippets.

@tamlyn
Created May 14, 2018 16:42
Show Gist options
  • Save tamlyn/9275ce73f6d21200a39d822a497b96d5 to your computer and use it in GitHub Desktop.
Save tamlyn/9275ce73f6d21200a39d822a497b96d5 to your computer and use it in GitHub Desktop.
'use strict';
let fact = (() => {
var _ref = _asyncToGenerator(function* () {
const response = yield fetch('https://catfact.ninja/fact');
const data = yield response.json();
return data.fact;
});
return function fact() {
return _ref.apply(this, arguments);
};
})();
function _asyncToGenerator(fn) {
return function () {
var gen = fn.apply(this, arguments);
return new Promise(function (resolve, reject) {
function step(key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
return Promise.resolve(value).then(function (value) {
step("next", value);
}, function (err) {
step("throw", err);
});
}
}
return step("next");
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment