Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Cancel notification like events?  (Read 7501 times)
Sammi
Courseware Beta
Full Member
***
Posts: 45


View Profile Email
« 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

Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 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>
Logged
Sammi
Courseware Beta
Full Member
***
Posts: 45


View Profile Email
« Reply #2 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
Logged
Pages: [1]
Print