Last active
October 9, 2018 23:37
-
-
Save superMDguy/2d8bcd3fb88d9947685f1af8d02762d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tuxi from 'tuxi' | |
import Vuex from 'vuex' | |
import Vue from 'vue' | |
import api from './api' | |
Vue.use(Vuex) | |
const store = new Vuex.Store({ | |
strict: true, // tuxi works in strict mode! | |
state: { | |
articles: [], | |
articlesTask: tuxi.task(api.fetchArticles) | |
}, | |
mutations: { | |
SET_ARTICLES(state, articles) { | |
state.articles = articles | |
} | |
}, | |
actions: { | |
async articles({ commit, state }) { | |
const articles = await state.articlesTask.start() | |
commit('SET_ARTICLES', articles) | |
} | |
} | |
}) | |
tuxi.config.vuexStore = store | |
// Now you can access $store.state.articlesTask in your components to look at the task's state |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment