You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

helpers.js 929B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * Create deferred object.
  3. * @returns {{promise, resolve, reject}}
  4. */
  5. export function createDeferred () {
  6. let deferred = {};
  7. deferred.promise = new Promise(function (resolve, reject) {
  8. deferred.resolve = resolve;
  9. deferred.reject = reject;
  10. });
  11. return deferred;
  12. }
  13. /**
  14. * Reload page.
  15. */
  16. export function reload () {
  17. window.location.reload();
  18. }
  19. /**
  20. * Redirects to new URL.
  21. * @param {string} url the URL pointing to the location where the user should
  22. * be redirected to.
  23. */
  24. export function redirect (url) {
  25. window.location.replace(url);
  26. }
  27. /**
  28. * Prints the error and reports it to the global error handler.
  29. * @param e {Error} the error
  30. * @param msg {string} [optional] the message printed in addition to the error
  31. */
  32. export function reportError (e, msg = "") {
  33. console.error(msg, e);
  34. if(window.onerror)
  35. window.onerror(msg, null, null,
  36. null, e);
  37. }