public static ExpendoObject AddItem(string label) { ExpendoObject action = new ExpendoObject(); action["type"] = TodoActionTypes.ADD; action["label"] = label; return(action); }
public static ExpendoObject ToggleItem(Guid todoId) { ExpendoObject action = new ExpendoObject(); action["type"] = TodoActionTypes.TOGGLE; action["id"] = todoId; return(action); }
public static ExpendoObject RemoveItem(Guid todoId) { ExpendoObject action = new ExpendoObject(); action["type"] = TodoActionTypes.REMOVE; action["id"] = todoId; return(action); }
public void OnStateChange(ExpendoObject state) { List <Task> list = state.Get <TodoState>("todo").Tasks; foreach (Transform c in m_grid) { if (list.FindIndex(o => o.Id.ToString() == c.name) == -1) { Destroy(c.gameObject); } } list.ForEach(ProcessTask); }
public override TodoState Reduce(TodoState state, ExpendoObject action) { string type = action.Get <string>("type"); switch (type) { case TodoActionTypes.TOGGLE: Guid id = action.Get <Guid>("id"); Task t = state.Tasks.First(o => o.Id == id); t.done = !t.done; break; case TodoActionTypes.ADD: Task task = new Task(action.Get <string>("label")); state.Tasks.Add(task); break; case TodoActionTypes.REMOVE: state.Tasks = state.Tasks.Where(o => o.Id != action.Get <Guid>("id")).ToList <Task>(); break; } return(state); }