1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import Vue from 'vue'
- import Vuex from '../../../src'
- import middlewares from './middlewares'
- Vue.use(Vuex)
- export const STORAGE_KEY = 'todos-vuejs'
- // for testing
- if (navigator.userAgent.indexOf('PhantomJS') > -1) {
- localStorage.clear()
- }
- const state = {
- todos: JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]')
- }
- const mutations = {
- ADD_TODO (state, text) {
- state.todos.push({
- text: text,
- done: false
- })
- },
- DELETE_TODO (state, todo) {
- state.todos.$remove(todo)
- },
- TOGGLE_TODO (state, todo) {
- todo.done = !todo.done
- },
- EDIT_TODO (state, todo, text) {
- todo.text = text
- },
- TOGGLE_ALL (state, done) {
- state.todos.forEach((todo) => {
- todo.done = done
- })
- },
- CLEAR_COMPLETED (state) {
- state.todos = state.todos.filter(todo => !todo.done)
- }
- }
- export default new Vuex.Store({
- state,
- mutations,
- middlewares
- })
|