puremvc.interfaces package

Submodules

puremvc.interfaces.ICommand module

class puremvc.interfaces.ICommand.ICommand

Bases: INotifier

The interface definition for a PureMVC Command

See Also

puremvc.interfaces.INotification

abstract execute(notification: INotification)

Execute the ICommand’s logic to handle a given INotification.

Parameters:

notification (INotification) – An INotification to handle.

Returns:

None

puremvc.interfaces.IController module

class puremvc.interfaces.IController.IController

Bases: ABC

The interface definition for a PureMVC Controller.

In PureMVC, an IController implementor follows the ‘Command and Controller’ strategy, and assumes these responsibilities:

Remembering which ICommand`s are intended to handle which `INotifications.

Registering itself as an IObserver with the View for each INotification that it has an ICommand mapping for.

Creating a new instance of the proper ICommand to handle a given INotification when notified by the View.

Calling the ICommand’s execute method, passing in the INotification.

See Also

puremvc.interfaces.INotification puremvc.interfaces.ICommand

abstract execute_command(notification: INotification)

Execute the ICommand previously registered as the handler for INotification with the given notification name.

Parameters:

notification (INotification) – The INotification to execute the associated ICommand for

Returns:

None

abstract has_command(notification_name: str) bool

Check if a Command is registered for a given Notification.

Parameters:

notification_name (str) – The name of the INotification

Returns:

True if a command is registered for the notification_name, False otherwise.

Return type:

bool

abstract register_command(notification_name: str, factory: Callable[[], ICommand])

Register a particular ICommand class as the handler for a particular INotification.

Parameters:
  • notification_name (str) – The name of the INotification

  • factory (Callable[[], ICommand]) – A factory function that returns an instance of ICommand.

Returns:

None

abstract remove_command(notification_name: str)

Remove a previously registered ICommand to INotification mapping.

Parameters:

notification_name (str) – The name of the INotification to remove the ICommand mapping for

Returns:

None

puremvc.interfaces.IFacade module

class puremvc.interfaces.IFacade.IFacade

Bases: INotifier, ABC

The interface definition for a PureMVC Facade.

The Facade Pattern suggests providing a single class to act as a central point of communication for a subsystem.

In PureMVC, the Facade acts as an interface between the core MVC actors (Model, View, Controller) and the rest of your application.

puremvc.interfaces.IModel puremvc.interfaces.IView puremvc.interfaces.IController puremvc.interfaces.ICommand puremvc.interfaces.INotification

abstract has_command(notification_name: str) bool

Check if a Command is registered for a given Notification.

Parameters:

notification_name (str) – The name of the notification to check.

Returns:

True if a command exists for the given notification_name, False otherwise.

abstract has_mediator(mediator_name: str) bool

Check if a Mediator is registered or not

Parameters:

mediator_name (str) – The name of the mediator to check for.

Returns:

True if the mediator exists, False otherwise.

abstract has_proxy(proxy_name: str) bool

Check if a Proxy is registered

Parameters:

proxy_name (str) – The name of the proxy to check.

Returns:

True if the proxy is currently registered, False otherwise.

Return type:

bool

abstract notify_observers(notification: INotification)

Notify Observer

Parameters:

notification (INotification) – The INotification to have the View notify Observers of.

Returns:

None

abstract register_command(notification_name: str, factory: Callable[[], ICommand])

Register an ICommand with the Controller.

Parameters:
  • notification_name (str) – The name of the INotification to associate the ICommand with.

  • factory (Callable[[], ICommand]) – A callable factory function that creates an instance of ICommand.

Returns:

None

abstract register_mediator(mediator: IMediator)

Register an IMediator instance with the View.

Parameters:

mediator (IMediator) – A reference to the IMediator instance

Returns:

None

abstract register_proxy(proxy: IProxy)

Register a Proxy with the Model by name.

Parameters:

proxy (IProxy) – The IProxy to be registered with the Model.

Returns:

None

abstract remove_command(notification_name: str)

Remove a previously registered ICommand to INotification mapping from the Controller.

Parameters:

notification_name (str) – The name of the INotification to remove the ICommand mapping for

Returns:

None

abstract remove_mediator(mediator_name: str) IMediator

Remove a IMediator instance from the View.

Parameters:

mediator_name (str) – name of the IMediator instance to be removed.

Returns:

The IMediator instance previously registered with the given mediator_name.

abstract remove_proxy(proxy_name: str) IProxy

Remove an IProxy instance from the Model by name.

Parameters:

proxy_name (str) – The IProxy to remove from the Model.

Returns:

the IProxy that was removed from the Model

Return type:

IProxy

abstract retrieve_mediator(mediator_name: str) IMediator

Retrieve an IMediator instance from the View.

Parameters:

mediator_name (str) – The name of the IMediator instance to retrieve

Returns:

