-
Notifications
You must be signed in to change notification settings - Fork 5
Organizing Tasks and Lists #14
Description
Problem
When a task is created on the client, two messages are sent to the server: list.update and task.create.
list.update({
"id": "inbox",
"tasks": [
"c0"
]
},{
"tasks": 1390074290378
})
task.create({
"id": "c0",
"listId": "inbox",
"date": 0,
"name": "This is a new task",
"notes": "",
"priority": 1,
"completed": 0
}, 1390074290379).fn(2)The server then stores the following.
{
"data_task": {
"s1": {
"id": "s1",
"listId": "inbox",
"date": 0,
"name": "This is a new task",
"notes": "",
"priority": 1,
"completed": 0
}
},
"data_list": {
"inbox": {
"name": "Inbox",
"tasks": [
"c0",
"s1"
],
"id": "inbox"
}
}
}See the problem? The inbox list has two tasks assigned to it: "c0" and "s1". But "c0" doesn't even exist!
Possible Solution 1
Whenever a list is created or updated, we loop through the tasks array and throw array any IDs that don't exist on the server.
- The client sends the
list.updatemessage. - Server inspects the
tasksproperty and deletes"c0"property. - The client sends the
task.createmessage. - Server adds task ID to the
tasksarray.
Possible Solution 2
- The client sends the
task.createmessage first, and then waits for the server to return the server ID. - The server will automatically add the task into the list.
- The client will then add the task into the list, and send the
list.updateevent. - The server will then magically merge the
tasksproperty.
Keeping Order
One of the features on the client is that you can sort tasks in order you want. We need to be able to keep this order on the server.
All The Solutions
So I think the best thing to do is just let the server manage the tasks array for each list.
Creating a task
The task.create event requires you send id and listId. The server can then check that listId exists, and will add the task id to it.
Moving a task between lists
Use task.update and set the listId to the new list id. The server can remove the task id from the old list and add it to the new one.
Destroying a task
Use task.destroy. The server can remove the task id from the list it was in.
Reordering a task
Send list.update with the tasks array.
The server willl throw array any tasks that don't exist on the server and add the tasks that aren't included. Then it will merge the order with the existing tasks array.