0.1.71 • Published 3 years ago

@onereach/lib-assist v0.1.71

Weekly downloads
86
License
UNLICENSED
Repository
-
Last release
3 years ago

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)
  }
};
0.1.71

3 years ago

0.1.70

3 years ago

0.1.68

3 years ago

0.1.69

3 years ago

0.1.67

3 years ago

0.1.63

3 years ago

0.1.64

3 years ago

0.1.65

3 years ago

0.1.66

3 years ago

0.1.62

3 years ago

0.1.61

3 years ago

0.1.56

3 years ago

0.1.57

3 years ago

0.1.58

3 years ago

0.1.59

3 years ago

0.1.60

3 years ago

0.1.52

3 years ago

0.1.53

3 years ago

0.1.54

3 years ago

0.1.55

3 years ago

0.1.50

3 years ago

0.1.51

3 years ago

0.1.49

3 years ago

0.1.47

3 years ago

0.1.48

3 years ago

0.1.45

4 years ago

0.1.46

4 years ago

0.1.42

4 years ago

0.1.43

4 years ago

0.1.44

4 years ago

0.1.41

4 years ago

0.1.40

4 years ago

0.1.39

4 years ago

0.1.38

4 years ago

0.1.37

4 years ago

0.1.36

4 years ago

0.1.35

4 years ago

0.1.34

4 years ago

0.1.32

4 years ago

0.1.33

4 years ago

0.1.30

4 years ago

0.1.31

4 years ago

0.1.29

4 years ago

0.1.28

4 years ago

0.1.27

4 years ago

0.1.26

4 years ago

0.1.25

4 years ago

0.1.24

4 years ago

0.1.23

4 years ago

0.1.22

4 years ago

0.1.21

4 years ago

0.1.20

4 years ago

0.1.19

4 years ago

0.1.18

4 years ago

0.1.17

4 years ago

0.1.15

4 years ago

0.1.16

4 years ago

0.1.13

4 years ago

0.1.14

4 years ago

0.1.12

4 years ago

0.1.11

4 years ago

0.1.10

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.9

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago