PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: Sammi on October 06, 2008, 06:09:42



Title: Cancel notification like events?
Post by: Sammi on October 06, 2008, 06:09:42
Hi,

this may sound strange but I think I would like to be able to "cancel" a notification.  I have a command that is triggered on notification.  This command does stuff and one of the things it does is to evaluate if there is any need to anything at all.  If nothing needs to be done I would like to prevent any interested mediator from getting the notification.

These mediators only have to act on the notification if something changed.

Sounds silly??  Maybe I should simply not send the initial notification if the command will not have to anything.  But I want the command to decide if actions are needed.

Best,
Sammi



Title: Re: Cancel notification like events?
Post by: puremvc on October 06, 2008, 06:44:15
Ok here's the poor man's note cancel:

If the command happens to be registered in the facade's initializeController method then you can be sure its the first observer to be notified.

This means the command gets a chance to modify the notification before the others get it, which means you could do something like use the type property of the note to indicate the result of the command's evaluation, and have the mediators act (or not) depending. Or you could create a custom note class with a cancel prop.

But that smells because the subsequent notifications happen, eating up cycles, and you have to have logic in the mediators to keep them from acting on a 'cancelled' note.

What you really want to do is have two notifications. The first one triggers the command and if the command wants further processing to happen, it sends the second note.

For instance, a note called USER_GESTURE is sent and the command looks at it and determines if it contains a valid gesture. If so, it sends PROCESS_VALID_GESTURE, whiche the mediators all handle as need be.

-=Cliff>


Title: Re: Cancel notification like events?
Post by: Sammi on October 06, 2008, 06:52:21
You are right - two notifications are the way to go I think.  It is cleaner that way.

Tank you very much,
Sammi