1

Imagine I need to create a Single page application like Gmail, using BackboneJS. Whenever a mail item is tagged with new labels/ removed the existing labels, the mail item should appear in the appropriate list.

I assume every list of e-mails, like Inbox, Sent Items, some custom labels, can be designed as a Collection. Whenever a mail item is archived or tagged with additional labels or removed existing labels, the mail item shall be removed from one list and added appropriately to some other list.

Is this a right design approach?

Kumaran
  • 41
  • 4

2 Answers2

0

So you want to put the e-mail model in lots of different collections (like inbox and sent). This is possible. But i would advice to give the e-mail model this data. Tell the e-mail model it has this and this label.

You will have a collection of e-mails; in this collection you can create functions to easily extract inbox and sent models.

Laurens Kling
  • 2,221
  • 1
  • 21
  • 31
0

You are right. This is perfect design approach. This makes easy for you to manage events as follows :

var Inpox = Backbone.Collection.extend({
    model: Email,
    ....
});


var SentItem = Backbone.Collection.extend({
    model: Email,
    ....
});

emailApp.on("sent",function(){// When sent triggered from Email

//Do sent email specific task

    backboneEventObject.trigger("add");
});

backboneEventObject.on("add", function(){
    newSentItemCollection.trigger("add");// Trigger add on the sent Item Collection
});
Soumya
  • 310
  • 1
  • 8