Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8704141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:01:30+00:00 2026-06-13T03:01:30+00:00

I have two Apps: A SrvLinkApp that has a Link Model (a sockjs connection

  • 0

I have two Apps:

A SrvLinkApp that has a Link Model (a sockjs connection to the server).
A ChatApp that has a chatView view, a ChatEntry Model, and a ChatCollection.

When I receive a msg form the server I trigger a ‘chat:server:message’, payload event with:

App.vent.trigger('chat:server:message', payload)

In my ChatApp I listen for this event, transform the payload into a ChatEntry and then add it to the ChatCollection witch is referenced by the ChatView.

Where should I add the binding? I only have the reference to the collection in the initialize part:

App.vent.bind("chat:server:msg", function(msg) {})

Plan A

Foo.module("ChatApp", function(ChatApp, App, Backbone, Marionette, $, _) {

App.addRegions({
    chatRegion: "#chat-region",
});


MsgEntry = Backbone.Model.extend({});


MsgCollection = Backbone.Collection.extend({
    model: MsgEntry
})


MsgView = Backbone.Marionette.ItemView.extend({
    template: '#chat-entry-template',
});

MsgListView = Backbone.Marionette.CompositeView.extend({

    itemView: MsgView,

    itemViewContainer: "#chat-messages",

    template: "#chat",

     ....
});


ChatApp.addInitializer(function() {

   var msgCollection = new MsgCollection();
   var msgListView = new MsgListView({collection: msgCollection});

   // render and display the view
   App.chatRegion.show(msgListView);


   // App Events listeners
   // --------------------

   // New chat message from server 
    App.vent.bind("chat:server:msg", function(msg) {
        // create an entry and add it to our collection
        console.log(msgCollection);
    });


});
});

or Plan B

Foo.module("ChatApp", function(ChatApp, App, Backbone, Marionette, $, _) {

App.addRegions({
    chatRegion: "#chat-region",
});


// App Events listeners
// --------------------

// New chat message from server 
App.vent.bind("chat:server:msg", function(msg) {
   // create an entry and add it to our collection
   console.log(ChatApp.msgCollection);
});


MsgEntry = Backbone.Model.extend({});


MsgCollection = Backbone.Collection.extend({
    model: MsgEntry
})


MsgView = Backbone.Marionette.ItemView.extend({
    template: '#chat-entry-template',
});

MsgListView = Backbone.Marionette.CompositeView.extend({

    itemView: MsgView,

    itemViewContainer: "#chat-messages",

    template: "#chat",

     ....
});


ChatApp.addInitializer(function() {

   var msgCollection = new MsgCollection();
   var msgListView = new MsgListView({collection: msgCollection});

   // HERE //
   ChatApp.msgCollection = msgCollection;
   // END HERE //

   App.chatRegion.show(msgListView);
});
});

Or is there other ways to access the collection ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:01:32+00:00Added an answer on June 13, 2026 at 3:01 am

    I don’t think either of these is bad. I use both ideas at various times. It largely depends on other circumstances within your app, what the possibilities of are of having multiple collections to deal with, etc.

    Personally, I’d go with A because it keeps everything within the module, and doesn’t leave the collection open to getting clobbered or forgotten about (memory leak) on the global app object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two apps that both access the same database. The first has clients
I have two apps that use custom URL schemes to switch between each other.
Say I have two Java apps that I wrote: Ping.jar and Pong.jar and they
I have two Express.js apps running on my server. A plain vanilla app called
I have two apps (one for the iPhone, the other for the iPad) that
So this isnt specific to a code sample, but we have two apps, that
I have two free apps, iSys and iSysMonitor, that report info about my iPhone.
I have two apps, account and myapp. I'm trying to display in a view
I have two apps that are in the app store with which a couple
I have two apps (free & paid) that are exactly same except for ad

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.