Icontem

File: app/components/test-todomvc/store/mutations.js

Recommend this page to a friend!
  Classes of Sergey Beskorovayniy  >  Vuex Examples  >  app/components/test-todomvc/store/mutations.js  >  Download  
File: app/components/test-todomvc/store/mutations.js
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Vuex Examples
Example apps using Vuex state management pattern
Author: By
Last change:
Date: 2 years ago
Size: 1,249 bytes
 

Contents

Class file image Download
define([], function () {
    
    var todos = [];
    //----------------------
    var STORAGE_KEY = 'todos-vuejs';
    var oTodos = JSON.parse(window.localStorage.getItem(STORAGE_KEY));
    if(oTodos){
        todos = oTodos.todos;
    }
    var state = {
        todos: todos
    };

    var mutations = {
        addTodo: function (state, text) {
            state.todos.push({
                text: text,
                done: false
            });
        },
        deleteTodo: function (state, todo) {
            var indexOf = state.todos.indexOf(todo);
            state.todos.splice(indexOf, 1);
        },
        toggleTodo: function (state, todo) {
            todo.done = !todo.done;
        },
        editTodo: function (state, values) {
            values.todo.text = values.value;
        },
        toggleAll: function (state, done) {
            state.todos.forEach(function (todo) {
                todo.done = done;
            });
        },
        clearCompleted: function (state) {
            state.todos = state.todos.filter(function (todo) {
                return !todo.done;
            });
        }
    };
    return {
        storage_key: STORAGE_KEY,
        state: state,
        mutations: mutations
    };
});