accounts-frontend/src/functions.js

49 lines
969 B
JavaScript
Raw Normal View History

let lastId = 0;
export function uniqueId(prefix = 'id') {
return `${prefix}${++lastId}`;
}
/**
* @param {object} obj
* @param {array} keys
*
* @return {object}
*/
export function omit(obj, keys) {
const newObj = {...obj};
keys.forEach((key) => {
Reflect.deleteProperty(newObj, key);
});
return newObj;
}
/**
* Asynchronously loads script
*
* @param {string} src
*
* @return {Promise}
*/
export function loadScript(src) {
const script = document.createElement('script');
script.async = true;
script.defer = true;
script.src = src;
return new Promise((resolve, reject) => {
script.onlaod = resolve;
script.onerror = reject;
document.body.appendChild(script);
});
}
2016-08-14 14:31:04 +05:30
2016-08-22 09:58:05 +05:30
export const rAF = window.requestAnimationFrame
|| window.mozRequestAnimationFrame
|| window.webkitRequestAnimationFrame
|| window.msRequestAnimationFrame
|| ((cb) => setTimeout(cb, 1000 / 60));