@onereach/lib-assist v0.1.71
Lib assist
Project setup
npm i
Compiles and hot-reloads for development
npm run dev
Compiles and minifies for production lib
npm run build:lib
To see the project in Action Desk
Create an empty View and paste the next code to its 'Details'
Template:
<lib-assist></lib-assist>
Code:
function getScript(url) {
return new Promise((resolve, reject) => {
var xhr = new XMLHttpRequest();
xhr.open("get", url);
xhr.onload = function() {
if (this.status >= 200 && this.status < 300) {
resolve(xhr.response);
} else {
reject({
status: this.status,
statusText: xhr.statusText,
});
}
};
xhr.onerror = function() {
reject({
status: this.status,
statusText: xhr.statusText,
});
};
xhr.send();
});
};
function loadScript(url) {
return new Promise((resolve, reject) => {
let script = document.createElement('script');
script.src = url;
script.async = true;
script.onload = resolve;
script.onerror = reject;
document.body.appendChild(script);
});
}
function loadComponent(url, name, dev) {
return async () => {
try {
if (!dev) {
let scope = {};
let data = await getScript(url);
window.Vue = Vue;
(new Function("Vue", `let vue = Vue;let self = this;${data}`)).bind(scope, Vue)();
delete window.Vue
return (name) ? scope[name] : scope;
} else {
window.Vue = Vue;
await loadScript(url);
delete window.Vue
return window[name]
}
} catch (e) {
console.error(e)
}
}
}
return {
components: {
libAssist: loadComponent('https://unpkg.com/@onereach/lib-assist',"libAssist", true)
}
};
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago