import alt from '../alt'
import TaskActions from '../actions/TaskActions'

class TaskStore {
  constructor() {
    this.bindActions(TaskActions)
    this.tasks = []
    this.loading = false
  }

  onFetched(tasks) {
    this.loading = false
    this.tasks = tasks
  }

  onAdded(task) {
    this.tasks.push(task)
  }

  onPlay(playTask) {
    this.tasks = this.tasks.map((task) => {
      if (task.id === playTask.id) {
        task.status = 'doing'
      }
      return task
    })
  }

  onDone(doneTask) {
    this.tasks = this.tasks.map((task) => {
      if (task.id === doneTask.id) {
        task.status = 'done'
      }
      return task
    })
  }

  onDelete(taskToDestroy) {
    this.tasks = this.tasks.filter((task) => {
      return task !== taskToDestroy
    })
  }
}

export default alt.createStore(TaskStore, 'TaskStore')

@@ -408,32 +408,24 @@
 ayTask.id) %7B
-%0A       
  task.status
@@ -434,22 +434,16 @@
  'doing'
-%0A     
  %7D%0A     
@@ -572,16 +572,8 @@
 d) %7B
-%0A       
  tas
@@ -589,22 +589,16 @@
 = 'done'
-%0A     
  %7D%0A     

Remove \n