Dart DocumentationpuremvcObserver

Observer Class

A base IObserver implementation.

In PureMVC, IObserver implementors assume these responsibilities:

  • Encapsulate the notification (callback) method of the interested object.
  • Encapsulate the notification context (this) of the interested object.
  • Provide methods for setting the interested object's notification method and context.
  • Provide a method for notifying the interested object.

The Observer Pattern as implemented within PureMVC exists to support publish/subscribe communication between actors.

An IObserver is an object that encapsulates information about an interested object with a notification (callback) method that should be called when an INotification is broadcast. The IObserver then acts as a conduit for notifying the interested object.

IObservers can receive Notifications by having their notifyObserver method invoked, passing in an object implementing the INotification interface.

See IView, INotification

Implements

IObserver

Constructors

Code new Observer(Function notifyMethod, [Object notifyContext]) #

Constructor.

The notifyMethod method on the interested object should take one parameter of type INotification

Param notifyMethod the callback method Param notifyContext the caller object

Observer( Function this.notifyMethod, [Object this.notifyContext] ){}

Methods

Code bool compareNotifyContext(Object object) #

Compare a given object to the notifyContext object.

  • Param Object - the object to compare.
  • Returns bool - whether the given object and the notifyContext are the same.
bool compareNotifyContext( Object object )
{
     return object === notifyContext;
}

Code Object getNotifyContext() #

Get the notification context.

  • Returns Object - the caller.
Object getNotifyContext()
{
    return notifyContext;
}

Code Function getNotifyMethod() #

Get the notification method.

  • Returns Function - the notification (callback) method of the interested object.
Function getNotifyMethod()
{
  return notifyMethod;
}

Code void notifyObserver(INotification notification) #

Notify the interested object.

void notifyObserver( INotification notification )
{
  if ( notifyContext != null ) getNotifyMethod()( notification );  
}

Code void setNotifyContext(Object caller) #

Set the notification context.

  • Param caller - a reference to the object to be notified.
void setNotifyContext( Object caller )
{
  notifyContext = caller;
}

Code void setNotifyMethod(Function callback) #

Set the notification method.

The notification method should take one parameter of type INotification.

  • Param notifyMethod - the notification (callback) method of the interested object.
void setNotifyMethod( Function callback )
{
  notifyMethod = callback;
}

Fields

Code Object notifyContext #

This IObserver's notifyContext (i.e., caller)

Object notifyContext;

Code Function notifyMethod #

This IObserver's notifyMethod (i.e., callback)

Function notifyMethod;