rename vuex actions as per best practices

This commit is contained in:
Dennis Tang 2018-05-14 14:38:55 +02:00
parent 3acc649d30
commit 2b903eceda
5 changed files with 27 additions and 27 deletions

View File

@ -47,7 +47,7 @@ export default {
selectedZone() {
this.isLoading = true;
this.getMachineTypes()
this.fetchMachineTypes()
.then(this.fetchSuccessHandler)
.catch(this.fetchFailureHandler);
},
@ -56,7 +56,7 @@ export default {
},
},
methods: {
...mapActions(['getMachineTypes']),
...mapActions(['fetchMachineTypes']),
...mapActions({ setItem: 'setMachineType' }),
enableSubmit() {
if (this.allDropdownsSelected) {

View File

@ -76,12 +76,12 @@ export default {
created() {
this.isLoading = true;
this.getProjects()
this.fetchProjects()
.then(this.fetchSuccessHandler)
.catch(this.fetchFailureHandler);
},
methods: {
...mapActions(['getProjects']),
...mapActions(['fetchProjects']),
...mapActions({ setItem: 'setProject' }),
fetchSuccessHandler() {
if (this.defaultValue) {

View File

@ -38,13 +38,13 @@ export default {
selectedProject() {
this.isLoading = true;
this.getZones()
this.fetchZones()
.then(this.fetchSuccessHandler)
.catch(this.fetchFailureHandler);
},
},
methods: {
...mapActions(['getZones']),
...mapActions(['fetchZones']),
...mapActions({ setItem: 'setZone' }),
},
};

View File

@ -1,18 +1,6 @@
/* global gapi */
import * as types from './mutation_types';
export const setProject = ({ commit }, selectedProject) => {
commit(types.SET_PROJECT, selectedProject);
};
export const setZone = ({ commit }, selectedZone) => {
commit(types.SET_ZONE, selectedZone);
};
export const setMachineType = ({ commit }, selectedMachineType) => {
commit(types.SET_MACHINE_TYPE, selectedMachineType);
};
const gapiRequest = ({ service, params, commit, mutation, payloadKey }) =>
new Promise((resolve, reject) => {
const request = service.list(params);
@ -31,7 +19,19 @@ const gapiRequest = ({ service, params, commit, mutation, payloadKey }) =>
);
});
export const getProjects = ({ commit }) =>
export const setProject = ({ commit }, selectedProject) => {
commit(types.SET_PROJECT, selectedProject);
};
export const setZone = ({ commit }, selectedZone) => {
commit(types.SET_ZONE, selectedZone);
};
export const setMachineType = ({ commit }, selectedMachineType) => {
commit(types.SET_MACHINE_TYPE, selectedMachineType);
};
export const fetchProjects = ({ commit }) =>
gapiRequest({
service: gapi.client.cloudresourcemanager.projects,
params: {},
@ -40,7 +40,7 @@ export const getProjects = ({ commit }) =>
payloadKey: 'projects',
});
export const getZones = ({ commit, state }) =>
export const fetchZones = ({ commit, state }) =>
gapiRequest({
service: gapi.client.compute.zones,
params: {
@ -51,7 +51,7 @@ export const getZones = ({ commit, state }) =>
payloadKey: 'items',
});
export const getMachineTypes = ({ commit, state }) =>
export const fetchMachineTypes = ({ commit, state }) =>
gapiRequest({
service: gapi.client.compute.machineTypes,
params: {

View File

@ -51,10 +51,10 @@ describe('GCP Cluster Dropdown Store Actions', () => {
describe('async fetch methods', () => {
window.gapi = gapi();
describe('getProjects', () => {
describe('fetchProjects', () => {
it('fetches projects from Google API', done => {
store
.dispatch('getProjects')
.dispatch('fetchProjects')
.then(() => {
expect(store.state.projects[0].projectId).toEqual(selectedProjectMock.projectId);
expect(store.state.projects[0].name).toEqual(selectedProjectMock.name);
@ -65,10 +65,10 @@ describe('GCP Cluster Dropdown Store Actions', () => {
});
});
describe('getZones', () => {
describe('fetchZones', () => {
it('fetches zones from Google API', done => {
store
.dispatch('getZones')
.dispatch('fetchZones')
.then(() => {
expect(store.state.zones[0].name).toEqual(selectedZoneMock);
@ -78,10 +78,10 @@ describe('GCP Cluster Dropdown Store Actions', () => {
});
});
describe('getMachineTypes', () => {
describe('fetchMachineTypes', () => {
it('fetches machine types from Google API', done => {
store
.dispatch('getMachineTypes')
.dispatch('fetchMachineTypes')
.then(() => {
expect(store.state.machineTypes[0].name).toEqual(selectedMachineTypeMock);