Destroy the right instance of view

Meg T's Avatar

Meg T

11 Nov, 2011 08:48 PM

Hi I have a parent view which has an object of type customreport and a drop down which drives the report. customreport is mapped to ReportMediator. When user changes the drop down, According to the requirements, I cannot put the autoremove to true. It has to be set to false so that the user can come back to the old screen and use the report (which gets removed coz of change in state)

I have to destroy customreport 1 and replace it by customreport 2. On the change event of the drop down I do the following in the parentMediator:

myContext:
mediatorMap.mapView(parentView, ParentMediator,null, true, false);
mediatorMap.mapView(CustomReport, ReportMediator, null, true, false);

ParentMediator:
mediatorMap.removeMediatorByView(parentView.customReportObject);
parentView.removeElement(customReportObject);
parentView.customReportObject= null;
customReportObject= new CustomReport(cmbBox.selectedItem.data);

Reportmediator:
override protected onRemove():void
{ //remove event listeners on the cutomreport object, unmap listeners etc. customReport.destroy(); //clean up}

Do you think by the time the clean up in happening on the mediator, the new object will be assigned to customreportObj in the parentview and cleanup will happen on the new report instead. you see what I am saying - a timing issue.

Please let me know if you think i could follow a different approach as i want to make sure that the report is destroyed and the mediators are unmapped everytime the dropdown is changed. this drop down is changes several times by the user and this way mediators are piling up in the memory.

Thanks,
Meg

  1. Support Staff 1 Posted by creynders on 13 Nov, 2011 08:09 AM

    creynders's Avatar

    I'm not 100% sure I understood the question/situation, but anyway:
    Mediators are automatically instantiated and removed when the view they're coupled to is added to the stage and removed.
    The moment you call parentView.removeElement( customReportObject ) (it removes the custom report from the stage, right?) the destruction sequence of the view and its mediator is set in motion. There's no need to manually call removeMediatorByView since it will all be done automatically.
    And to answer your question: mediator instances are coupled 1-on-1 to view instances, so even if the same view is added to the stage again it will be coupled to its own mediator instance and there's no chance that the cleanup of the previous view/mediator couple will interfere with the creation/initialisation of the new view/mediator couple even if they overlap in time.

  2. Ondina D.F. closed this discussion on 23 Dec, 2011 08:57 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac