Skip to content

Commit 7b17fc5

Browse files
author
Walker Leite
committed
feat(async): add async module
1 parent 3413b45 commit 7b17fc5

File tree

6 files changed

+55
-1
lines changed

6 files changed

+55
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ A Vue project template with [Loopback](http://loopback.io/) framework featuring
2020
3. `server`: Loopback server files
2121
4. `test`: Unit test
2222

23+
## Features
24+
25+
* Loopback service using [axios](https://github.com/axios/axios) at `client/services/loopback`;
26+
* Full authentication support, by default the account listed in `server/initial-data/maintenance-account.json` is created;
27+
* Ajax Async queue module in `client/modules/async` (useful to see if and how many requests are being made to the server);
28+
* [CSS Modules](https://github.com/css-modules/css-modules), [Sass](https://sass-lang.com/) and [Bootstrap Vue](https://bootstrap-vue.js.org).
29+
2330
## Linting
2431

2532
```

template/client/App.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export default {
1313
hello: 'Hello World!',
1414
}),
1515
{{/unless}}
16+
created() {
17+
// Boot Application
18+
this.$store.dispatch('async/syncLoopback');
19+
}
1620
}
1721
</script>
1822

template/client/services/loopback.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function addTokenFromLocalStorage(http) {
2828

2929
const http = axios.create({
3030
baseURL: `http://${host}:${port}${restApiRoot}`,
31-
});fi
31+
});
3232

3333
// Current setLoading function
3434
let setLoading = () => {

template/client/store/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Vue from 'vue';
22
import Vuex from 'vuex';
33

4+
import async from './modules/async';
45
import auth from './modules/auth';
56

67
Vue.use(Vuex);
@@ -16,6 +17,7 @@ export default new Vuex.Store({
1617
}],
1718
},
1819
modules: {
20+
async, // async namespaced
1921
auth, // auth namespaced
2022
},
2123
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import getUID from 'uid';
2+
import lb from '@/services/loopback';
3+
4+
export default {
5+
namespaced: true,
6+
state: {
7+
ajaxCommands: [],
8+
},
9+
getters: {
10+
loadingAjax(state) {
11+
if (state.ajaxCommands.length > 0) return true;
12+
return false;
13+
},
14+
},
15+
actions: {
16+
syncLoopback({commit}) {
17+
lb.setLoadingFunction(
18+
(isLoading, uid = getUID()) => {
19+
if (isLoading) {
20+
commit('addAjaxCommand', uid);
21+
} else {
22+
commit('removeAjaxCommand', uid);
23+
}
24+
return uid;
25+
}
26+
);
27+
},
28+
},
29+
mutations: {
30+
addAjaxCommand(state, uid) {
31+
state.ajaxCommands.push(uid);
32+
},
33+
removeAjaxCommand(state, uid) {
34+
state.ajaxCommands.splice(
35+
state.ajaxCommands.indexOf(uid),
36+
1
37+
);
38+
},
39+
},
40+
};

template/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"install": "^0.10.1",
3838
"lodash.defaultsdeep": "^4.6.0",
3939
"loopback-ds-timestamp-mixin": "^3.4.1",
40+
"uid": "0.0.2",
4041
"vue-awesome": "^2.3.4",
4142
"vue-router": "^3.0.1",
4243
"vue-template-compiler": "^2.5.3",

0 commit comments

Comments
 (0)