I believe I have a good understanding of Marionette and Backbone, but the following issue has me stumped. I'm trying to display a message board using marionette item views within a collection view, and I have a way that works, but I'm unhappy with the outcome as it ends up with me calling reset on a new collection after processing my initial array of messages.
Let's say I have an array, or backbone Collection, of messages from a web server. e.g.
[{ user : "Alice", timestamp : 1, body : "message1" },
{ user : "Alice", timestamp : 5, body : "message2" },
{ user : "Bob", timestamp : 10, body : "message3" },
{ user : "Alice", timestamp : 20, body : "message4" }] etc.
I would like to display the messages in batches of user messages, so I would see:
Alice
- message1
- message2
Bob
- message3
Alice
- message4
How can I best achieve this using Marionette? I currently perform a single pass of all messages, building a new array that looks like the following:
[{ user : "Alice", messages : ["message1", "message2"] },
{ user : "Bob", messages : ["message3"] },
{ user : "Alice", messages : ["message4"] }]
I then make a new Collection, and call reset with the above array. This 'reset' takes a long time (27 seconds!!) for a large (~250) number of messages. Each batch of user messages is a new ItemView and I use handlebars in my template to iterate over the messages array for that batch.
I also want this to cope with another message being appended to the end of the initial array, and have the CollectionView update automatically. Thanks in advance!