1

So I'm creating a project where people can work together on a task list. My current method of synchronization is pretty bad so I've been wanting to move to GoInstant for a while. As I was looking around I found out about GoAngular, which seems to provide a really sweet, intuitive way to bind together the data and display. However I do not know if GoAngular will be up to the task of handling multiple people adding deleting and reordering items at the same time.

Do you know of a way to make GoAngular support reordering? It is important that updates be incremental and not recreate the DOM of the whole list every time.

lemiant
  • 4,205
  • 4
  • 31
  • 38

1 Answers1

1

It really depends on the size of your list, you can take two approaches (neither is perfect), both involves adding a position property to your GoAngular model (or creating a model specifically to track positions):

Let's make this our starting point:

[
 { title: 'Item A', position: 1 },
 { title: 'Item B', position: 2 },
 { title: 'Item C', position: 3 },
 { title: 'Item D', position: 4 },
]

If the list is small (in the hundreds of items), you can update positions as they change, so if 'Item B' was moved after 'Item C', you would update the position (using $set) for items B & C:

[
 { title: 'Item A', position: 1 },
 { title: 'Item C', position: 2 },
 { title: 'Item B', position: 3 },
 { title: 'Item D', position: 4 },
]

Alternatively you could insert an item in the middle of two positions, this is more practical in large lists. If 'Item B' was again moved after 'Item C', you would update the position of only 'Item B'. In this example it would be (3+4) / 2 = 3.5:

[
 { title: 'Item A', position: 1 },
 { title: 'Item C', position: 3 },
 { title: 'Item B', position: 3.5 },
 { title: 'Item D', position: 4 },
]

Does that help?

Slukehart
  • 1,037
  • 5
  • 15
  • 1
    This is really clever. I'd never have thought of doing it the second way – lemiant Apr 02 '14 at 14:05
  • 1
    It should do the trick, it's not operational transformations, but it's a start :) – Slukehart Apr 02 '14 at 17:27
  • So I ran into a problem with this. If Person 1 moves A between B and C then it is given position 2.5. If at the same time Person 2 moves D between B and C it is also given position 2.5. Once the lists are synced up if someone places an item between A and D the algorithm has no way to represent that. – lemiant Apr 04 '14 at 13:38
  • 1
    I have figured out a solution, but its not very elegant. Since you seem to be pretty good at this I figured I'd ask if you knew a better way. – lemiant Apr 04 '14 at 13:38
  • If the position is really important you could use a separate key to lock down a particular list (using [overwrite: false](https://developers.goinstant.com/v1/javascript_api/key/set.html)). So basically.. User A, says... wish to edit list with ID x. If it fails, he gets the new state of the list, and repeats. Once user X has a lock (successfully sets the value of our lock key) we update the position. – Slukehart Apr 30 '14 at 19:09