I have a case where I am creating multiple views for a single model. When I close a view, I am removing the model from the collection.
But in case of multiple views, there are other views that depend on the model.
So, how can I know when there are no views depending on the model? When should I destroy the model in case of multiple views?
Though this is not a proper way but still you can achieve this following
Declare
dependentViewsin your model'sdefaultsIn initialization of each view, increment the
dependentViewOn close of view decrement
dependentViewsand on each view destroy, just check the value ofdependentViews. If it is 0, remove the model from the collection.