Reputation: 1542
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
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.
Pass either model from my app router to each new view. Bind model changes to the view.
Prefer: Use my eventing system but find a work around for new view initialization.
Throw my hands up and say "sc*** it" and scream at the lady across the hall for an hour
Upvotes: 3
Views: 366
Reputation: 36
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.
Upvotes: 2