puremvc 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +11 -0
- data/LICENSE +28 -0
- data/README.md +88 -0
- data/lib/core/controller.rb +177 -0
- data/lib/core/model.rb +133 -0
- data/lib/core/view.rb +230 -0
- data/lib/patterns/command/macro_command.rb +81 -0
- data/lib/patterns/command/simple_command.rb +28 -0
- data/lib/patterns/facade/facade.rb +267 -0
- data/lib/patterns/mediator/mediator.rb +56 -0
- data/lib/patterns/observer/notification.rb +68 -0
- data/lib/patterns/observer/notifier.rb +87 -0
- data/lib/patterns/observer/observer.rb +55 -0
- data/lib/patterns/proxy/proxy.rb +50 -0
- data/lib/puremvc.rb +19 -0
- data/sig/lib/core/controller.rbs +40 -0
- data/sig/lib/core/model.rbs +38 -0
- data/sig/lib/core/view.rbs +42 -0
- data/sig/lib/interfaces/i_command.rbs +18 -0
- data/sig/lib/interfaces/i_controller.rbs +52 -0
- data/sig/lib/interfaces/i_facade.rbs +116 -0
- data/sig/lib/interfaces/i_mediator.rbs +60 -0
- data/sig/lib/interfaces/i_model.rbs +38 -0
- data/sig/lib/interfaces/i_notification.rbs +52 -0
- data/sig/lib/interfaces/i_notifier.rbs +48 -0
- data/sig/lib/interfaces/i_observer.rbs +56 -0
- data/sig/lib/interfaces/i_proxy.rbs +36 -0
- data/sig/lib/interfaces/i_view.rbs +71 -0
- data/sig/lib/patterns/command/macro_command.rbs +18 -0
- data/sig/lib/patterns/command/simple_command.rbs +11 -0
- data/sig/lib/patterns/facade/facade.rbs +48 -0
- data/sig/lib/patterns/mediator/mediator.rbs +18 -0
- data/sig/lib/patterns/observer/notification.rbs +18 -0
- data/sig/lib/patterns/observer/notifier.rbs +17 -0
- data/sig/lib/patterns/observer/observer.rbs +20 -0
- data/sig/lib/patterns/proxy/proxy.rbs +19 -0
- metadata +71 -56
- data/puremvc.rb +0 -13
- data/src/org/puremvc/ruby/core/controller.rb +0 -76
- data/src/org/puremvc/ruby/core/model.rb +0 -57
- data/src/org/puremvc/ruby/core/view.rb +0 -112
- data/src/org/puremvc/ruby/patterns/command/macro_command.rb +0 -59
- data/src/org/puremvc/ruby/patterns/command/simple_command.rb +0 -17
- data/src/org/puremvc/ruby/patterns/facade/facade.rb +0 -161
- data/src/org/puremvc/ruby/patterns/mediator/mediator.rb +0 -37
- data/src/org/puremvc/ruby/patterns/observer/notification.rb +0 -38
- data/src/org/puremvc/ruby/patterns/observer/notifier.rb +0 -27
- data/src/org/puremvc/ruby/patterns/observer/observer.rb +0 -31
- data/src/org/puremvc/ruby/patterns/proxy/proxy.rb +0 -32
- data/version.txt +0 -12
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# proxy.rb
|
4
|
+
# PureMVC Ruby Multicore
|
5
|
+
#
|
6
|
+
# Copyright(c) 2025 Saad Shams <saad.shams@puremvc.org>
|
7
|
+
# Your reuse is governed by the BSD 3-Clause License
|
8
|
+
|
9
|
+
module PureMVC
|
10
|
+
# A base <code>IProxy</code> implementation.
|
11
|
+
#
|
12
|
+
# In PureMVC, <code>Proxy</code> classes are used to manage parts of the application's data model.
|
13
|
+
#
|
14
|
+
# A <code>Proxy</code> might simply manage a reference to a local data object, in which case
|
15
|
+
# interacting with it might involve setting and getting of its data in a synchronous fashion.
|
16
|
+
#
|
17
|
+
# <code>Proxy</code> classes are also used to encapsulate the application's interaction with
|
18
|
+
# remote services to save or retrieve data. In this case, we adopt an asynchronous idiom:
|
19
|
+
# setting data (or calling a method) on the <code>Proxy</code> and listening for a <code>Notification</code>
|
20
|
+
# to be sent when the <code>Proxy</code> has retrieved the data from the service.
|
21
|
+
#
|
22
|
+
# @see Model
|
23
|
+
class Proxy < Notifier
|
24
|
+
# The name of the <code>Proxy</code>.
|
25
|
+
NAME = 'Proxy'
|
26
|
+
public_constant :NAME
|
27
|
+
|
28
|
+
# @return [String] The proxy name
|
29
|
+
attr_reader :name
|
30
|
+
|
31
|
+
# @return [Object, nil] The data managed by the proxy
|
32
|
+
attr_accessor :data
|
33
|
+
|
34
|
+
# Initializes a new Proxy instance.
|
35
|
+
#
|
36
|
+
# @param [String, nil] name the name of the proxy
|
37
|
+
# @param [Object, nil] data optional data to be managed by the proxy
|
38
|
+
def initialize(name = nil, data = nil)
|
39
|
+
super()
|
40
|
+
@name = name || NAME
|
41
|
+
@data = data
|
42
|
+
end
|
43
|
+
|
44
|
+
# Called by the Model when the Proxy is registered
|
45
|
+
def on_register; end
|
46
|
+
|
47
|
+
# Called by the Model when the Proxy is removed
|
48
|
+
def on_remove; end
|
49
|
+
end
|
50
|
+
end
|
data/lib/puremvc.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# puremvc.rb
|
4
|
+
# PureMVC Ruby Multicore
|
5
|
+
#
|
6
|
+
# Copyright(c) 2025 Saad Shams <saad.shams@puremvc.org>
|
7
|
+
# Your reuse is governed by the BSD 3-Clause License
|
8
|
+
|
9
|
+
require_relative 'core/controller'
|
10
|
+
require_relative 'core/model'
|
11
|
+
require_relative 'core/view'
|
12
|
+
require_relative 'patterns/observer/notifier'
|
13
|
+
require_relative 'patterns/command/simple_command'
|
14
|
+
require_relative 'patterns/command/macro_command'
|
15
|
+
require_relative 'patterns/facade/facade'
|
16
|
+
require_relative 'patterns/mediator/mediator'
|
17
|
+
require_relative 'patterns/observer/notification'
|
18
|
+
require_relative 'patterns/observer/observer'
|
19
|
+
require_relative 'patterns/proxy/proxy'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module PureMVC
|
2
|
+
|
3
|
+
class Controller
|
4
|
+
|
5
|
+
include _IController
|
6
|
+
|
7
|
+
MULTITON_MSG: String
|
8
|
+
|
9
|
+
self.@instance_map: Hash[String, _IController]
|
10
|
+
|
11
|
+
self.@mutex: Mutex
|
12
|
+
|
13
|
+
@multiton_key: String
|
14
|
+
|
15
|
+
@view: _IView?
|
16
|
+
|
17
|
+
@command_map: Hash[String, ^() -> _ICommand]
|
18
|
+
|
19
|
+
@command_mutex: Mutex
|
20
|
+
|
21
|
+
def self.instance_map: () -> Hash[String, _IController]
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def self.mutex: () -> Mutex
|
26
|
+
|
27
|
+
public
|
28
|
+
|
29
|
+
def self.get_instance: (String key) { (String k) -> _IController } -> _IController
|
30
|
+
|
31
|
+
def self.remove_controller: (String key) -> void
|
32
|
+
|
33
|
+
def initialize: (String key) -> void
|
34
|
+
|
35
|
+
def initialize_controller: () -> void
|
36
|
+
end
|
37
|
+
|
38
|
+
# Type-level assertion that Controller conforms to _IController
|
39
|
+
type controller_validation = validate_controller[Controller]
|
40
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module PureMVC
|
2
|
+
|
3
|
+
class Model
|
4
|
+
|
5
|
+
include _IModel
|
6
|
+
|
7
|
+
MULTITON_MSG: String
|
8
|
+
|
9
|
+
self.@instance_map: Hash[String, _IModel]
|
10
|
+
|
11
|
+
self.@mutex: Mutex
|
12
|
+
|
13
|
+
@multiton_key: String
|
14
|
+
|
15
|
+
@proxy_map: Hash[String, _IProxy]
|
16
|
+
|
17
|
+
@proxy_mutex: Mutex
|
18
|
+
|
19
|
+
def self.instance_map: () -> Hash[String, _IModel]
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def self.mutex: () -> Mutex
|
24
|
+
|
25
|
+
public
|
26
|
+
|
27
|
+
def self.get_instance: (String key) { (String k) -> _IModel } -> _IModel
|
28
|
+
|
29
|
+
def self.remove_model: (String key) -> void
|
30
|
+
|
31
|
+
def initialize: (String key) -> void
|
32
|
+
|
33
|
+
def initialize_model: () -> void
|
34
|
+
end
|
35
|
+
|
36
|
+
# Type-level assertion that Model conforms to _IModel
|
37
|
+
type model_validation = validate_model[Model]
|
38
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module PureMVC
|
2
|
+
|
3
|
+
class View
|
4
|
+
|
5
|
+
include _IView
|
6
|
+
|
7
|
+
MULTITON_MSG: String
|
8
|
+
|
9
|
+
self.@instance_map: Hash[String, _IView]
|
10
|
+
|
11
|
+
self.@mutex: Mutex
|
12
|
+
|
13
|
+
@multiton_key: String
|
14
|
+
|
15
|
+
@observer_map: Hash[String, Array[_IObserver]]
|
16
|
+
|
17
|
+
@observer_mutex: Mutex
|
18
|
+
|
19
|
+
@mediator_map: Hash[String, _IMediator]
|
20
|
+
|
21
|
+
@mediator_mutex: Mutex
|
22
|
+
|
23
|
+
def self.instance_map: () -> Hash[String, _IView]
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def self.mutex: () -> Mutex
|
28
|
+
|
29
|
+
public
|
30
|
+
|
31
|
+
def self.get_instance: (String key) { (String k) -> _IView } -> _IView
|
32
|
+
|
33
|
+
def self.remove_view: (String key) -> void
|
34
|
+
|
35
|
+
def initialize: (String key) -> void
|
36
|
+
|
37
|
+
def initialize_view: () -> void
|
38
|
+
end
|
39
|
+
|
40
|
+
# Type-level assertion that View conforms to _IView
|
41
|
+
type view_validation = validate_view[View]
|
42
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module PureMVC
|
2
|
+
# The interface definition for a PureMVC Command.
|
3
|
+
#
|
4
|
+
# @see INotification
|
5
|
+
interface _ICommand
|
6
|
+
|
7
|
+
include _INotifier
|
8
|
+
|
9
|
+
# Execute the <code>_ICommand</code>'s logic to handle a given <code>_INotification</code>.
|
10
|
+
#
|
11
|
+
# @abstract This method must be implemented by the concrete command.
|
12
|
+
# @param notification [_INotification] an _INotification to handle.
|
13
|
+
def execute: (_INotification notification) -> void
|
14
|
+
end
|
15
|
+
|
16
|
+
# Assert that the given `Command` type parameter is a subtype of `_ICommand`
|
17
|
+
type validate_command[Command < _ICommand] = top
|
18
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module PureMVC
|
2
|
+
# The interface definition for a PureMVC Controller.
|
3
|
+
#
|
4
|
+
# In PureMVC, an <code>_IController</code> implementor
|
5
|
+
# follows the 'Command and Controller' strategy, and
|
6
|
+
# assumes these responsibilities:
|
7
|
+
#
|
8
|
+
# - Remembering which <code>_ICommand</code>s
|
9
|
+
# are intended to handle which <code>_INotifications</code>.
|
10
|
+
# - Registering itself as an <code>_IObserver</code> with
|
11
|
+
# the <code>View</code> for each <code>_INotification</code>
|
12
|
+
# that it has an <code>_ICommand</code> mapping for.
|
13
|
+
# - Creating a new instance of the proper <code>_ICommand</code>
|
14
|
+
# to handle a given <code>_INotification</code> when notified by the <code>View</code>.
|
15
|
+
# - Calling the <code>_ICommand</code>'s <code>execute</code>
|
16
|
+
# method, passing in the <code>_INotification</code>.
|
17
|
+
#
|
18
|
+
# @see INotification
|
19
|
+
# @see ICommand
|
20
|
+
interface _IController
|
21
|
+
# Register a particular <code>_ICommand</code> class as the handler
|
22
|
+
# for a particular <code>_INotification</code>.
|
23
|
+
#
|
24
|
+
# @abstract This method must be implemented by the concrete command.
|
25
|
+
# @param notification_name [String] the name of the <code>_INotification</code>
|
26
|
+
# @param factory [^() -> _ICommand] the class of the _ICommand
|
27
|
+
def register_command: (String notification_name) { () -> _ICommand } -> void
|
28
|
+
|
29
|
+
# Execute the <code>ICommand</code> previously registered as the
|
30
|
+
# handler for <code>INotification</code>s with the given notification name.
|
31
|
+
#
|
32
|
+
# @abstract This method must be implemented by the concrete command.
|
33
|
+
# @param notification [_INotification] the <code>_INotification</code> to execute the associated <code>_ICommand</code> for
|
34
|
+
def execute_command: (_INotification notification) -> void
|
35
|
+
|
36
|
+
# Check if a Command is registered for a given Notification.
|
37
|
+
#
|
38
|
+
# @abstract This method must be implemented by the concrete command.
|
39
|
+
# @param notification_name [String]
|
40
|
+
# @return [Boolean] whether a Command is currently registered for the given <code>notificationName</code>.
|
41
|
+
def has_command?: (String notification_name) -> bool
|
42
|
+
|
43
|
+
# Remove a previously registered <code>_ICommand</code> to <code>_INotification</code> mapping.
|
44
|
+
#
|
45
|
+
# @abstract This method must be implemented by the concrete command.
|
46
|
+
# @param notification_name [String] the name of the <code>_INotification</code> to remove the <code>_ICommand</code> mapping for
|
47
|
+
def remove_command: (String notification_name) -> void
|
48
|
+
end
|
49
|
+
|
50
|
+
# Assert that the given `Controller` type parameter is a subtype of `_IController`
|
51
|
+
type validate_controller[Controller < _IController] = top
|
52
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module PureMVC
|
2
|
+
# The interface definition for a PureMVC Facade.
|
3
|
+
#
|
4
|
+
# The Facade Pattern suggests providing a single
|
5
|
+
# class to act as a central point of communication
|
6
|
+
# for a subsystem.
|
7
|
+
#
|
8
|
+
# In PureMVC, the Facade acts as an interface between
|
9
|
+
# the core MVC actors (<code>Model</code>, <code>View</code>, <code>Controller</code>) and
|
10
|
+
# the rest of your application.
|
11
|
+
#
|
12
|
+
# @see IModel
|
13
|
+
# @see IView
|
14
|
+
# @see IController
|
15
|
+
# @see ICommand
|
16
|
+
# @see INotification
|
17
|
+
interface _IFacade
|
18
|
+
|
19
|
+
# Register an <code>_ICommand</code> with the <code>Controller</code>.
|
20
|
+
#
|
21
|
+
# @param notification_name [String] the name of the <code>_INotification</code> to associate the <code>_ICommand</code> with.
|
22
|
+
# @param factory [^() -> _ICommand] the factory to produce an instance of the _ICommand
|
23
|
+
def register_command: (String notification_name) { () -> _ICommand } -> void
|
24
|
+
|
25
|
+
# Check if a Command is registered for a given Notification
|
26
|
+
#
|
27
|
+
# @param notification_name [String]
|
28
|
+
# @return [Boolean] whether a Command is currently registered for the given <code>notification_name</code>.
|
29
|
+
def has_command?: (String notification_name) -> bool
|
30
|
+
|
31
|
+
# Remove a previously registered <code>_ICommand</code> to <code>_INotification</code> mapping from the Controller.
|
32
|
+
#
|
33
|
+
# @param notification_name [String] the name of the <code>_INotification</code> to remove the <code>_ICommand</code> mapping for
|
34
|
+
def remove_command: (String notification_name) -> void
|
35
|
+
|
36
|
+
# Register an <code>_IProxy</code> with the <code>Model</code> by name.
|
37
|
+
#
|
38
|
+
# @param proxy [_IProxy] the <code>_IProxy</code> to be registered with the <code>Model</code>.
|
39
|
+
def register_proxy: (_IProxy proxy) -> void
|
40
|
+
|
41
|
+
# Retrieve a <code>IProxy</code> from the <code>Model</code> by name.
|
42
|
+
#
|
43
|
+
# @param proxy_name [String] the name of the <code>_IProxy</code> instance to be retrieved.
|
44
|
+
# @return [_IProxy | nil] the <code>IProxy</code> previously registered by <code>proxy_name</code> with the <code>Model</code>.
|
45
|
+
def retrieve_proxy: (String proxy_name) -> _IProxy?
|
46
|
+
|
47
|
+
# Check if a Proxy is registered
|
48
|
+
#
|
49
|
+
# @param proxy_name [String]
|
50
|
+
# @return [Boolean] whether a Proxy is currently registered with the given <code>proxy_name</code>.
|
51
|
+
def has_proxy?: (String proxy_name) -> bool
|
52
|
+
|
53
|
+
# Remove an <code>_IProxy</code> instance from the <code>Model</code> by name.
|
54
|
+
#
|
55
|
+
# @param proxy_name [String] the <code>_IProxy</code> to remove from the <code>Model</code>.
|
56
|
+
# @return [_IProxy | nil] the <code>_IProxy</code> that was removed from the <code>Model</code>
|
57
|
+
def remove_proxy: (String proxy_name) -> _IProxy?
|
58
|
+
|
59
|
+
# Register an <code>_IMediator</code> instance with the <code>View</code>.
|
60
|
+
#
|
61
|
+
# @param mediator [_IMediator] a reference to the <code>_IMediator</code> instance
|
62
|
+
def register_mediator: (_IMediator mediator) -> void
|
63
|
+
|
64
|
+
# Retrieve an <code>_IMediator</code> instance from the <code>View</code>.
|
65
|
+
#
|
66
|
+
# @param mediator_name [String] the name of the <code>_IMediator</code> instance to retrieve
|
67
|
+
# @return [_IMediator | nil] the <code>_IMediator</code> previously registered with the given <code>mediator_name</code>.
|
68
|
+
def retrieve_mediator: (String mediator_name) -> _IMediator?
|
69
|
+
|
70
|
+
# Check if a Mediator is registered or not
|
71
|
+
#
|
72
|
+
# @param mediator_name [String]
|
73
|
+
# @return [Boolean] whether a Mediator is registered with the given <code>mediator_name</code>.
|
74
|
+
def has_mediator?: (String mediator_name) -> bool
|
75
|
+
|
76
|
+
# Remove an <code>_IMediator</code> instance from the <code>View</code>.
|
77
|
+
#
|
78
|
+
# @param mediator_name [String] name of the <code>IMediator</code> instance to be removed.
|
79
|
+
# @return [_IMediator | nil] the <code>_IMediator</code> instance previously registered with the given <code>mediator_name</code>.
|
80
|
+
def remove_mediator: (String mediator_name) -> _IMediator?
|
81
|
+
|
82
|
+
# Initialize this _INotifier instance.
|
83
|
+
#
|
84
|
+
# This is how a </code>Notifier</code> gets its multitonKey.
|
85
|
+
# Calls to <code>send_notification</code> or to access the
|
86
|
+
# facade will fail until after this method has been called.
|
87
|
+
#
|
88
|
+
# @param key [String] The multitonKey for this INotifier to use.
|
89
|
+
def initialize_notifier: (String key) -> void
|
90
|
+
|
91
|
+
# Notify <code>Observer</code>s.
|
92
|
+
#
|
93
|
+
# This method is left public mostly for backward
|
94
|
+
# compatibility and to allow you to send custom
|
95
|
+
# notification classes using the facade.
|
96
|
+
#
|
97
|
+
# Usually you should call sendNotification
|
98
|
+
# and pass the parameters, never having to
|
99
|
+
# construct the notification yourself.
|
100
|
+
#
|
101
|
+
# @param notification [_INotification] the <code>_INotification</code> to have the <code>View</code> notify <code>Observers</code> of.
|
102
|
+
def notify_observers: (_INotification notification) -> void
|
103
|
+
|
104
|
+
# Send a <code>_INotification</code>.
|
105
|
+
#
|
106
|
+
# Convenience method to prevent having to construct new
|
107
|
+
# notification instances in our implementation code.
|
108
|
+
#
|
109
|
+
# @param name [String] The name of the notification to send.
|
110
|
+
# @param body [Object, nil] The body of the notification (optional).
|
111
|
+
# @param type [String, nil] The type of the notification (optional).
|
112
|
+
def send_notification: (String name, ?Object? body, ?String? type) -> void
|
113
|
+
end
|
114
|
+
|
115
|
+
type validate_facade[Facade < _IFacade] = top
|
116
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module PureMVC
|
2
|
+
#
|
3
|
+
# The interface definition for a PureMVC <code>_IMediator</code>.
|
4
|
+
#
|
5
|
+
# In PureMVC, <code>_IMediator</code> implementors assume these responsibilities:
|
6
|
+
#
|
7
|
+
# * Implement a common method that returns a list of all <code>_INotification</code>s
|
8
|
+
# the <code>_IMediator</code> has interest in.
|
9
|
+
# * Implement a notification callback method.
|
10
|
+
# * Implement methods that are called when the <code>_IMediator</code> is registered or removed from the <code>View</code>.
|
11
|
+
#
|
12
|
+
# Additionally, <code>_IMediator</code>s typically:
|
13
|
+
#
|
14
|
+
# * Act as an intermediary between one or more view components such as text boxes or list controls,
|
15
|
+
# maintaining references and coordinating their behavior.
|
16
|
+
# * In Flash-based apps, this is often the place where event listeners are
|
17
|
+
# added to view components, and their handlers implemented.
|
18
|
+
# * Respond to and generate <code>_INotifications</code>, interacting with the rest of the PureMVC app.
|
19
|
+
#
|
20
|
+
# When an <code>_IMediator</code> is registered with the <code>_IView</code>,
|
21
|
+
# the <code>_IView</code> will call the <code>_IMediator</code>'s <code>list_notification_interests</code> method.
|
22
|
+
# The <code>_IMediator</code> will return an <code>Array</code> of <code>_INotification</code> names
|
23
|
+
# which it wishes to be notified about.
|
24
|
+
#
|
25
|
+
# The <code>_IView</code> will then create an <code>Observer</code> object
|
26
|
+
# encapsulating that <code>IMediator</code>'s <code>handle_notification</code> method
|
27
|
+
# and register it as an Observer for each <code>_INotification</code> name returned by <code>list_notification_interests</code>.
|
28
|
+
#
|
29
|
+
# @see INotification
|
30
|
+
interface _IMediator
|
31
|
+
|
32
|
+
include _INotifier
|
33
|
+
|
34
|
+
# @return [String] The name of the Mediator.
|
35
|
+
def name: () -> String
|
36
|
+
|
37
|
+
# @return [Object, nil] The view component associated with this Mediator.
|
38
|
+
def view: () -> Object?
|
39
|
+
def view=: (Object?) -> void
|
40
|
+
|
41
|
+
# List <code>_INotification</code> interests.
|
42
|
+
#
|
43
|
+
# @return [Array] an <code>Array</code> of the <code>_INotification</code> names this <code>_IMediator</code> has an interest in.
|
44
|
+
def list_notification_interests: () -> Array[String]
|
45
|
+
|
46
|
+
# Handle an <code>INotification</code>.
|
47
|
+
#
|
48
|
+
# @param notification [_INotification] the <code>_INotification</code> to be handled
|
49
|
+
def handle_notification: (_INotification notification) -> void
|
50
|
+
|
51
|
+
# Called by the View when the Mediator is registered.
|
52
|
+
def on_register: () -> void
|
53
|
+
|
54
|
+
# Called by the View when the Mediator is registered.
|
55
|
+
def on_remove: () -> void
|
56
|
+
end
|
57
|
+
|
58
|
+
# Assert that the given `Mediator` type parameter is a subtype of `_IMediator`
|
59
|
+
type validate_mediator[Mediator < _IMediator] = top
|
60
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module PureMVC
|
2
|
+
# The interface definition for a PureMVC Model.
|
3
|
+
#
|
4
|
+
# In PureMVC, <code>_IModel</code> implementors provide
|
5
|
+
# access to <code>_IProxy</code> objects by named lookup.
|
6
|
+
#
|
7
|
+
# An <code>_IModel</code> assumes these responsibilities:
|
8
|
+
#
|
9
|
+
# - Maintain a cache of <code>_IProxy</code> instances
|
10
|
+
# - Provide methods for registering, retrieving, and removing <code>_IProxy</code> instances
|
11
|
+
interface _IModel
|
12
|
+
# Register an <code>_IProxy</code> instance with the <code>Model</code>.
|
13
|
+
#
|
14
|
+
# @param proxy [_IProxy] an object reference to be held by the <code>Model</code>.
|
15
|
+
def register_proxy: (_IProxy proxy) -> void
|
16
|
+
|
17
|
+
# Retrieve an <code>_IProxy</code> instance from the <code>Model</code>.
|
18
|
+
#
|
19
|
+
# @param proxy_name [String]
|
20
|
+
# @return [_IProxy] the <code>_IProxy</code> instance previously registered with the given <code>proxyName</code>.
|
21
|
+
def retrieve_proxy: (String proxy_name) -> _IProxy?
|
22
|
+
|
23
|
+
# Check if a <code>Proxy</code> is registered.
|
24
|
+
#
|
25
|
+
# @param proxy_name [String]
|
26
|
+
# @return [Boolean] whether a <code>Proxy</code> is currently registered with the given <code>proxyName</code>.
|
27
|
+
def has_proxy?: (String proxy_name) -> bool
|
28
|
+
|
29
|
+
# Remove an <code>_IProxy</code> instance from the <code>Model</code>.
|
30
|
+
#
|
31
|
+
# @param proxy_name [String] name of the <code>_IProxy</code> instance to be removed.
|
32
|
+
# @return [_IProxy | nil] the <code>_IProxy</code> that was removed from the <code>Model</code>.
|
33
|
+
def remove_proxy: (String proxy_name) -> _IProxy?
|
34
|
+
end
|
35
|
+
|
36
|
+
# Assert that the given `Model` type parameter is a subtype of `_IModel`
|
37
|
+
type validate_model[Model < _IModel] = top
|
38
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module PureMVC
|
2
|
+
# The interface definition for a PureMVC Notification.
|
3
|
+
#
|
4
|
+
# PureMVC does not rely upon underlying event models such
|
5
|
+
# as the one provided with Flash, and ActionScript 3 does
|
6
|
+
# not have an inherent event model.
|
7
|
+
#
|
8
|
+
# The Observer Pattern as implemented within PureMVC exists
|
9
|
+
# to support event-driven communication between the
|
10
|
+
# application and the actors of the MVC triad.
|
11
|
+
#
|
12
|
+
# Notifications are not meant to be a replacement for Events
|
13
|
+
# in Flex/Flash/AIR. Generally, <code>_IMediator</code> implementors
|
14
|
+
# place event listeners on their view components, which they
|
15
|
+
# then handle in the usual way. This may lead to the broadcast of <code>Notification</code>s to
|
16
|
+
# trigger <code>_ICommand</code>s or to communicate with other <code>_IMediators</code>.
|
17
|
+
# <code>_IProxy</code> and <code>_ICommand</code>
|
18
|
+
# instances communicate with each other and <code>_IMediator</code>s
|
19
|
+
# by broadcasting <code>_INotification</code>s.
|
20
|
+
#
|
21
|
+
# A key difference between Flash <code>Event</code>s and PureMVC
|
22
|
+
# <code>Notification</code>s is that <code>Event</code>s follow the
|
23
|
+
# 'Chain of Responsibility' pattern, 'bubbling' up the display hierarchy
|
24
|
+
# until some parent component handles the <code>Event</code>, while
|
25
|
+
# PureMVC <code>Notification</code>s follow a 'Publish/Subscribe'
|
26
|
+
# pattern. PureMVC classes need not be related to each other in a
|
27
|
+
# parent/child relationship to communicate with one another
|
28
|
+
# using <code>Notification</code>s.
|
29
|
+
#
|
30
|
+
# @see IView
|
31
|
+
# @see IObserver
|
32
|
+
interface _INotification
|
33
|
+
# @return [String] the name of the notification
|
34
|
+
def name: () -> String
|
35
|
+
|
36
|
+
# @return [Object, nil] the body of the notification
|
37
|
+
def body: () -> Object?
|
38
|
+
def body=: (Object?) -> void
|
39
|
+
|
40
|
+
# @return [String, nil] the type of the notification
|
41
|
+
def type: () -> String?
|
42
|
+
def type=: (String?) -> void
|
43
|
+
|
44
|
+
# Get the string representation of the <code>_INotification</code> instance
|
45
|
+
#
|
46
|
+
# @return [String]
|
47
|
+
def to_s: () -> String
|
48
|
+
end
|
49
|
+
|
50
|
+
# Assert that the given `Notification` type parameter is a subtype of `_INotification`
|
51
|
+
type validate_notification[Notification < _INotification] = top
|
52
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module PureMVC
|
2
|
+
# The interface definition for a PureMVC Notifier.
|
3
|
+
#
|
4
|
+
# <code>MacroCommand, Command, Mediator</code> and <code>Proxy</code>
|
5
|
+
# all have a need to send <code>Notifications</code>.
|
6
|
+
#
|
7
|
+
# The <code>_INotifier</code> interface provides a common method called
|
8
|
+
# <code>sendNotification</code> that relieves implementation code of
|
9
|
+
# the necessity to actually construct <code>Notifications</code>.
|
10
|
+
#
|
11
|
+
# The <code>Notifier</code> class, which all the above-mentioned classes
|
12
|
+
# extend, also provides an initialized reference to the <code>Facade</code>
|
13
|
+
# Singleton, which is required for the convenience method
|
14
|
+
# for sending <code>Notifications</code>, but also eases implementation as these
|
15
|
+
# classes have frequent <code>Facade</code> interactions and usually require
|
16
|
+
# access to the facade anyway.
|
17
|
+
#
|
18
|
+
# @see IFacade
|
19
|
+
# @see INotification
|
20
|
+
interface _INotifier
|
21
|
+
# Initialize this _INotifier instance.
|
22
|
+
#
|
23
|
+
# This is how a </code>Notifier</code> gets its multitonKey.
|
24
|
+
# Calls to <code>send_notification</code> or to access the
|
25
|
+
# facade will fail until after this method has been called.
|
26
|
+
#
|
27
|
+
# @param key [String] The multitonKey for this INotifier to use.
|
28
|
+
def initialize_notifier: (String key) -> void
|
29
|
+
|
30
|
+
# Send a <code>_INotification</code>.
|
31
|
+
#
|
32
|
+
# Convenience method to prevent having to construct new
|
33
|
+
# notification instances in our implementation code.
|
34
|
+
#
|
35
|
+
# @param name [String] The name of the notification to send.
|
36
|
+
# @param body [Object, nil] The body of the notification (optional).
|
37
|
+
# @param type [String, nil] The type of the notification (optional).
|
38
|
+
def send_notification: (String name, ?Object? body, ?String? type) -> void
|
39
|
+
|
40
|
+
# Return the Multiton Facade instance
|
41
|
+
#
|
42
|
+
# @raise [RuntimeError] if the <code>multiton_key</code> is not set
|
43
|
+
# @return [_IFacade] the facade instance for the notifier's key
|
44
|
+
def facade: () -> _IFacade
|
45
|
+
end
|
46
|
+
|
47
|
+
type validate_notifier[Notifier < _INotifier] = top
|
48
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module PureMVC
|
2
|
+
# The interface definition for a PureMVC Observer.
|
3
|
+
#
|
4
|
+
# In PureMVC, <code>_IObserver</code> implementors assume these responsibilities:
|
5
|
+
# - Encapsulate the notification (callback) method of the interested object.
|
6
|
+
# - Encapsulate the notification context (this) of the interested object.
|
7
|
+
# - Provide methods for setting the interested object's notification method and context.
|
8
|
+
# - Provide a method for notifying the interested object.
|
9
|
+
#
|
10
|
+
# PureMVC does not rely upon underlying event
|
11
|
+
# models such as the one provided with Flash,
|
12
|
+
# and ActionScript 3 does not have an inherent
|
13
|
+
# event model.
|
14
|
+
#
|
15
|
+
# The Observer Pattern as implemented within
|
16
|
+
# PureMVC exists to support event-driven communication
|
17
|
+
# between the application and the actors of the
|
18
|
+
# MVC triad.
|
19
|
+
#
|
20
|
+
# An Observer is an object that encapsulates information
|
21
|
+
# about an interested object with a notification method that
|
22
|
+
# should be called when an <code>_INotification</code> is broadcast. The Observer then
|
23
|
+
# acts as a proxy for notifying the interested object.
|
24
|
+
#
|
25
|
+
# Observers can receive <code>Notification</code>s by having their
|
26
|
+
# <code>notifyObserver</code> method invoked, passing
|
27
|
+
# in an object implementing the <code>_INotification</code> interface, such
|
28
|
+
# as a subclass of <code>Notification</code>.
|
29
|
+
#
|
30
|
+
# @see IView
|
31
|
+
# @see INotification
|
32
|
+
interface _IObserver
|
33
|
+
|
34
|
+
# @return [Method, nil] The callback method to be called on notification.
|
35
|
+
def notify: () -> Method?
|
36
|
+
def notify=: (Method?) -> void
|
37
|
+
|
38
|
+
# @return [Object, nil] The object context for the callback.
|
39
|
+
def context: () -> Object?
|
40
|
+
def context=: (Object?) -> void
|
41
|
+
|
42
|
+
# Notify the interested object.
|
43
|
+
#
|
44
|
+
# @param notification [_INotification] the <code>_INotification</code> to pass to the interested object's notification method
|
45
|
+
def notify_observer: (_INotification notification) -> void
|
46
|
+
|
47
|
+
# Compare the given object to the notification context object.
|
48
|
+
#
|
49
|
+
# @param object [Object] the object to compare.
|
50
|
+
# @return [Boolean] indicating if the notification context and the object are the same.
|
51
|
+
def compare_notify_context?: (Object object) -> bool
|
52
|
+
end
|
53
|
+
|
54
|
+
# Assert that the given `Observer` type parameter is a subtype of `_IObserver`
|
55
|
+
type validate_observer[Observer < _IObserver] = top
|
56
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module PureMVC
|
2
|
+
# The interface definition for a PureMVC Proxy.
|
3
|
+
#
|
4
|
+
# In PureMVC, <code>_IProxy</code> implementors assume these responsibilities:
|
5
|
+
# - Implement a common method which returns the name of the Proxy.
|
6
|
+
# - Provide methods for setting and getting the data object.
|
7
|
+
#
|
8
|
+
# Additionally, <code>_IProxy</code>s typically:
|
9
|
+
# - Maintain references to one or more pieces of model data.
|
10
|
+
# - Provide methods for manipulating that data.
|
11
|
+
# - Generate <code>_INotifications</code> when their model data changes.
|
12
|
+
# - Expose their name called <code>NAME</code>, if they are not instantiated multiple times.
|
13
|
+
# - Encapsulate interaction with local or remote services used to fetch and persist model data.
|
14
|
+
#
|
15
|
+
# @see INotifier
|
16
|
+
interface _IProxy
|
17
|
+
|
18
|
+
include _INotifier
|
19
|
+
|
20
|
+
# @return [String] The proxy name
|
21
|
+
def name: () -> String
|
22
|
+
|
23
|
+
# @return [Object | nil] The data managed by the proxy
|
24
|
+
def data: () -> Object?
|
25
|
+
def data=: (Object?) -> void
|
26
|
+
|
27
|
+
# Called by the Model when the Proxy is registered
|
28
|
+
def on_register: () -> void
|
29
|
+
|
30
|
+
# Called by the Model when the Proxy is removed
|
31
|
+
def on_remove: () -> void
|
32
|
+
end
|
33
|
+
|
34
|
+
# Assert that the given `Proxy` type parameter is a subtype of `_IProxy`
|
35
|
+
type validate_proxy[Proxy < _IProxy] = top
|
36
|
+
end
|