puremvc.patterns.observer package
Submodules
puremvc.patterns.observer.Notification module
- class puremvc.patterns.observer.Notification.Notification(name: str, body: Optional[Any] = None, _type: Optional[str] = None)
Bases:
INotification
A base INotification implementation.
PureMVC does not rely upon underlying event models such as the one provided with Flash, and ActionScript 3 does not have an inherent event model.
The Observer Pattern as implemented within PureMVC exists to support event-driven communication between the application and the actors of the MVC triad.
Notifications are not meant to be a replacement for Events in Flex/Flash/Apollo. Generally, IMediator implementors place event listeners on their view components, which they then handle in the usual way. This may lead to the broadcast of Notification to trigger ICommand or to communicate with other IMediators. IProxy and ICommand instances communicate with each other and IMediator`s by broadcasting `INotification.
A key difference between Flash Event and PureMVC Notification is that Event follows the ‘Chain of Responsibility’ pattern, ‘bubbling’ up the display hierarchy until some parent component handles the Event, while PureMVC Notification follows a ‘Publish/Subscribe’ pattern. PureMVC classes need not be related to each other in a parent/child relationship to communicate with one another using Notification.
See Also
puremvc.patterns.observer.Observer
- property body: Any
This method returns the value of the _body attribute.
- Returns:
The value of the _body attribute.
- Return type:
Any
- property name: str
Get the name of the Notification instance.
- Returns:
The name of the Notification instance.
- Return type:
str
- property type: str
Get the body of the Notification instance.
- Returns:
The type of the object.
- Return type:
str
puremvc.patterns.observer.Observer module
- class puremvc.patterns.observer.Observer.Observer(notify_method: Optional[Callable[[INotification], None]] = None, notify_context: Optional[Any] = None)
Bases:
IObserver
A base IObserver implementation.
An Observer is an object that encapsulates information about an interested object with a method that should be called when a particular INotification is broadcast.
In PureMVC, the Observer class assumes 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 notification method and context.
Provide a method for notifying the interested object.
See Also
puremvc.core.View
puremvc.patterns.observer.Notification
- compare_notify_context(obj: Any) bool
Compare an object to the notification context.
- Parameters:
obj (Any) – The object to compare with the notify context.
- Returns:
True if the given object is equal to the notify context, False otherwise.
- Return type:
bool
- property notify_context: Any
Get the notification context.
- Returns:
The notify context.
- Return type:
Any
- property notify_method: Callable[[INotification], None]
Get the notification method.
- Returns:
The notify method.
- Return type:
Callable[[INotification]]
- notify_observer(notification: INotification)
Notify the interested object.
- Parameters:
notification (INotification) – The INotification to pass to the interested
- Returns:
None