├── package.json
├── index.js
├── LICENSE
└── README.md
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@meforma/vue-wait-for",
3 | "version": "0.0.2",
4 | "description": "A loader manager for vuejs 3 with reactive method",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git+https://github.com/MeForma/vue-wait-for.git"
12 | },
13 | "keywords": [
14 | "wait",
15 | "waiting",
16 | "loader",
17 | "management",
18 | "manager",
19 | "vue-wait",
20 | "vue",
21 | "vue3",
22 | "js"
23 | ],
24 | "author": "@jprodrigues70",
25 | "license": "MIT",
26 | "bugs": {
27 | "url": "https://github.com/MeForma/vue-wait-for/issues"
28 | },
29 | "homepage": "https://github.com/MeForma/vue-wait-for#readme"
30 | }
31 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | import { reactive } from "vue";
2 |
3 | class Wait {
4 | constructor() {
5 | this.list = reactive({});
6 | }
7 | is(name) {
8 | return !!this.list[name];
9 | }
10 | start(name) {
11 | return !this.list[name] && (this.list[name] = Date.now());
12 | }
13 | end(name) {
14 | const start = this.list[name];
15 | delete this.list[name];
16 | return Date.now() - start;
17 | }
18 | any() {
19 | return Object.keys(this.list).length;
20 | }
21 | clear() {
22 | let clearList = {};
23 | Object.keys(this.list).forEach((item) => {
24 | clearList[item] = this.end(item);
25 | });
26 | return clearList;
27 | }
28 | }
29 |
30 | export const $wait = new Wait();
31 |
32 | export default {
33 | install: (app) => {
34 | app.config.globalProperties.$wait = $wait;
35 | },
36 | };
37 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 MeForma!
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Vue Wait For
2 |
3 | A loader manager for vuejs 3 with reactive method
4 |
5 | ## Installation
6 |
7 | ```bash
8 | # yarn
9 | yarn add @meforma/vue-wait-for
10 |
11 | # npm
12 | npm install @meforma/vue-wait-for
13 | ```
14 |
15 | ## Import
16 |
17 | ```js
18 | // In you main.js
19 | // ... considering that your app creation is here
20 | import wait from "@meforma/vue-wait-for";
21 |
22 | createApp(App).use(wait).mount("#app");
23 | ```
24 |
25 | ## Usage
26 |
27 | ```html
28 |
29 |
30 |
Waiting Dogs Time...
31 |
Dogs are ready!!
32 |
33 |
34 |
35 |
52 | ```
53 |
54 | ## Methods
55 |
56 | ### start(name)
57 |
58 | Starts the wait for some word (string). You can't start the same wait more than one time, before execute end.
59 |
60 | ```js
61 | this.$wait.start("something");
62 | ```
63 |
64 | ### end(name)
65 |
66 | Kills the wait for some word (string), and returns the duration time of the wait in milliseconds.
67 |
68 | ```js
69 | this.$wait.end("something");
70 | ```
71 |
72 | ### is(name)
73 |
74 | Checks if exists a wait for some word (string).
75 |
76 | ```js
77 | this.$wait.is("something");
78 | ```
79 |
80 | ### any()
81 |
82 | Checks if exists any wait.
83 |
84 | ```js
85 | this.$wait.any();
86 | ```
87 |
88 | ### clear()
89 |
90 | Kills all waits, and returns a object with the duration time of all waits in milliseconds.
91 |
92 | ```js
93 | this.$wait.clear();
94 | ```
95 |
96 | ## License
97 |
98 | [MIT](LICENSE.txt) License
99 |
--------------------------------------------------------------------------------