The mediator object found, of type IMediator.

abstract retrieve_proxy(proxy_name: str) IProxy

Retrieve a IProxy from the Model by name.

Parameters:

proxy_name (str) – The name of the IProxy instance to be retrieved.

Returns:

the IProxy previously registered by proxyName with the Model.

puremvc.interfaces.IMediator module

class puremvc.interfaces.IMediator.IMediator

Bases: INotifier

The base interface for all Mediator classes.

In PureMVC, IMediator implementors assume these responsibilities:

Implement a common method which returns a list of all INotification the IMediator has interest in implementing a notification callback method. Implement methods that are called when the IMediator is registered or removed from the View.

Additionally, IMediator typically:

Act as an intermediary between one or more view components such as text boxes or list controls, maintaining references and coordinating their behavior.

In Flash-based apps, this is often the place where event listeners are added to view components, and their handlers implemented.

Respond to and generate INotifications, interacting with of the rest of the PureMVC app.

When an IMediator is registered with the IView, the IView will call the IMediator’s list_notification_interests method. The IMediator will return an Array of INotification names which it wishes to be notified about.

The IView will then create an Observer object encapsulating that IMediator’s (handle_notification) method and register it as an Observer for each INotification name returned by list_notification_interests.

See Also

puremvc.interfaces.INotification

abstract handle_notification(notification: INotification)

Handle an INotification.

Parameters:

notification (INotification) – The INotification to be handled

Returns:

None

abstract list_notification_interests() [<class 'str'>]

List INotification interests.

Returns:

A list containing strings representing the notification interests.

Return type:

[str]

abstract property mediator_name: str

Get the IMediator instance name.

Returns:

The IMediator instance name

abstract on_register()

Called by the View when the Mediator is registered :return: None

abstract on_remove()

Called by the View when the Mediator is removed :return: None

abstract property view_component: Any

Get the IMediator’s view component.

Returns:

The view component.

Return type:

Any

puremvc.interfaces.IModel module

class puremvc.interfaces.IModel.IModel

Bases: ABC

The interface definition for a PureMVC Model.

In PureMVC, IModel implementors provide access to IProxy objects by named look up.

An IModel assumes these responsibilities:

Maintain a cache of IProxy instances Provide methods for registering, retrieving, and removing IProxy instances

abstract has_proxy(proxy_name: str) bool

Check if a proxy with the given name is registered.

Parameters:

proxy_name (str) – The name of the proxy to check.

Returns:

True if the proxy is registered, False otherwise.

Return type:

bool

abstract register_proxy(proxy: IProxy)

Register an IProxy instance with the Model.

Parameters:

proxy (IProxy) – An object reference to be held by the Model.

abstract remove_proxy(proxy_name: str) IProxy

Remove an IProxy instance from the Model.

Parameters:

proxy_name (str) – The name of the proxy to remove.

Returns:

The IProxy instance that was removed from the Model.

Return type:

IProxy

abstract retrieve_proxy(proxy_name: str) IProxy

Retrieve an IProxy instance from the Model.

Parameters:

proxy_name (str) – The name of the proxy to retrieve.

Returns:

The IProxy instance previously registered with the given proxy_name.

Return type:

IProxy

puremvc.interfaces.INotification module

class puremvc.interfaces.INotification.INotification

Bases: ABC

The interface definition for a PureMVC Notification.

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/AIR. 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 IMediator, IProxy and ICommand instances communicate with each other and IMediator 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.interfaces.IView puremvc.interfaces.IObserver

abstract property body: Any

Get the body of the INotification instance

Returns:

The body of the method.

Return type:

Any

abstract property name: str

Get the name of the INotification instance. No setter, it should be set by constructor only

Returns:

The name of the object.

abstract property type: str

Get the type of the INotification instance

Returns:

The type of the object.

Return type:

str

puremvc.interfaces.INotifier module

class puremvc.interfaces.INotifier.INotifier

Bases: ABC

The interface definition for a PureMVC Notifier.

MacroCommand, Command, Mediator and Proxy all have a need to send Notifications.

The INotifier interface provides a common method called send_notification that relieves implementation code of the necessity to actually construct Notifications.

The Notifier class, which all the above-mentioned classes extend, also provides an initialized reference to the Facade Singleton, which is required for the convenience method for sending Notifications, but also eases implementation as these classes have frequent Facade interactions and usually require access to the facade anyway.

See Also

puremvc.interfaces.IFacade puremvc.interfaces.INotification

abstract initialize_notifier(key: str)

Initialise this INotifier instance.

This is how a Notifier gets its multiton_key. Calls to send_notification or to access the facade will fail until after this method has been called.

@param key: The multiton_key for this INotifier to use

abstract send_notification(notification_name: str, body: Optional[Any] = None, _type: Optional[str] = None)

Send a INotification.

