💕 A Promise Plugin for Vuex, compatible with 1.0.0-rc.2
import createPromise from 'vuex-promise'
export default new Vuex.Store({
strict: __DEV__,
...,
plugins: [createPromise({
debug: __DEV__,
status: {
PENDING: 'PROMISE_PENDING',
SUCCESS: 'PROMISE_SUCCESS',
FAILURE: 'PROMISE_FAILURE'
},
silent: false
})]
})
import { GET_COMMITS } from '../types'
import request from 'plato-request'
export default {
getCommits ({ dispatch }, payload) {
dispatch(GET_COMMITS, request({
url: '{base}/commits?sha=',
params: {
base: 'https://api.github.com/repos/crossjs/plato'
},
query: {
per_page: 3
},
headers: {
'Accept': 'application/vnd.github.v3+json'
}
}))
}
}
import { GET_COMMITS } from '../types'
import { PROMISE_SUCCESS } from '../constants'
const state = {
commits: null
}
const mutations = {
[GET_COMMITS] (state, { payload, meta }) {
if (meta === PROMISE_SUCCESS) {
state.commits = payload
}
}
}
export default {
state,
mutations
}