egoist / zerotwo

😈 Refined state containter for Vue.js
75 stars 6 forks source link

Possibly get parent store in a store? #3

Closed egoist closed 6 years ago

egoist commented 6 years ago
const Todo = zerotwo({
    state: {
        text: null,
        completed: false,
        id: null
    },
    actions: self => ({
        complete: () => self.completed = !self.completed,
        remove: () => self.getParent().removeTodo(self)
    })
})

const Todos = zerotwo({
    state: {
        todos: []
    },
    actions: self => ({
        addTodo: text => self.todos.push(Todo({ text, id: Date.now() })),
        removeTodo: todo => 
            self.todos = self.todos.filter(t => t.id !== todo.id)
    })
})