-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtodosreducer.cpp
More file actions
33 lines (23 loc) · 847 Bytes
/
Copy pathtodosreducer.cpp
File metadata and controls
33 lines (23 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "todosreducer.h"
#include <QDebug>
TodosReducer::TodosReducer()
{
this->addProp("todos", QList<QVariant>());
}
void TodosReducer::handleAction(Action action)
{
qDebug() << "TODOS action received: " << action.type;
if(action.type == "ADD_TODO") {
qDebug() << "Adding todo";
QList<QVariant> list = this->getProp("todos").toList();
list.append(action.payload);
data["todos"] = list;
} else if(action.type == "UPDATE_TODO") {
qDebug() << "Updating todo";
QList<QVariant> list = this->getProp("todos").toList();
QMap<QString, QVariant> params = action.payload.toMap();
if(params["index"].toInt() >= 0 && params["index"].toInt() < list.count())
list[params["index"].toInt()] = params["todo"].toString();
data["todos"] = list;
}
}