Trait ruex::prelude::Observer

source ·
pub trait Observer<Body>: Debugwhere
    Body: Debug + 'static,{
    // Required methods
    fn context(&self) -> &Rc<dyn NotifyContext>;
    fn set_method(
        &mut self,
        notify_method: Box<dyn Fn(Rc<dyn Notification<Body>>)>
    );
    fn set_context(&mut self, notify_context: Rc<dyn NotifyContext>);
    fn notify(&self, notification: Rc<dyn Notification<Body>>);
    fn compare_context(&self, object: &Rc<dyn NotifyContext>) -> bool;
}
Expand description

The definition for a PureMVC Observer.

In PureMVC, Observer 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’ notification method and context.
  • Provide a method for notifying the interested object.

PureMVC does not rely upon underlying event models such as the one provided with Flash.

The Observer Pattern as implemented within PureMVC exists to support event driven communication between the application and the actors of the MVC triad.

An Observer is an object that encapsulates information about an interested object with a notification method that should be called when an Notification is broadcast. The Observer then acts as a proxy for notifying the interested object.

Observers can receive Notification’s by having their notify method invoked, passing in an object implementing the Notification interface, such as a subclass of Notification.

Required Methods§

source

fn context(&self) -> &Rc<dyn NotifyContext>

Get the notification context.

source

fn set_method(&mut self, notify_method: Box<dyn Fn(Rc<dyn Notification<Body>>)>)

Set the notification method.

The notification method should take one parameter of type Notification

source

fn set_context(&mut self, notify_context: Rc<dyn NotifyContext>)

Set the notification context.

source

fn notify(&self, notification: Rc<dyn Notification<Body>>)

Notify the interested object.

source

fn compare_context(&self, object: &Rc<dyn NotifyContext>) -> bool

Compare the given object to the notificaiton context object.

Implementors§

source§

impl<Body> Observer<Body> for BaseObserver<Body>where Body: Debug + 'static,