Event Dispatching From Model Setter With Need For Different Events

dougrdotnet's Avatar

dougrdotnet

25 Jul, 2011 07:38 PM

I have a model that I need to dispatch an updated event from within the setter of an ArrayCollection. Currently, I have a single command that updates on EventA. I need to add a second command that updates the model on EventB. The events both sort the model's variable ArrayCollection in different ways ( e.g. one is a standard sort while the other is a numeric sort). The two mediators which dispatch their events exist at the same time, one is a popup over the parent. What would be the correct event architecture to dispatch these events and be able to respond appropriately to the correct event?
For example, should I pull the updated event out of the model's variable setter and dispatch updated from the associated commands instead? In this case, how can I be assured that the setter actually was updated?

Upon some further thought, I looked at eventMap.unmapListener(). Perhaps the better approach would be to unmap the mediator eventDispatcher listener while the popup is active, and mapListener on it's close event. Would that be a more appropriate approach. Then I could use the same event for both, add the property I need for the numeric sort and respond to both from the model collections setter, where I know it has been set.
Thanks

  1. 2 Posted by Michal Wroblewski on 29 Jul, 2011 02:32 PM

    Michal Wroblewski's Avatar

    I think there should be methods to sort an ArrayCollection IN the model. The route should be like this:
    1. Your mediator dispatches an EventA or EventB on mouse action. 2. A command is called and it calls a method on the model e.g. model.sortDataByA() or sortDataByB() 3. At the end of that sort method there can be an event dispatched e.g. DATA_UPDATE. In case of an ArrayCollection, a view can listen to its changes. 4. If you're using DATA_UPDATE approach it should be listened in mediators and accordingly update its view.

    You can parametrize and merge EventA and EventB and add a sortMethod as a parameter and then have it distinguished in a command or pass sortMethod to model's sort function.

    Thanks,
    Mike

  2. Support Staff 3 Posted by Ondina D.F. on 02 Nov, 2011 05:35 PM

    Ondina D.F.'s Avatar

    Feel free to reopen this discussion in case you have more questions or you need further assistance with this issue. Please open new threads for new issues.
    Thank you for posting
    Ondina

  3. Ondina D.F. closed this discussion on 02 Nov, 2011 05:35 PM.

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