puremvc 1.0.0 → 1.0.2
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 +15 -0
- data/LICENSE +28 -0
- data/README.md +88 -0
- data/sig/core/controller.rbs +40 -0
- data/sig/core/model.rbs +38 -0
- data/sig/core/view.rbs +42 -0
- data/sig/interfaces/i_command.rbs +18 -0
- data/sig/interfaces/i_controller.rbs +52 -0
- data/sig/interfaces/i_facade.rbs +116 -0
- data/sig/interfaces/i_mediator.rbs +60 -0
- data/sig/interfaces/i_model.rbs +38 -0
- data/sig/interfaces/i_notification.rbs +52 -0
- data/sig/interfaces/i_notifier.rbs +48 -0
- data/sig/interfaces/i_observer.rbs +56 -0
- data/sig/interfaces/i_proxy.rbs +36 -0
- data/sig/interfaces/i_view.rbs +71 -0
- data/sig/patterns/command/macro_command.rbs +18 -0
- data/sig/patterns/command/simple_command.rbs +11 -0
- data/sig/patterns/facade/facade.rbs +48 -0
- data/sig/patterns/mediator/mediator.rbs +18 -0
- data/sig/patterns/observer/notification.rbs +18 -0
- data/sig/patterns/observer/notifier.rbs +17 -0
- data/sig/patterns/observer/observer.rbs +20 -0
- data/sig/patterns/proxy/proxy.rbs +19 -0
- data/src/core/controller.rb +177 -0
- data/src/core/model.rb +133 -0
- data/src/core/view.rb +230 -0
- data/src/patterns/command/macro_command.rb +81 -0
- data/src/patterns/command/simple_command.rb +28 -0
- data/src/patterns/facade/facade.rb +267 -0
- data/src/patterns/mediator/mediator.rb +56 -0
- data/src/patterns/observer/notification.rb +68 -0
- data/src/patterns/observer/notifier.rb +87 -0
- data/src/patterns/observer/observer.rb +55 -0
- data/src/patterns/proxy/proxy.rb +50 -0
- data/src/puremvc.rb +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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 26e147a6639ad6b8e4143b15143b5612a47a0b87bd658d4eb9777702482ccf9d
|
4
|
+
data.tar.gz: d2c91173162c28ab377facb590c02fe2f7bff293cd23967ffdd5cbdc3c4adf44
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 10b4b062f5759403f465ddf24f3070c80b09d895181ebd161d624aa1cf4b43d6297c9a7edb26fde3f8edbdb60d3500ac715f1ddec10c9e27a46230db933085e9
|
7
|
+
data.tar.gz: 87da5a1fc550e1954b7c2da6abe9add951878414bde033d880650a1431bf31638010fbf676a5174d2303f31c26a658abae62d86b0ae99e348162e6ce39fd1a87
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
## [1.0.2] - 2025-08-14
|
6
|
+
### Changed
|
7
|
+
- Updated structure
|
8
|
+
|
9
|
+
## [1.0.1] - 2025-08-14
|
10
|
+
### Changed
|
11
|
+
- Bumped version to 1.0.1 to allow Multicore override after initial 1.0.0 standard release on rubygems.org
|
12
|
+
|
13
|
+
## [1.0.0] - 2025-08-14
|
14
|
+
### Added
|
15
|
+
- Initial release of the framework
|
data/LICENSE
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
BSD 3-Clause License
|
2
|
+
|
3
|
+
Copyright (c) 2025, Saad Shams <saad.shams@puremvc.org>
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
7
|
+
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
9
|
+
list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
13
|
+
and/or other materials provided with the distribution.
|
14
|
+
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
16
|
+
contributors may be used to endorse or promote products derived from
|
17
|
+
this software without specific prior written permission.
|
18
|
+
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
## [PureMVC](http://puremvc.github.com/) Ruby MultiCore Framework [](https://github.com/PureMVC/puremvc-ruby-multicore-framework/actions/workflows/ruby.yml)
|
2
|
+
|
3
|
+
PureMVC is a lightweight framework for creating applications based upon the classic [Model-View-Controller](http://en.wikipedia.org/wiki/Model-view-controller) design meta-pattern. It supports [modular programming](http://en.wikipedia.org/wiki/Modular_programming) through the use of [Multiton](http://en.wikipedia.org/wiki/Multiton) Core actors instead of the [Singletons](http://en.wikipedia.org/wiki/Singleton_pattern) used in the [Standard](https://github.com/PureMVC/puremvc-ruby-standard-framework/wiki) Version.
|
4
|
+
|
5
|
+
* [Ruby Gem](https://rubygems.org/gems/puremvc)
|
6
|
+
* [API Docs](http://puremvc.org/pages/docs/Ruby/multicore/)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
```shell
|
10
|
+
gem install puremvc
|
11
|
+
```
|
12
|
+
|
13
|
+
## Platforms / Technologies
|
14
|
+
* [Ruby](https://en.wikipedia.org/wiki/Ruby_(programming_language))
|
15
|
+
* [Command-line interface](https://en.wikipedia.org/wiki/Command-line_interface)
|
16
|
+
* [Cross-platform software](https://en.wikipedia.org/wiki/Cross-platform_software)
|
17
|
+
|
18
|
+
---
|
19
|
+
## Development
|
20
|
+
|
21
|
+
### Install Dependencies
|
22
|
+
```shell
|
23
|
+
bundle install
|
24
|
+
```
|
25
|
+
|
26
|
+
### Lint Code
|
27
|
+
```shell
|
28
|
+
bundle exec rubocop
|
29
|
+
```
|
30
|
+
|
31
|
+
### Generate RBS Signatures
|
32
|
+
```shell
|
33
|
+
rbs prototype rb src/**/*.rb --out-dir=sig
|
34
|
+
```
|
35
|
+
|
36
|
+
### Run Type Checking
|
37
|
+
```shell
|
38
|
+
steep check
|
39
|
+
```
|
40
|
+
|
41
|
+
### Test
|
42
|
+
```shell
|
43
|
+
ruby -Itest -e 'Dir["test/**/*_test.rb"].each { |file| require_relative file }'
|
44
|
+
RubyMine: Test file name mask: **/{*_test,test_*,*_spec}.rb
|
45
|
+
```
|
46
|
+
|
47
|
+
### Generate Documentation
|
48
|
+
```shell
|
49
|
+
yard doc src/**/*.rb --protected --private
|
50
|
+
open doc/index.html
|
51
|
+
```
|
52
|
+
|
53
|
+
#### Publish
|
54
|
+
##### 1. Setup RubyGems API Key
|
55
|
+
```shell
|
56
|
+
mkdir -p ~/.gem
|
57
|
+
cat > ~/.gem/credentials <<EOF
|
58
|
+
---
|
59
|
+
:rubygems_api_key: API_KEY
|
60
|
+
EOF
|
61
|
+
chmod 0600 ~/.gem/credentials
|
62
|
+
```
|
63
|
+
##### 2. Build the gem
|
64
|
+
```shell
|
65
|
+
gem build puremvc.gemspec
|
66
|
+
gem push puremvc-1.0.0.gem
|
67
|
+
```
|
68
|
+
|
69
|
+
## Reference
|
70
|
+
* [Ruby](https://www.ruby-lang.org/en)
|
71
|
+
* [RBS](https://github.com/ruby/rbs)
|
72
|
+
* [YARD: Yay! A Ruby Documentation Tool](https://rubydoc.info/gems/yard)
|
73
|
+
|
74
|
+
---
|
75
|
+
|
76
|
+
## License
|
77
|
+
* PureMVC MultiCore Framework for Ruby
|
78
|
+
* PureMVC - Copyright © 2025 [Saad Shams](https://www.linkedin.com/in/muizz/)
|
79
|
+
* PureMVC - Copyright © 2025 [Futurescale, Inc.](http://futurescale.com/)
|
80
|
+
* All rights reserved.
|
81
|
+
|
82
|
+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
83
|
+
|
84
|
+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
85
|
+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
86
|
+
* Neither the name of Futurescale, Inc., PureMVC.org, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
87
|
+
|
88
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@@ -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
|
data/sig/core/model.rbs
ADDED
@@ -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
|
data/sig/core/view.rbs
ADDED
@@ -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
|