Convenience method to prevent having to construct new notification instances in our implementation code.

@param notification_name: The name of the notification to send @type notification_name: str @param body: the body of the notification (optional) @type body: Any @param _type: the type of the notification (optional) @type _type: str

puremvc.interfaces.IObserver module

class puremvc.interfaces.IObserver.IObserver

Bases: ABC

The interface definition for a PureMVC Observer.

In PureMVC, IObserver implementors assume these responsibilities:

Encapsulate the notification (callback) method of the interested object.

Encapsulate the notification context 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, 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.

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

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

See Also

puremvc.interfaces.IView puremvc.interfaces.INotification

abstract compare_notify_context(obj: Any) bool

Compare the given object to the notification context object.

Parameters:

obj (Any) – The object to compare.

Returns:

boolean indicating if the notification context and the object are the same.

abstract property notify_context: Any

Get the notify_context.

Returns:

notify context

Return type:

Any

abstract property notify_method: Callable[[INotification], None]

Set the notification method.

The notification method should take one parameter of type INotification

Returns:

The notification (callback) method of the interested object

Return type:

Callable[[INotification], None]

abstract notify_observer(notification: INotification)

Notify the interested object.

Parameters:

notification (INotification) – The INotification to pass to the interested object’s notification method

puremvc.interfaces.IProxy module

class puremvc.interfaces.IProxy.IProxy

Bases: INotifier

The interface definition for a PureMVC Proxy.

In PureMVC, ‘IProxy’ implementors assume these responsibilities:</P>

Implement a common method which returns the name of the Proxy. Provide methods for setting and getting the data object.

Additionally, ‘IProxy’s typically:

Maintain references to one or more pieces of model data. Provide methods for manipulating that data. Generate ‘INotifications’ when their model data changes. Expose their name as a ‘public static const’ called ‘NAME’, if they are not instantiated multiple times. Encapsulate interaction with local or remote services used to fetch and persist model data.

abstract property data: Any

Get the data object

Returns:

The data of the method.

Return type:

Any

abstract on_register()

Called by the Model when the Proxy is registered.

abstract on_remove()

Called by the Model when the Proxy is removed.

abstract property proxy_name: str

Get the Proxy name

Returns:

The name of the proxy as a string.

Return type:

str

puremvc.interfaces.IView module

class puremvc.interfaces.IView.IView

Bases: ABC

The interface definition for a PureMVC View.

In PureMVC, IView implementors assume these responsibilities:

In PureMVC, the View class assumes these responsibilities:

Maintain a cache of IMediator instances. Provide methods for registering, retrieving, and removing IMediators. Managing the observer lists for each INotification in the application. Providing a method for attaching IObservers to an INotification’s observer list. Providing a method for broadcasting an INotification. Notifying the IObservers of a given INotification when it broadcast.

See Also

puremvc.interfaces.IMediator puremvc.interfaces.IObserver puremvc.interfaces.INotification

abstract has_mediator(mediator_name: str) bool

Check if a Mediator is registered or not.

Parameters:

mediator_name (str) – Name of the IMediator

Returns:

whether a Mediator is registered with the given mediatorName.

Return type:

bool

abstract notify_observers(notification: INotification)

Notify the IObservers for a particular INotification.

All previously attached IObservers for this INotification’s list are notified and are passed a reference to the INotification in the order in which they were registered.

Parameters:

notification (INotification) – The INotification to notify IObservers of.

abstract register_mediator(mediator: IMediator)

Register an IMediator instance with the View.

Registers the IMediator so that it can be retrieved by name, and further interrogates the IMediator for its INotification interests.

If the IMediator returns any INotification names to be notified about, an Observer is created encapsulating the IMediator instance’s handleNotification method and registering it as an Observer for all INotifications the IMediator is interested in.

Parameters:

mediator – A reference to the IMediator instance

abstract register_observer(notification_name: str, observer: IObserver)

Register an IObserver to be notified of INotifications with a given name.

Parameters:
  • notification_name (str) – The name of the INotifications to notify this IObserver of

  • observer (IObserver) – The IObserver to register

abstract remove_mediator(mediator_name: str) IMediator

Remove an IMediator from the View.

Parameters:

mediator_name (str) – Name of the IMediator instance to be removed.

Returns:

the IMediator that was removed from the View

Return type:

IMediator

abstract remove_observer(notification_name: str, notify_context: Any)

Remove a group of observers from the observer list for a given Notification name.

Parameters:
  • notification_name (str) – Which observer list to remove from

  • notify_context (Any) – Removed the observers with this object as their notify_context

abstract retrieve_mediator(mediator_name: str) IMediator

Retrieve an IMediator from the View.

Parameters:

mediator_name (str) – The name of the IMediator instance to retrieve.

Returns:

The IMediator instance previously registered with the given mediatorName.

Return type:

IMediator

Module contents