3

So here is the skinny...(I always talk like a 30s gangster)

I have two Models - ya seee: Company + Date

Setup
The Company model is attached to a drop down list view. It fetches the list of companies from the server. Date is set to today and is attached to a date selector View. On initialization, these models are both attached to their respective views through the app router. These make up the main navigation and are always there.

Problem
The problem is that these models + data will be used by multiple views and I would like to have a cleaner way to pass them to these views. So I used an event aggregator that publishes the event along with the model when they change. However, this does not help on initialization of the new views as the models haven't changed.

Four Options

  1. Store the date model in localStorage. Retrieve it when the model is initialized by a new view. Pull the company data from cache when the model is initialized by a new view.

  2. Pass either model from my app router to each new view. Bind model changes to the view.

  3. Prefer: Use my eventing system but find a work around for new view initialization.

  4. Throw my hands up and say "sc*** it" and scream at the lady across the hall for an hour

imrane
  • 1,542
  • 2
  • 16
  • 29
  • Who is initializing your views, and how? Sounds as if your option 2 is the commonly preferred variant... – Julian D. Feb 29 '12 at 17:56
  • The app router is initializing the views. With navview = new NavView({model: company}) – imrane Feb 29 '12 at 18:30
  • Sounds perfectly fine (and clean) to me. Why do you wan't do change it? – Julian D. Feb 29 '12 at 18:49
  • Maybe I am over thinking it. I thought it would be easier to use an eventing system to pass around models..I'll head down the route of using option 2 and see if things change...thanks for the help. – imrane Feb 29 '12 at 18:59

1 Answers1

2

Stick with #2 - Passing your model into each view when it is instantiated. This is classic MVC architecture and will do you just fine to adhere to this convention. Typical MVC has each view listening to events from a model stored as a reference so that the view can update itself when the model changes. Typically the model object is passed in the view constructor.

Britt M
  • 36
  • 1