Skip to content

Commit a32a97f

Browse files
committed
📝 improve docs and fix typos
1 parent 6991fe8 commit a32a97f

File tree

2 files changed

+56
-38
lines changed

2 files changed

+56
-38
lines changed

README.md

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,51 @@
44
[![Library minified size](https://badgen.net/bundlephobia/min/vue-loadable)](https://bundlephobia.com/result?p=vue-loadable)
55
[![Library minified + gzipped size](https://badgen.net/bundlephobia/minzip/vue-loadable)](https://bundlephobia.com/result?p=vue-loadable)
66

7+
`vue-loadable` can improve your loading state control by providing methods and helpers to manage it.
8+
9+
```html
10+
<template>
11+
<p v-if="$isLoading('initialize')">Initializing...</p>
12+
<div v-else>
13+
<!-- Loaded content... -->
14+
</div>
15+
</template>
16+
17+
<script>
18+
import { loadable, mapLoadableActions } from 'vue-loadable';
19+
20+
export default {
21+
...,
22+
23+
methods: {
24+
async initialize () {
25+
// Set initialize state as loading on async function start.
26+
this.$setLoading('initialize');
27+
28+
try {
29+
await this.$store.dispatch('users/fetchUsers');
30+
} catch (_) {}
31+
32+
// Unset initialize state as loading on async function end.
33+
this.$unsetLoading('initialize');
34+
},
35+
36+
// `loadable` decorator can automate this process.
37+
initialize: loadable(async function () {
38+
await this.$store.dispatch('users/fetchUsers');
39+
}, 'initialize'),
40+
41+
// An there's `mapLoadableActions` to map Vuex actions into loadable methods.
42+
...mapLoadableActions('users', {
43+
initialize: 'fetchUsers'
44+
})
45+
},
46+
mounted () {
47+
this.initialize();
48+
}
49+
};
50+
```
51+
752
## Installation
853
954
This library is published in the NPM registry and can be installed using any compatible package manager.
@@ -56,44 +101,11 @@ export default {
56101
</script>
57102
```
58103
59-
## Usage
60-
61-
`vue-loadable` can improve your loading state control by providing pretty simple methods and helpers to automate its usage.
62-
63-
```vue
64-
<template>
65-
<p v-if="$isLoading('initialize')">Initializing...</p>
66-
<div v-else>
67-
<user-list :users="users" />
68-
</div>
69-
</template>
70-
71-
<script>
72-
import { loadable } from 'vue-loadable';
73-
74-
// ...
75-
76-
export default {
77-
data () {
78-
return {
79-
users: []
80-
};
81-
},
82-
methods: {
83-
fetch: loadable(async function () {
84-
const response = await fetch(baseURL + '/users');
85-
this.users = await response.json();
86-
}, 'initialize')
87-
},
88-
mounted () {
89-
this.initialize();
90-
}
91-
};
92-
```
93-
94104
## API
95105
96-
- **`loadable`** decorates a function to change loading state during its execution. It set state as loading when function init and unset on throws an error, on resolve or return a value.
106+
- **`loadable`** decorates a function to change loading state during its execution. It sets the state as loading when function inits and unsets when it throws an error, when it resolves or when it returns a value.
107+
108+
> Second argument is the loading state name, is `"unknown"` when it's not defined.
97109
98110
```js
99111
Vue.component('SignInForm', {
@@ -120,7 +132,7 @@ export default {
120132
});
121133
```
122134
123-
> It pass down the function arguments, reject the errors and resolve returned value.
135+
> It passes down the function arguments, rejects the errors and resolves the returned value.
124136
> ```ts
125137
> async function confirmUsername(username: string): Promise<boolean> {
126138
> // ...
@@ -206,6 +218,8 @@ export default {
206218
207219
- **`$isLoading`** is a method to check if a state is loading.
208220
221+
> Argument is the loading state name, is `"unknown"` when it's not defined.
222+
209223
```vue
210224
<template>
211225
<v-spinner v-if="$isLoading('initialize')" />
@@ -286,6 +300,8 @@ export default {
286300
287301
- **`$setLoading`** is a method to set state as loading.
288302
303+
> Argument is the loading state name, is `"unknown"` when it's not defined.
304+
289305
```js
290306
export default {
291307
methods: {
@@ -313,6 +329,8 @@ export default {
313329
314330
- **`$unsetLoading`** is a method to unset state as loading.
315331
332+
> Argument is the loading state name, is `"unknown"` when it's not defined.
333+
316334
```js
317335
export default {
318336
methods: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-loadable",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Adds loading state when running load method / param.",
55
"cdn": "dist/vue-loadable.umd.js",
66
"types": "types/vue-loadable.d.ts",

0 commit comments

Comments
 (0)