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: Circular notifications  (Read 5861 times)
paulv410
Newbie
*
Posts: 3


View Profile Email
« on: September 25, 2008, 05:06:17 »

We are designing a builder type application where the user adds/removes/configures items on a canvas.  The view that the user creates is backed in the model with a definition which can be saved/retrieved.  There are multiple parts of the view which can update the model and need to be aware of changes to the model.  In addition, the model can be updated from the server side as a side-effect of a view change.

Whenever the model changes (either due to a user interaction or from a server push), the model proxy sends a "change" notification.  The mediators in the view are registered for these notifications so that they can update their view components.

Whenever the view changes, the mediator sends a notification which a command will handle to update the model.

This seems to cause a notification loop.  For instance, the user makes a change in the view which causes the mediator to send a notification of the change.  That is eventually processed by the proxy who sends a notification of the change.  This notification is then processed by the mediator which originated the first notification.

Since there may be multiple mediators in the view who need to know about the model change, the proxy really does need to send the notification whenever there is a change.  Also, the model can be changed from the server side so notifications seem to be essential.

Is there a good way to prevent this kind of notification loop?  Is this normal?  We also seem to have duplicate command types: one which comes from the view and one which comes from the proxy.

Also, typically, you want the view to represent what is in the model.  However, in this builder-type application, the view often knows about changes before the model.  For example, when an object is resized with a drag, the UI component already knows it's new size before a notification can be sent to the model.  It seems odd to wait to do the resize until the notification is received from the model.

Does anyone have any suggestions on how to handle this situation?  Let me know if I need to explain this better.

Thanks,
Paul
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: September 26, 2008, 06:55:39 »

Try adding the name of the Mediator that initiated the change as the type property of the CHANGE Notification. Then make sure this is passed to the Proxy as 'changeAgent' or some such, so it can include it in the type property of the outbound CHANGED Notification.

Then inside interested Mediators, only act on CHANGED if the type property is not equal to the evaluating Mediator's name.

And in the view component, go ahead and resize the object in reaction to the user gesture, then send the event that results in the object's Mediator sending the CHANGE event. Since following the above logic, this Mediator won't be responding to the resulting CHANGED notification coming back from the Proxy, there should be no worries.

-=Cliff>
Logged
Pages: [1]
Print