puremvc.patterns.facade package
Submodules
puremvc.patterns.facade.Facade module
- class puremvc.patterns.facade.Facade.Facade(key: str)
Bases:
IFacade
A base Multiton IFacade implementation.
In PureMVC, the Facade class assumes these responsibilities:
Initializing the Model, View and Controller Singletons.
Providing all the methods defined by the IModel, IView, & IController interfaces.
Providing the ability to override the specific Model, View and Controller Singletons created.
Providing a single point of contact to the application for registering Commands and notifying Observers
See Also
puremvc.core.Model
puremvc.core.View
puremvc.core.Controller
puremvc.patterns.observer.Notification
puremvc.patterns.mediator.Mediator
puremvc.patterns.proxy.Proxy
puremvc.patterns.command.SimpleCommand
puremvc.patterns.command.MacroCommand
- MULTITON_MSG = 'Facade instance for this Multiton key already constructed!'
- classmethod get_instance(key: str, factory: Callable[[str], IFacade]) IFacade
Facade Multiton Factory method
- Parameters:
key (str) – The key used to identify the Multiton instance
factory (Callable[[str], IFacade]) – A callable object that takes a string parameter and returns an instance of the IFacade interface
- Returns:
the Multiton instance of the Facade
- 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, False otherwise.
- classmethod has_core(key: str) bool
Check if a Core is registered or not
- Parameters:
key (str) – The multiton key for the Core in question
- Returns:
True if an instance with the specified key exists, False otherwise.
- has_mediator(mediator_name: str) bool
Check if a Mediator is registered or not
- Parameters:
mediator_name (str) – The name of the IMediator
- Returns:
True if the mediator with the specified name exists in the view, False otherwise.
- Return type:
bool
- has_proxy(proxy_name: str) bool
Check if a Proxy is registered
- Parameters:
proxy_name (str) – The name of the IProxy
- Returns:
True if the proxy exists, False otherwise.
- initialize_controller()
Initialize the Controller.
Called by the initialize_facade method. Override this method in your subclass of Facade if one or both of the following are true:
You wish to initialize a different IController. You have Commands to register with the Controller at startup.
If you don’t want to initialize a different IController, call super.initialize_controller() at the beginning of your method, then register Proxy.
Note: This method is rarely overridden; in practice, you are more likely to use a Command to create and register Proxy`s with the `Model, since Proxy with mutable data will likely need to send INotification and thus will likely want to fetch a reference to the Facade during their construction.
- Returns:
None
- initialize_facade()
Initialize the Multiton Facade instance.
Called automatically by the constructor. Override in your subclass to do any subclass specific initializations. Be sure to call super.initialize_facade(), though.
- Returns:
None
- initialize_model()
Initialize the Model.
Called by the initialize_facade method. Override this method in your subclass of Facade if one or both of the following are true:
You wish to initialize a different IModel.
You have Proxy to register with the Model that does not retrieve a reference to the Facade at construction time.
If you don’t want to initialize a different IModel, call super.initialize_model() at the beginning of your method, then register Proxy.
Note: This method is rarely overridden; in practice, you are more likely to use a Command to create and register Proxy with the Model, since Proxy with mutable data will likely need to send INotification and thus will likely want to fetch a reference to the Facade during their construction.
- Returns:
None
- initialize_notifier(key: str)
Set the Multiton key for this facade instance.
Not called directly, but instead from the constructor when getInstance is invoked. It is necessary to be public to implement INotifier.
- Parameters:
key (str) – A string representing the key for the notifier.
- Returns:
None
- initialize_view()
Initialize the View.
Called by the initialize_facade method. Override this method in your subclass of Facade if one or both of the following are true:
You wish to initialize a different IView.
You have Observers to register with the View
If you don’t want to initialize a different IView, call super.initialize_view() at the beginning of your method, then register IMediator instances.
Note: This method is rarely overridden; in practice, you are more likely to use a Command to create and register Mediator with the View, since IMediator instances will need to send INotification and thus will likely want to fetch a reference to the Facade during their construction.
- Returns:
None
- instanceMapLock = <unlocked _thread.lock object>
MULTITON_MSG (str): Multiton error message
- notify_observers(notification: INotification)
Notify Observer.
This method is left public mostly for backward compatibility, and to allow you to send custom notification classes using the facade.
Usually you should just call sendNotification and pass the parameters, never having to construct the notification yourself.
- Parameters:
notification (INotification) – The INotification to have the View notify Observers of.
- Returns:
None
- register_command(notification_name: str, factory: Callable[[str], ICommand])
Register an ICommand with the Controller by Notification name.
- Parameters:
notification_name (str) – The name of the INotification to associate the ICommand with
factory (Callable[[str], ICommand]) – A factory function that will be used to create instances of the ICommand.
- Returns:
None
- register_mediator(mediator: IMediator)
Register a IMediator with the View.
- Parameters:
mediator (IMediator) – A reference to the IMediator
- Returns:
None
- register_proxy(proxy: IProxy)
Register an IProxy with the Model by name.
- Parameters:
proxy (IProxy) – The IProxy instance to be registered with the Model.
- Returns:
None.
- 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
- classmethod remove_core(key: str)
Remove a Core.
Remove the Model, View, Controller and Facade instances for the given key.
- Parameters:
key (str) – The key representing the core components to be removed.
- Returns:
None
- remove_mediator(mediator_name: str) IMediator
Remove an IMediator from the View.
- Parameters:
mediator_name (str) – Name of the IMediator to be removed.
- Returns:
The IMediator that was removed from the View
- Return type:
- remove_proxy(proxy_name: str) IProxy
Remove an IProxy from the Model by name.
- Parameters:
proxy_name (IProxy) – The IProxy to remove from the Model.
- Returns:
the IProxy that was removed from the Model
- retrieve_mediator(mediator_name: str) IMediator
Retrieve an IMediator from the View.
- Parameters:
mediator_name (str) – The name of the IMediator
- Returns:
the IMediator previously registered with the given mediator_name.
- Return type:
- retrieve_proxy(proxy_name: str) IProxy
Retrieve an IProxy from the Model by name.
- Parameters:
proxy_name (str) – The name of the proxy to be retrieved.
- Returns:
the IProxy instance previously registered with the given proxyName.
- send_notification(notification_name: str, body: Optional[Any] = None, _type: Optional[str] = None)
Create and send an INotification.
Keeps us from having to construct new notification instances in our implementation code.
- Parameters:
notification_name (str) – The name of the notification.
body (Any) – The body of the notification (optional).
_type (str) – The type of the notification (optional).
- Returns:
None
puremvc.patterns.facade.Notifier module
- class puremvc.patterns.facade.Notifier.Notifier
Bases:
INotifier
A Base INotifier implementation.
MacroCommand, Command, Mediator and Proxy all have a need to send Notifications.
The INotifier interface provides a common method called sendNotification that relieves implementation code of the necessity to actually construct Notifications.
The Notifier class, which all the above-mentioned classes extend, provides an initialized reference to the Facade Multiton, 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.
NOTE: In the MultiCore version of the framework, there is one caveat to notifiers, they cannot send notifications or reach the facade until they have a valid multitonKey.
The multitonKey is set:
on a Command when it is executed by the Controller
on a Mediator is registered with the View
on a Proxy is registered with the Model.
See Also
puremvc.patterns.proxy.Proxy
puremvc.patterns.facade.Facade
puremvc.patterns.mediator.Mediator
puremvc.patterns.command.MacroCommand
puremvc.patterns.command.SimpleCommand
- MULTITON_MSG = 'multitonKey for this Notifier not yet initialized!'
- property facade: IFacade
Return the Multiton Facade instance
- Returns:
The instance of IFacade.
- Return type:
- initialize_notifier(key: str)
Initialize this INotifier instance.
This is how a Notifier gets its multitonKey. Calls to sendNotification or to access the facade will fail until after this method has been called.
Mediators, Commands or Proxies may override this method in order to send notifications or access the Multiton Facade instance as soon as possible. They CANNOT access the facade in their constructors, since this method will not yet have been called.
- Parameters:
key (str) – The multitonKey for this INotifier to use
- Returns:
None
- send_notification(notification_name: str, body: Optional[Any] = None, note_type: Optional[str] = None)
Create and send an INotification.
Keeps us from having to construct new INotification instances in our implementation code.
- Parameters:
notification_name (str) – The name of the notification to be sent.
body (Any, optional) – The body of the notification (optional). Default is None.
note_type (str, optional) – The type of the notification (optional). Default is None.
- Returns:
None