Esempio n. 1
0
        public static ExpendoObject AddItem(string label)
        {
            ExpendoObject action = new ExpendoObject();

            action["type"]  = TodoActionTypes.ADD;
            action["label"] = label;

            return(action);
        }
Esempio n. 2
0
        public static ExpendoObject ToggleItem(Guid todoId)
        {
            ExpendoObject action = new ExpendoObject();

            action["type"] = TodoActionTypes.TOGGLE;
            action["id"]   = todoId;

            return(action);
        }
Esempio n. 3
0
        public static ExpendoObject RemoveItem(Guid todoId)
        {
            ExpendoObject action = new ExpendoObject();

            action["type"] = TodoActionTypes.REMOVE;
            action["id"]   = todoId;

            return(action);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }