Skip to content
This repository has been archived by the owner on Jan 22, 2021. It is now read-only.

Organizing Tasks and Lists #14

Open
stayradiated opened this issue Jan 18, 2014 · 0 comments
Open

Organizing Tasks and Lists #14

stayradiated opened this issue Jan 18, 2014 · 0 comments
Assignees

Comments

@stayradiated
Copy link
Member

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.

  1. The client sends the list.update message.
  2. Server inspects the tasks property and deletes "c0" property.
  3. The client sends the task.create message.
  4. Server adds task ID to the tasks array.

Possible Solution 2

  1. The client sends the task.create message first, and then waits for the server to return the server ID.
  2. The server will automatically add the task into the list.
  3. The client will then add the task into the list, and send the list.update event.
  4. The server will then magically merge the tasks property.

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.

@ghost ghost assigned stayradiated Jan 18, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant