├── LICENSE ├── README.md ├── VERSION ├── asdoc ├── all-classes.html ├── all-index-A.html ├── all-index-B.html ├── all-index-C.html ├── all-index-D.html ├── all-index-E.html ├── all-index-F.html ├── all-index-G.html ├── all-index-H.html ├── all-index-I.html ├── all-index-J.html ├── all-index-K.html ├── all-index-L.html ├── all-index-M.html ├── all-index-N.html ├── all-index-O.html ├── all-index-P.html ├── all-index-Q.html ├── all-index-R.html ├── all-index-S.html ├── all-index-T.html ├── all-index-U.html ├── all-index-V.html ├── all-index-W.html ├── all-index-X.html ├── all-index-Y.html ├── all-index-Z.html ├── appendixes.html ├── asdoc.js ├── class-summary.html ├── cookies.js ├── images │ ├── collapsed.gif │ ├── detailHeaderRule.jpg │ ├── detailSectionHeader.jpg │ ├── expanded.gif │ ├── inherit-arrow.gif │ ├── inheritedSummary.gif │ ├── logo.jpg │ ├── titleTableBottom.jpg │ ├── titleTableMiddle.jpg │ └── titleTableTop.jpg ├── index-list.html ├── index.html ├── mxml-tags.html ├── org │ └── puremvc │ │ └── as3 │ │ ├── core │ │ ├── Controller.html │ │ ├── Model.html │ │ ├── View.html │ │ ├── class-list.html │ │ └── package-detail.html │ │ ├── interfaces │ │ ├── ICommand.html │ │ ├── IController.html │ │ ├── IFacade.html │ │ ├── IMediator.html │ │ ├── IModel.html │ │ ├── INotification.html │ │ ├── INotifier.html │ │ ├── IObserver.html │ │ ├── IProxy.html │ │ ├── IView.html │ │ ├── class-list.html │ │ └── package-detail.html │ │ └── patterns │ │ ├── command │ │ ├── MacroCommand.html │ │ ├── SimpleCommand.html │ │ ├── class-list.html │ │ └── package-detail.html │ │ ├── facade │ │ ├── Facade.html │ │ ├── class-list.html │ │ └── package-detail.html │ │ ├── mediator │ │ ├── Mediator.html │ │ ├── class-list.html │ │ └── package-detail.html │ │ ├── observer │ │ ├── Notification.html │ │ ├── Notifier.html │ │ ├── Observer.html │ │ ├── class-list.html │ │ └── package-detail.html │ │ └── proxy │ │ ├── Proxy.html │ │ ├── class-list.html │ │ └── package-detail.html ├── package-frame.html ├── package-list.html ├── package-summary.html ├── print.css ├── style.css └── title-bar.html ├── bin └── PureMVC_AS3_2_0_4.swc └── src ├── org └── puremvc │ └── as3 │ ├── core │ ├── Controller.as │ ├── Model.as │ └── View.as │ ├── interfaces │ ├── ICommand.as │ ├── IController.as │ ├── IFacade.as │ ├── IMediator.as │ ├── IModel.as │ ├── INotification.as │ ├── INotifier.as │ ├── IObserver.as │ ├── IProxy.as │ └── IView.as │ └── patterns │ ├── command │ ├── MacroCommand.as │ └── SimpleCommand.as │ ├── facade │ └── Facade.as │ ├── mediator │ └── Mediator.as │ ├── observer │ ├── Notification.as │ ├── Notifier.as │ └── Observer.as │ └── proxy │ └── Proxy.as └── puremvc-manifest.xml /LICENSE: -------------------------------------------------------------------------------- 1 | * PureMVC AS3 Standard Framework - Copyright © 2006-2012 Futurescale, Inc. 2 | * All rights reserved. 3 | 4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | * 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. 8 | * 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. 9 | 10 | 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. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## [PureMVC](http://puremvc.github.com/) ActionScript 3 Standard Framework 2 | 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. This is the specific implementation for the AS3 language, and the reference implementation for [all other PureMVC Ports](http://puremvc.github.com/). It does not support [modular programming](http://en.wikipedia.org/wiki/Modular_programming) since it uses [Singleton](http://en.wikipedia.org/wiki/Singleton_pattern)s as Core actors rather than the [Multiton](http://en.wikipedia.org/wiki/Multiton)s used in the [MultiCore](https://github.com/PureMVC/puremvc-as3-multicore-framework/wiki/) Version. 3 | 4 | * [API Docs](http://puremvc.org/pages/docs/AS3/standard/framework_asdoc/) 5 | * [Unit Tests](https://github.com/PureMVC/puremvc-as3-standard-unittests/wiki) 6 | * [Discussion](http://forums.puremvc.org/index.php?board=26.0) 7 | * [Standard Version Overview Presentation](http://puremvc.tv/#P100) 8 | * [ActionScript Developer's Guide to PureMVC (O'Reilly)](http://oreil.ly/puremvc) 9 | 10 | ## Demos 11 | * For FLEX 12 | * [App Skeleton](https://github.com/PureMVC/puremvc-as3-demo-flex-appskeleton/wiki) 13 | * [Bookstore](https://github.com/PureMVC/puremvc-as3-demo-flex-weborb-bookstore/wiki) 14 | * [Cafe Townsend](https://github.com/PureMVC/puremvc-as3-demo-flex-cafetownsend/wiki) 15 | * [Employee Admin](https://github.com/PureMVC/puremvc-as3-demo-flex-employeeadmin/wiki) 16 | * [File Upload](https://github.com/PureMVC/puremvc-as3-demo-flex-cf-fileupload/wiki) 17 | * [History Panel](https://github.com/PureMVC/puremvc-as3-demo-flex-historypanel/wiki) 18 | * [Index Cards](https://github.com/PureMVC/puremvc-as3-demo-flex-rails-indexcards/wiki) 19 | * [Loadup as Ordered](https://github.com/PureMVC/puremvc-as3-demo-flex-loadupasordered/wiki) 20 | * [Loadup for Assets](https://github.com/PureMVC/puremvc-as3-demo-flex-loadupforassets/wiki) 21 | * [Manifold Roamer](https://github.com/PureMVC/puremvc-as3-demo-flex-manifoldroamer/wiki) 22 | * [Login](https://github.com/PureMVC/puremvc-as3-demo-flex-weborb-login/wiki) 23 | * [Slacker](https://github.com/PureMVC/puremvc-as3-demo-flex-slacker/wiki) 24 | * [Query CFC](https://github.com/PureMVC/puremvc-as3-demo-flex-cf-querycfc/wiki) 25 | * [StopWatch](https://github.com/PureMVC/puremvc-as3-demo-flex-stopwatch/wiki) 26 | * For AIR 27 | * [CodePeek](https://github.com/PureMVC/puremvc-as3-demo-air-codepeek/wiki) 28 | * [HelloPlaybook](https://github.com/PureMVC/puremvc-as3-demo-air-helloplaybook/wiki) 29 | * [RSS Headlines](https://github.com/PureMVC/puremvc-as3-demo-air-rssheadlines/wiki) 30 | * For FLASH 31 | * [Hello Flash](https://github.com/PureMVC/puremvc-as3-demo-flash-helloflash/wiki) 32 | * [Sequential](https://github.com/PureMVC/puremvc-as3-demo-flash-sequential/wiki) 33 | 34 | ## Utilities 35 | * For FLEX, FLASH, or AIR 36 | * [Async Command](https://github.com/PureMVC/puremvc-as3-util-asynccommand/wiki) 37 | * [Async Stub](https://github.com/PureMVC/puremvc-as3-util-asyncstub/wiki) 38 | * [Loadup](https://github.com/PureMVC/puremvc-as3-util-loadup/wiki) 39 | * [State Machine](https://github.com/PureMVC/puremvc-as3-util-statemachine/wiki) 40 | * [Undo](https://github.com/PureMVC/puremvc-as3-util-undo/wiki) 41 | * For FLEX or AIR 42 | * [Deployment Config](https://github.com/PureMVC/puremvc-as3-util-flex-deploymentconfig/wiki) 43 | * For AIR 44 | * [Desktop Citizen](https://github.com/PureMVC/puremvc-as3-util-air-desktopcitizen/wiki) 45 | * [XML Database](https://github.com/PureMVC/puremvc-as3-util-air-xmldatabase/wiki) 46 | 47 | ## Status 48 | Production - [Version 2.0.4](https://github.com/PureMVC/puremvc-as3-standard-framework/blob/master/VERSION) 49 | 50 | ## Platforms / Technologies 51 | * [ActionScript 3](http://en.wikipedia.org/wiki/ActionScript) 52 | * [Flex](http://en.wikipedia.org/wiki/Adobe_flash) 53 | * [Flash](http://en.wikipedia.org/wiki/Adobe_Flex) 54 | * [AIR](http://en.wikipedia.org/wiki/Adobe_Air) 55 | 56 | ## License 57 | * PureMVC AS3 Standard Framework - Copyright © 2006-2012 Futurescale, Inc. 58 | * All rights reserved. 59 | 60 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 61 | 62 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 63 | * 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. 64 | * 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. 65 | 66 | 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. 67 | -------------------------------------------------------------------------------- /asdoc/all-classes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |Controller | 17 |
Facade | 20 |
ICommand | 23 |
IController | 26 |
IFacade | 29 |
IMediator | 32 |
IModel | 35 |
INotification | 38 |
INotifier | 41 |
IObserver | 44 |
IProxy | 47 |
IView | 50 |
MacroCommand | 53 |
Mediator | 56 |
Model | 59 |
Notification | 62 |
Notifier | 65 |
Observer | 68 |
Proxy | 71 |
SimpleCommand | 74 |
View | 77 |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | 36 ||
39 | | |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | 42 |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | 36 ||
39 | | |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | 42 |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | 36 ||
39 | | |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | 42 |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | 36 ||
39 | | |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | 42 |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | 36 ||
39 | | |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | 42 |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | 36 ||
39 | | |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | 42 |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | 36 ||
39 | | |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | 42 |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | 36 ||
39 | | |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | 42 |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | 36 ||
39 | | |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | 42 |
Appendix | Description | 37 |
---|
A | 27 |N | 28 | 29 |
B | 34 |O | 35 | 36 |
C | 41 |P | 42 | 43 |
D | 48 |Q | 49 | 50 |
E | 55 |R | 56 | 57 |
F | 62 |S | 63 | 64 |
G | 69 |T | 70 | 71 |
H | 76 |U | 77 | 78 |
I | 83 |V | 84 | 85 |
J | 90 |W | 91 | 92 |
K | 97 |X | 98 | 99 |
L | 104 |Y | 105 | 106 |
M | 111 |Z | 112 | 113 |
Classes | 17 |
Controller | 20 |
Model | 23 |
View | 26 |
Class | Description | 40 ||
---|---|---|
Controller |
43 | A Singleton IController implementation. |
44 | |
Model |
47 | A Singleton IModel implementation. |
48 | |
View |
51 | A Singleton IView implementation. |
52 |
Package | org.puremvc.as3.interfaces | 36 |
Interface | public interface ICommand | 39 |
Implementors | MacroCommand, SimpleCommand | 42 |
48 | See also 49 |
50 |Method | Defined by | 62 |||
---|---|---|---|
65 |
66 | execute(notification:INotification):void
67 |
68 | Execute the
69 | ICommand 's logic to handle a given INotification . | ICommand | 70 |
execute | () | method | 84 |
public function execute(notification:INotification):void
88 | Execute the ICommand
's logic to handle a given INotification
.
89 |
90 |
notification:INotification — an INotification to handle.
94 | |
95 |
Package | org.puremvc.as3.interfaces | 36 |
Interface | public interface INotifier | 39 |
Subinterfaces | IFacade | 42 |
Implementors | MacroCommand, Mediator, Notifier, Proxy, SimpleCommand | 45 |
51 | MacroCommand, Command, Mediator
and Proxy
52 | all have a need to send Notifications
.
55 | The INotifier
interface provides a common method called
56 | sendNotification
that relieves implementation code of
57 | the necessity to actually construct Notifications
.
60 | The Notifier
class, which all of the above mentioned classes
61 | extend, also provides an initialized reference to the Facade
62 | Singleton, which is required for the convienience method
63 | for sending Notifications
, but also eases implementation as these
64 | classes have frequent Facade
interactions and usually require
65 | access to the facade anyway.
69 | See also 70 |
71 | 76 |Method | Defined by | 85 |||
---|---|---|---|
88 |
89 | sendNotification(notificationName:String, body:Object = null, type:String = null):void
90 |
91 | Send a
92 | INotification . | INotifier | 93 |
sendNotification | () | method | 107 |
public function sendNotification(notificationName:String, body:Object = null, type:String = null):void
111 | Send a INotification
.
112 |
113 |
114 | Convenience method to prevent having to construct new 115 | notification instances in our implementation code.
116 | 117 | Parameters 118 |notificationName:String — the name of the notification to send
121 | |
122 | |
125 | | |
body:Object (default = null ) — the body of the notification (optional)
128 | |
129 | |
132 | | |
type:String (default = null ) — the type of the notification (optional)
135 | |
136 |
Interfaces | 17 |
ICommand | 20 |
IController | 23 |
IFacade | 26 |
IMediator | 29 |
IModel | 32 |
INotification | 35 |
INotifier | 38 |
IObserver | 41 |
IProxy | 44 |
IView | 47 |
50 | |
Interface | Description | 40 ||
---|---|---|
ICommand | 43 | The interface definition for a PureMVC Command. | 44 ||
IController | 47 | The interface definition for a PureMVC Controller. | 48 ||
IFacade | 51 | The interface definition for a PureMVC Facade. | 52 ||
IMediator | 55 | The interface definition for a PureMVC Mediator. | 56 ||
IModel | 59 | The interface definition for a PureMVC Model. | 60 ||
INotification | 63 | The interface definition for a PureMVC Notification. | 64 ||
INotifier | 67 | The interface definition for a PureMVC Notifier. | 68 ||
IObserver | 71 | The interface definition for a PureMVC Observer. | 72 ||
IProxy | 75 | The interface definition for a PureMVC Proxy. | 76 ||
IView | 79 | The interface definition for a PureMVC View. | 80 |
Classes | 17 |
MacroCommand | 20 |
SimpleCommand | 23 |
Class | Description | 40 ||
---|---|---|
MacroCommand |
43 | A base ICommand implementation that executes other ICommand s. |
44 | |
SimpleCommand |
47 | A base ICommand implementation. |
48 |
Classes | 17 |
Facade | 20 |
Class | Description | 40 ||
---|---|---|
Facade |
43 | A base Singleton IFacade implementation. |
44 |
Classes | 17 |
Mediator | 20 |
Class | Description | 40 ||
---|---|---|
Mediator |
43 | A base IMediator implementation. |
44 |
Classes | 17 |
Notification | 20 |
Notifier | 23 |
Observer | 26 |
Class | Description | 40 ||
---|---|---|
Notification |
43 | A base INotification implementation. |
44 | |
Notifier |
47 | A Base INotifier implementation. |
48 | |
Observer |
51 | A base IObserver implementation. |
52 |
Classes | 17 |
Proxy | 20 |
Class | Description | 40 ||
---|---|---|
Proxy |
43 | A base IProxy implementation. |
44 |
This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client.
24 |
25 | Link toNon-frame version.
26 |
27 |
org.puremvc.as3.core
18 | 19 | |
20 |
org.puremvc.as3.interfaces
23 | 24 | |
25 |
org.puremvc.as3.patterns.command
28 | 29 | |
30 |
org.puremvc.as3.patterns.facade
33 | 34 | |
35 |
org.puremvc.as3.patterns.mediator
38 | 39 | |
40 |
org.puremvc.as3.patterns.observer
43 | 44 | |
45 |
org.puremvc.as3.patterns.proxy | 48 |
Package | Description | 37 ||
---|---|---|
org.puremvc.as3.core | 40 | | |
org.puremvc.as3.interfaces | 43 | | |
org.puremvc.as3.patterns.command | 46 | | |
org.puremvc.as3.patterns.facade | 49 | | |
org.puremvc.as3.patterns.mediator | 52 | | |
org.puremvc.as3.patterns.observer | 55 | | |
org.puremvc.as3.patterns.proxy | 58 | |
PureMVC AS3 Framework - [Standard Version] | 25 |26 | All Packages | All Classes | Index | No Frames 27 | | 28 | 29 |30 | 31 | | 32 | 33 |
38 | | 39 | | 41 | 42 | 40 ||
47 | 48 | |
IController
implementation.
13 | *
14 | *
15 | * In PureMVC, the Controller
class follows the
16 | * 'Command and Controller' strategy, and assumes these
17 | * responsibilities:
18 | *
ICommand
s
20 | * are intended to handle which INotifications
.IObserver
with
22 | * the View
for each INotification
23 | * that it has an ICommand
mapping for.ICommand
25 | * to handle a given INotification
when notified by the View
.ICommand
's execute
27 | * method, passing in the INotification
.
31 | * Your application must register ICommands
with the
32 | * Controller.
33 | *
34 | * The simplest way is to subclass Facade,
35 | * and use its initializeController
method to add your
36 | * registrations.
37 | *
38 | * @see org.puremvc.as3.core.view.View View
39 | * @see org.puremvc.as3.patterns.observer.Observer Observer
40 | * @see org.puremvc.as3.patterns.observer.Notification Notification
41 | * @see org.puremvc.as3.patterns.command.SimpleCommand SimpleCommand
42 | * @see org.puremvc.as3.patterns.command.MacroCommand MacroCommand
43 | */
44 | public class Controller implements IController
45 | {
46 |
47 | /**
48 | * Constructor.
49 | *
50 | *
51 | * This IController
implementation is a Singleton,
52 | * so you should not call the constructor
53 | * directly, but instead call the static Singleton
54 | * Factory method Controller.getInstance()
55 | *
56 | * @throws Error Error if Singleton instance has already been constructed
57 | *
58 | */
59 | public function Controller( )
60 | {
61 | if (instance != null) throw Error(SINGLETON_MSG);
62 | instance = this;
63 | commandMap = new Array();
64 | initializeController();
65 | }
66 |
67 | /**
68 | * Initialize the Singleton Controller
instance.
69 | *
70 | *
Called automatically by the constructor.
71 | * 72 | *Note that if you are using a subclass of View
73 | * in your application, you should also subclass Controller
74 | * and override the initializeController
method in the
75 | * following way:
Controller
Singleton Factory method.
94 | *
95 | * @return the Singleton instance of Controller
96 | */
97 | public static function getInstance() : IController
98 | {
99 | if ( instance == null ) instance = new Controller( );
100 | return instance;
101 | }
102 |
103 | /**
104 | * If an ICommand
has previously been registered
105 | * to handle a the given INotification
, then it is executed.
106 | *
107 | * @param note an INotification
108 | */
109 | public function executeCommand( note : INotification ) : void
110 | {
111 | var commandClassRef : Class = commandMap[ note.getName() ];
112 | if ( commandClassRef == null ) return;
113 |
114 | var commandInstance : ICommand = new commandClassRef();
115 | commandInstance.execute( note );
116 | }
117 |
118 | /**
119 | * Register a particular ICommand
class as the handler
120 | * for a particular INotification
.
121 | *
122 | *
123 | * If an ICommand
has already been registered to
124 | * handle INotification
s with this name, it is no longer
125 | * used, the new ICommand
is used instead.
INotification
131 | * @param commandClassRef the Class
of the ICommand
132 | */
133 | public function registerCommand( notificationName : String, commandClassRef : Class ) : void
134 | {
135 | if ( commandMap[ notificationName ] == null ) {
136 | view.registerObserver( notificationName, new Observer( executeCommand, this ) );
137 | }
138 | commandMap[ notificationName ] = commandClassRef;
139 | }
140 |
141 | /**
142 | * Check if a Command is registered for a given Notification
143 | *
144 | * @param notificationName
145 | * @return whether a Command is currently registered for the given notificationName
.
146 | */
147 | public function hasCommand( notificationName:String ) : Boolean
148 | {
149 | return commandMap[ notificationName ] != null;
150 | }
151 |
152 | /**
153 | * Remove a previously registered ICommand
to INotification
mapping.
154 | *
155 | * @param notificationName the name of the INotification
to remove the ICommand
mapping for
156 | */
157 | public function removeCommand( notificationName : String ) : void
158 | {
159 | // if the Command is registered...
160 | if ( hasCommand( notificationName ) )
161 | {
162 | // remove the observer
163 | view.removeObserver( notificationName, this );
164 |
165 | // remove the command
166 | commandMap[ notificationName ] = null;
167 | }
168 | }
169 |
170 | // Local reference to View
171 | protected var view : IView;
172 |
173 | // Mapping of Notification names to Command Class references
174 | protected var commandMap : Array;
175 |
176 | // Singleton instance
177 | protected static var instance : IController;
178 |
179 | // Message Constants
180 | protected const SINGLETON_MSG : String = "Controller Singleton already constructed!";
181 |
182 | }
183 | }
--------------------------------------------------------------------------------
/src/org/puremvc/as3/core/Model.as:
--------------------------------------------------------------------------------
1 | /*
2 | PureMVC - Copyright(c) 2006-08 Futurescale, Inc., Some rights reserved.
3 | Your reuse is governed by the Creative Commons Attribution 3.0 United States License
4 | */
5 | package org.puremvc.as3.core
6 | {
7 |
8 | import org.puremvc.as3.interfaces.*;
9 |
10 | /**
11 | * A Singleton IModel
implementation.
12 | *
13 | *
14 | * In PureMVC, the Model
class provides
15 | * access to model objects (Proxies) by named lookup.
16 | *
17 | *
18 | * The Model
assumes these responsibilities:
IProxy
instances.IProxy
instances.
27 | * Your application must register IProxy
instances
28 | * with the Model
. Typically, you use an
29 | * ICommand
to create and register IProxy
30 | * instances once the Facade
has initialized the Core
31 | * actors.
42 | * This IModel
implementation is a Singleton,
43 | * so you should not call the constructor
44 | * directly, but instead call the static Singleton
45 | * Factory method Model.getInstance()
46 | *
47 | * @throws Error Error if Singleton instance has already been constructed
48 | *
49 | */
50 | public function Model( )
51 | {
52 | if (instance != null) throw Error(SINGLETON_MSG);
53 | instance = this;
54 | proxyMap = new Array();
55 | initializeModel();
56 | }
57 |
58 | /**
59 | * Initialize the Singleton Model
instance.
60 | *
61 | *
62 | * Called automatically by the constructor, this 63 | * is your opportunity to initialize the Singleton 64 | * instance in your subclass without overriding the 65 | * constructor.
66 | * 67 | * @return void 68 | */ 69 | protected function initializeModel( ) : void 70 | { 71 | } 72 | 73 | /** 74 | *Model
Singleton Factory method.
75 | *
76 | * @return the Singleton instance
77 | */
78 | public static function getInstance() : IModel
79 | {
80 | if (instance == null) instance = new Model( );
81 | return instance;
82 | }
83 |
84 | /**
85 | * Register an IProxy
with the Model
.
86 | *
87 | * @param proxy an IProxy
to be held by the Model
.
88 | */
89 | public function registerProxy( proxy:IProxy ) : void
90 | {
91 | proxyMap[ proxy.getProxyName() ] = proxy;
92 | proxy.onRegister();
93 | }
94 |
95 | /**
96 | * Retrieve an IProxy
from the Model
.
97 | *
98 | * @param proxyName
99 | * @return the IProxy
instance previously registered with the given proxyName
.
100 | */
101 | public function retrieveProxy( proxyName:String ) : IProxy
102 | {
103 | return proxyMap[ proxyName ];
104 | }
105 |
106 | /**
107 | * Check if a Proxy is registered
108 | *
109 | * @param proxyName
110 | * @return whether a Proxy is currently registered with the given proxyName
.
111 | */
112 | public function hasProxy( proxyName:String ) : Boolean
113 | {
114 | return proxyMap[ proxyName ] != null;
115 | }
116 |
117 | /**
118 | * Remove an IProxy
from the Model
.
119 | *
120 | * @param proxyName name of the IProxy
instance to be removed.
121 | * @return the IProxy
that was removed from the Model
122 | */
123 | public function removeProxy( proxyName:String ) : IProxy
124 | {
125 | var proxy:IProxy = proxyMap [ proxyName ] as IProxy;
126 | if ( proxy )
127 | {
128 | proxyMap[ proxyName ] = null;
129 | proxy.onRemove();
130 | }
131 | return proxy;
132 | }
133 |
134 | // Mapping of proxyNames to IProxy instances
135 | protected var proxyMap : Array;
136 |
137 | // Singleton instance
138 | protected static var instance : IModel;
139 |
140 | // Message Constants
141 | protected const SINGLETON_MSG : String = "Model Singleton already constructed!";
142 |
143 | }
144 | }
--------------------------------------------------------------------------------
/src/org/puremvc/as3/interfaces/ICommand.as:
--------------------------------------------------------------------------------
1 | /*
2 | PureMVC - Copyright(c) 2006-08 Futurescale, Inc., Some rights reserved.
3 | Your reuse is governed by the Creative Commons Attribution 3.0 United States License
4 | */
5 | package org.puremvc.as3.interfaces
6 | {
7 | /**
8 | * The interface definition for a PureMVC Command.
9 | *
10 | * @see org.puremvc.as3.interfaces INotification
11 | */
12 | public interface ICommand
13 | {
14 | /**
15 | * Execute the ICommand
's logic to handle a given INotification
.
16 | *
17 | * @param note an INotification
to handle.
18 | */
19 | function execute( notification:INotification ) : void;
20 | }
21 | }
--------------------------------------------------------------------------------
/src/org/puremvc/as3/interfaces/IController.as:
--------------------------------------------------------------------------------
1 | /*
2 | PureMVC - Copyright(c) 2006-08 Futurescale, Inc., Some rights reserved.
3 | Your reuse is governed by the Creative Commons Attribution 3.0 United States License
4 | */
5 | package org.puremvc.as3.interfaces
6 | {
7 | /**
8 | * The interface definition for a PureMVC Controller.
9 | *
10 | *
11 | * In PureMVC, an IController
implementor
12 | * follows the 'Command and Controller' strategy, and
13 | * assumes these responsibilities:
14 | *
ICommand
s
16 | * are intended to handle which INotifications
.IObserver
with
18 | * the View
for each INotification
19 | * that it has an ICommand
mapping for.ICommand
21 | * to handle a given INotification
when notified by the View
.ICommand
's execute
23 | * method, passing in the INotification
.ICommand
class as the handler
34 | * for a particular INotification
.
35 | *
36 | * @param notificationName the name of the INotification
37 | * @param commandClassRef the Class of the ICommand
38 | */
39 | function registerCommand( notificationName : String, commandClassRef : Class ) : void;
40 |
41 | /**
42 | * Execute the ICommand
previously registered as the
43 | * handler for INotification
s with the given notification name.
44 | *
45 | * @param notification the INotification
to execute the associated ICommand
for
46 | */
47 | function executeCommand( notification : INotification ) : void;
48 |
49 | /**
50 | * Remove a previously registered ICommand
to INotification
mapping.
51 | *
52 | * @param notificationName the name of the INotification
to remove the ICommand
mapping for
53 | */
54 | function removeCommand( notificationName : String ):void;
55 |
56 | /**
57 | * Check if a Command is registered for a given Notification
58 | *
59 | * @param notificationName
60 | * @return whether a Command is currently registered for the given notificationName
.
61 | */
62 | function hasCommand( notificationName:String ) : Boolean;
63 | }
64 | }
--------------------------------------------------------------------------------
/src/org/puremvc/as3/interfaces/IFacade.as:
--------------------------------------------------------------------------------
1 | /*
2 | PureMVC - Copyright(c) 2006-08 Futurescale, Inc., Some rights reserved.
3 | Your reuse is governed by the Creative Commons Attribution 3.0 United States License
4 | */
5 | package org.puremvc.as3.interfaces
6 | {
7 |
8 | /**
9 | * The interface definition for a PureMVC Facade.
10 | *
11 | * 12 | * The Facade Pattern suggests providing a single 13 | * class to act as a central point of communication 14 | * for a subsystem.
15 | * 16 | *17 | * In PureMVC, the Facade acts as an interface between 18 | * the core MVC actors (Model, View, Controller) and 19 | * the rest of your application.
20 | * 21 | * @see org.puremvc.as3.interfaces.IModel IModel 22 | * @see org.puremvc.as3.interfaces.IView IView 23 | * @see org.puremvc.as3.interfaces.IController IController 24 | * @see org.puremvc.as3.interfaces.ICommand ICommand 25 | * @see org.puremvc.as3.interfaces.INotification INotification 26 | */ 27 | public interface IFacade extends INotifier 28 | { 29 | 30 | /** 31 | * Register anIProxy
with the Model
by name.
32 | *
33 | * @param proxy the IProxy
to be registered with the Model
.
34 | */
35 | function registerProxy( proxy:IProxy ) : void;
36 |
37 | /**
38 | * Retrieve a IProxy
from the Model
by name.
39 | *
40 | * @param proxyName the name of the IProxy
instance to be retrieved.
41 | * @return the IProxy
previously regisetered by proxyName
with the Model
.
42 | */
43 | function retrieveProxy( proxyName:String ) : IProxy;
44 |
45 | /**
46 | * Remove an IProxy
instance from the Model
by name.
47 | *
48 | * @param proxyName the IProxy
to remove from the Model
.
49 | * @return the IProxy
that was removed from the Model
50 | */
51 | function removeProxy( proxyName:String ) : IProxy;
52 |
53 | /**
54 | * Check if a Proxy is registered
55 | *
56 | * @param proxyName
57 | * @return whether a Proxy is currently registered with the given proxyName
.
58 | */
59 | function hasProxy( proxyName:String ) : Boolean;
60 |
61 | /**
62 | * Register an ICommand
with the Controller
.
63 | *
64 | * @param noteName the name of the INotification
to associate the ICommand
with.
65 | * @param commandClassRef a reference to the Class
of the ICommand
.
66 | */
67 | function registerCommand( noteName : String, commandClassRef : Class ) : void;
68 |
69 | /**
70 | * Remove a previously registered ICommand
to INotification
mapping from the Controller.
71 | *
72 | * @param notificationName the name of the INotification
to remove the ICommand
mapping for
73 | */
74 | function removeCommand( notificationName:String ): void;
75 |
76 | /**
77 | * Check if a Command is registered for a given Notification
78 | *
79 | * @param notificationName
80 | * @return whether a Command is currently registered for the given notificationName
.
81 | */
82 | function hasCommand( notificationName:String ) : Boolean;
83 |
84 | /**
85 | * Register an IMediator
instance with the View
.
86 | *
87 | * @param mediator a reference to the IMediator
instance
88 | */
89 | function registerMediator( mediator:IMediator ) : void;
90 |
91 | /**
92 | * Retrieve an IMediator
instance from the View
.
93 | *
94 | * @param mediatorName the name of the IMediator
instance to retrievve
95 | * @return the IMediator
previously registered with the given mediatorName
.
96 | */
97 | function retrieveMediator( mediatorName:String ) : IMediator;
98 |
99 | /**
100 | * Remove a IMediator
instance from the View
.
101 | *
102 | * @param mediatorName name of the IMediator
instance to be removed.
103 | * @return the IMediator
instance previously registered with the given mediatorName
.
104 | */
105 | function removeMediator( mediatorName:String ) : IMediator;
106 |
107 | /**
108 | * Check if a Mediator is registered or not
109 | *
110 | * @param mediatorName
111 | * @return whether a Mediator is registered with the given mediatorName
.
112 | */
113 | function hasMediator( mediatorName:String ) : Boolean;
114 |
115 | /**
116 | * Notify the IObservers
for a particular INotification
.
117 | *
118 | *
119 | * All previously attached IObservers
for this INotification
's
120 | * list are notified and are passed a reference to the INotification
in
121 | * the order in which they were registered.
123 | * NOTE: Use this method only if you are sending custom Notifications. Otherwise 124 | * use the sendNotification method which does not require you to create the 125 | * Notification instance.
126 | * 127 | * @param notification theINotification
to notify IObservers
of.
128 | */
129 | function notifyObservers( note:INotification ) : void;
130 | }
131 | }
--------------------------------------------------------------------------------
/src/org/puremvc/as3/interfaces/IMediator.as:
--------------------------------------------------------------------------------
1 | /*
2 | PureMVC - Copyright(c) 2006-08 Futurescale, Inc., Some rights reserved.
3 | Your reuse is governed by the Creative Commons Attribution 3.0 United States License
4 | */
5 | package org.puremvc.as3.interfaces
6 | {
7 |
8 | /**
9 | * The interface definition for a PureMVC Mediator.
10 | *
11 | *
12 | * In PureMVC, IMediator
implementors assume these responsibilities:
INotification
s
15 | * the IMediator
has interest in.
20 | * Additionally, IMediator
s typically:
21 | *
INotifications
, interacting with of
27 | * the rest of the PureMVC app.
28 | *
30 | * When an IMediator
is registered with the IView
,
31 | * the IView
will call the IMediator
's
32 | * listNotificationInterests
method. The IMediator
will
33 | * return an Array
of INotification
names which
34 | * it wishes to be notified about.
37 | * The IView
will then create an Observer
object
38 | * encapsulating that IMediator
's (handleNotification
) method
39 | * and register it as an Observer for each INotification
name returned by
40 | * listNotificationInterests
.
43 | * A concrete IMediator implementor usually looks something like this:
44 | * 45 | *IMediator
instance name
106 | *
107 | * @return the IMediator
instance name
108 | */
109 | function getMediatorName():String;
110 |
111 | /**
112 | * Get the IMediator
's view component.
113 | *
114 | * @return Object the view component
115 | */
116 | function getViewComponent():Object;
117 |
118 | /**
119 | * Set the IMediator
's view component.
120 | *
121 | * @param Object the view component
122 | */
123 | function setViewComponent( viewComponent:Object ):void;
124 |
125 | /**
126 | * List INotification
interests.
127 | *
128 | * @return an Array
of the INotification
names this IMediator
has an interest in.
129 | */
130 | function listNotificationInterests( ):Array;
131 |
132 | /**
133 | * Handle an INotification
.
134 | *
135 | * @param notification the INotification
to be handled
136 | */
137 | function handleNotification( notification:INotification ):void;
138 |
139 | /**
140 | * Called by the View when the Mediator is registered
141 | */
142 | function onRegister( ):void;
143 |
144 | /**
145 | * Called by the View when the Mediator is removed
146 | */
147 | function onRemove( ):void;
148 |
149 | }
150 | }
--------------------------------------------------------------------------------
/src/org/puremvc/as3/interfaces/IModel.as:
--------------------------------------------------------------------------------
1 | /*
2 | PureMVC - Copyright(c) 2006-08 Futurescale, Inc., Some rights reserved.
3 | Your reuse is governed by the Creative Commons Attribution 3.0 United States License
4 | */
5 | package org.puremvc.as3.interfaces
6 | {
7 | /**
8 | * The interface definition for a PureMVC Model.
9 | *
10 | *
11 | * In PureMVC, IModel
implementors provide
12 | * access to IProxy
objects by named lookup.
15 | * An IModel
assumes these responsibilities:
IProxy
instancesIProxy
instancesIProxy
instance with the Model
.
26 | *
27 | * @param proxyName the name to associate with this IProxy
instance.
28 | * @param proxy an object reference to be held by the Model
.
29 | */
30 | function registerProxy( proxy:IProxy ) : void;
31 |
32 | /**
33 | * Retrieve an IProxy
instance from the Model.
34 | *
35 | * @param proxyName
36 | * @return the IProxy
instance previously registered with the given proxyName
.
37 | */
38 | function retrieveProxy( proxyName:String ) : IProxy;
39 |
40 | /**
41 | * Remove an IProxy
instance from the Model.
42 | *
43 | * @param proxyName name of the IProxy
instance to be removed.
44 | * @return the IProxy
that was removed from the Model
45 | */
46 | function removeProxy( proxyName:String ) : IProxy;
47 |
48 | /**
49 | * Check if a Proxy is registered
50 | *
51 | * @param proxyName
52 | * @return whether a Proxy is currently registered with the given proxyName
.
53 | */
54 | function hasProxy( proxyName:String ) : Boolean;
55 |
56 | }
57 | }
--------------------------------------------------------------------------------
/src/org/puremvc/as3/interfaces/INotification.as:
--------------------------------------------------------------------------------
1 | /*
2 | PureMVC - Copyright(c) 2006-08 Futurescale, Inc., Some rights reserved.
3 | Your reuse is governed by the Creative Commons Attribution 3.0 United States License
4 | */
5 | package org.puremvc.as3.interfaces
6 | {
7 | /**
8 | * The interface definition for a PureMVC Notification.
9 | *
10 | * 11 | * PureMVC does not rely upon underlying event models such 12 | * as the one provided with Flash, and ActionScript 3 does 13 | * not have an inherent event model.
14 | * 15 | *16 | * The Observer Pattern as implemented within PureMVC exists 17 | * to support event-driven communication between the 18 | * application and the actors of the MVC triad.
19 | * 20 | *
21 | * Notifications are not meant to be a replacement for Events
22 | * in Flex/Flash/AIR. Generally, IMediator
implementors
23 | * place event listeners on their view components, which they
24 | * then handle in the usual way. This may lead to the broadcast of Notification
s to
25 | * trigger ICommand
s or to communicate with other IMediators
. IProxy
and ICommand
26 | * instances communicate with each other and IMediator
s
27 | * by broadcasting INotification
s.
30 | * A key difference between Flash Event
s and PureMVC
31 | * Notification
s is that Event
s follow the
32 | * 'Chain of Responsibility' pattern, 'bubbling' up the display hierarchy
33 | * until some parent component handles the Event
, while
34 | * PureMVC Notification
s follow a 'Publish/Subscribe'
35 | * pattern. PureMVC classes need not be related to each other in a
36 | * parent/child relationship in order to communicate with one another
37 | * using Notification
s.
38 | *
39 | * @see org.puremvc.as3.interfaces.IView IView
40 | * @see org.puremvc.as3.interfaces.IObserver IObserver
41 | */
42 | public interface INotification
43 | {
44 |
45 | /**
46 | * Get the name of the INotification
instance.
47 | * No setter, should be set by constructor only
48 | */
49 | function getName():String;
50 |
51 | /**
52 | * Set the body of the INotification
instance
53 | */
54 | function setBody( body:Object ):void;
55 |
56 | /**
57 | * Get the body of the INotification
instance
58 | */
59 | function getBody():Object;
60 |
61 | /**
62 | * Set the type of the INotification
instance
63 | */
64 | function setType( type:String ):void;
65 |
66 | /**
67 | * Get the type of the INotification
instance
68 | */
69 | function getType():String;
70 |
71 | /**
72 | * Get the string representation of the INotification
instance
73 | */
74 | function toString():String;
75 | }
76 | }
--------------------------------------------------------------------------------
/src/org/puremvc/as3/interfaces/INotifier.as:
--------------------------------------------------------------------------------
1 | /*
2 | PureMVC - Copyright(c) 2006-08 Futurescale, Inc., Some rights reserved.
3 | Your reuse is governed by the Creative Commons Attribution 3.0 United States License
4 | */
5 | package org.puremvc.as3.interfaces
6 | {
7 | /**
8 | * The interface definition for a PureMVC Notifier.
9 | *
10 | *
11 | * MacroCommand, Command, Mediator
and Proxy
12 | * all have a need to send Notifications
.
15 | * The INotifier
interface provides a common method called
16 | * sendNotification
that relieves implementation code of
17 | * the necessity to actually construct Notifications
.
20 | * The Notifier
class, which all of the above mentioned classes
21 | * extend, also provides an initialized reference to the Facade
22 | * Singleton, which is required for the convienience method
23 | * for sending Notifications
, but also eases implementation as these
24 | * classes have frequent Facade
interactions and usually require
25 | * access to the facade anyway.
INotification
.
34 | *
35 | * 36 | * Convenience method to prevent having to construct new 37 | * notification instances in our implementation code.
38 | * 39 | * @param notificationName the name of the notification to send 40 | * @param body the body of the notification (optional) 41 | * @param type the type of the notification (optional) 42 | */ 43 | function sendNotification( notificationName:String, body:Object=null, type:String=null ):void; 44 | 45 | } 46 | } -------------------------------------------------------------------------------- /src/org/puremvc/as3/interfaces/IObserver.as: -------------------------------------------------------------------------------- 1 | /* 2 | PureMVC - Copyright(c) 2006-08 Futurescale, Inc., Some rights reserved. 3 | Your reuse is governed by the Creative Commons Attribution 3.0 United States License 4 | */ 5 | package org.puremvc.as3.interfaces 6 | { 7 | 8 | /** 9 | * The interface definition for a PureMVC Observer. 10 | * 11 | *
12 | * In PureMVC, IObserver
implementors assume these responsibilities:
13 | *
21 | * PureMVC does not rely upon underlying event 22 | * models such as the one provided with Flash, 23 | * and ActionScript 3 does not have an inherent 24 | * event model.
25 | * 26 | *27 | * The Observer Pattern as implemented within 28 | * PureMVC exists to support event driven communication 29 | * between the application and the actors of the 30 | * MVC triad.
31 | * 32 | *33 | * An Observer is an object that encapsulates information 34 | * about an interested object with a notification method that 35 | * should be called when an INotification is broadcast. The Observer then 36 | * acts as a proxy for notifying the interested object. 37 | * 38 | *
39 | * Observers can receive Notification
s by having their
40 | * notifyObserver
method invoked, passing
41 | * in an object implementing the INotification
interface, such
42 | * as a subclass of Notification
.
53 | * The notification method should take one parameter of type INotification
INotification
to pass to the interested object's notification method
70 | */
71 | function notifyObserver( notification:INotification ):void;
72 |
73 | /**
74 | * Compare the given object to the notificaiton context object.
75 | *
76 | * @param object the object to compare.
77 | * @return boolean indicating if the notification context and the object are the same.
78 | */
79 | function compareNotifyContext( object:Object ):Boolean;
80 | }
81 | }
--------------------------------------------------------------------------------
/src/org/puremvc/as3/interfaces/IProxy.as:
--------------------------------------------------------------------------------
1 | /*
2 | PureMVC - Copyright(c) 2006-08 Futurescale, Inc., Some rights reserved.
3 | Your reuse is governed by the Creative Commons Attribution 3.0 United States License
4 | */
5 | package org.puremvc.as3.interfaces
6 | {
7 |
8 | /**
9 | * The interface definition for a PureMVC Proxy.
10 | *
11 | *
12 | * In PureMVC, IProxy
implementors assume these responsibilities:
18 | * Additionally, IProxy
s typically:
INotifications
when their model data changes.public static const
called NAME
, if they are not instantiated multiple times.
12 | * In PureMVC, IView
implementors assume these responsibilities:
15 | * In PureMVC, the View
class assumes these responsibilities:
16 | *
IMediator
instances.IMediators
.INotification
in the application.IObservers
to an INotification
's observer list.INotification
.IObservers
of a given INotification
when it broadcast.IObserver
to be notified
34 | * of INotifications
with a given name.
35 | *
36 | * @param notificationName the name of the INotifications
to notify this IObserver
of
37 | * @param observer the IObserver
to register
38 | */
39 | function registerObserver( notificationName:String, observer:IObserver ) : void;
40 |
41 | /**
42 | * Remove a group of observers from the observer list for a given Notification name.
43 | *
44 | * @param notificationName which observer list to remove from
45 | * @param notifyContext removed the observers with this object as their notifyContext
46 | */
47 | function removeObserver( notificationName:String, notifyContext:Object ):void;
48 |
49 | /**
50 | * Notify the IObservers
for a particular INotification
.
51 | *
52 | *
53 | * All previously attached IObservers
for this INotification
's
54 | * list are notified and are passed a reference to the INotification
in
55 | * the order in which they were registered.
INotification
to notify IObservers
of.
58 | */
59 | function notifyObservers( note:INotification ) : void;
60 |
61 | /**
62 | * Register an IMediator
instance with the View
.
63 | *
64 | *
65 | * Registers the IMediator
so that it can be retrieved by name,
66 | * and further interrogates the IMediator
for its
67 | * INotification
interests.
69 | * If the IMediator
returns any INotification
70 | * names to be notified about, an Observer
is created encapsulating
71 | * the IMediator
instance's handleNotification
method
72 | * and registering it as an Observer
for all INotifications
the
73 | * IMediator
is interested in.
IMediator
instance
76 | * @param mediator a reference to the IMediator
instance
77 | */
78 | function registerMediator( mediator:IMediator ) : void;
79 |
80 | /**
81 | * Retrieve an IMediator
from the View
.
82 | *
83 | * @param mediatorName the name of the IMediator
instance to retrieve.
84 | * @return the IMediator
instance previously registered with the given mediatorName
.
85 | */
86 | function retrieveMediator( mediatorName:String ) : IMediator;
87 |
88 | /**
89 | * Remove an IMediator
from the View
.
90 | *
91 | * @param mediatorName name of the IMediator
instance to be removed.
92 | * @return the IMediator
that was removed from the View
93 | */
94 | function removeMediator( mediatorName:String ) : IMediator;
95 |
96 | /**
97 | * Check if a Mediator is registered or not
98 | *
99 | * @param mediatorName
100 | * @return whether a Mediator is registered with the given mediatorName
.
101 | */
102 | function hasMediator( mediatorName:String ) : Boolean;
103 |
104 | }
105 |
106 | }
--------------------------------------------------------------------------------
/src/org/puremvc/as3/patterns/command/MacroCommand.as:
--------------------------------------------------------------------------------
1 | /*
2 | PureMVC - Copyright(c) 2006-08 Futurescale, Inc., Some rights reserved.
3 | Your reuse is governed by the Creative Commons Attribution 3.0 United States License
4 | */
5 | package org.puremvc.as3.patterns.command
6 | {
7 |
8 | import org.puremvc.as3.interfaces.*;
9 | import org.puremvc.as3.patterns.observer.*;
10 |
11 | /**
12 | * A base ICommand
implementation that executes other ICommand
s.
13 | *
14 | *
15 | * A MacroCommand
maintains an list of
16 | * ICommand
Class references called SubCommands.
19 | * When execute
is called, the MacroCommand
20 | * instantiates and calls execute
on each of its SubCommands turn.
21 | * Each SubCommand will be passed a reference to the original
22 | * INotification
that was passed to the MacroCommand
's
23 | * execute
method.
26 | * Unlike SimpleCommand
, your subclass
27 | * should not override execute
, but instead, should
28 | * override the initializeMacroCommand
method,
29 | * calling addSubCommand
once for each SubCommand
30 | * to be executed.
33 | * 34 | * @see org.puremvc.as3.core.controller.Controller Controller 35 | * @see org.puremvc.as3.patterns.observer.Notification Notification 36 | * @see org.puremvc.as3.patterns.command.SimpleCommand SimpleCommand 37 | */ 38 | public class MacroCommand extends Notifier implements ICommand, INotifier 39 | { 40 | 41 | private var subCommands:Array; 42 | 43 | /** 44 | * Constructor. 45 | * 46 | *
47 | * You should not need to define a constructor,
48 | * instead, override the initializeMacroCommand
49 | * method.
52 | * If your subclass does define a constructor, be
53 | * sure to call super()
.
MacroCommand
.
63 | *
64 | *
65 | * In your subclass, override this method to
66 | * initialize the MacroCommand
's SubCommand
67 | * list with ICommand
class references like
68 | * this:
81 | * Note that SubCommands may be any ICommand
implementor,
82 | * MacroCommand
s or SimpleCommands
are both acceptable.
83 | */
84 | protected function initializeMacroCommand():void
85 | {
86 | }
87 |
88 | /**
89 | * Add a SubCommand.
90 | *
91 | *
92 | * The SubCommands will be called in First In/First Out (FIFO) 93 | * order.
94 | * 95 | * @param commandClassRef a reference to theClass
of the ICommand
.
96 | */
97 | protected function addSubCommand( commandClassRef:Class ): void
98 | {
99 | subCommands.push(commandClassRef);
100 | }
101 |
102 | /**
103 | * Execute this MacroCommand
's SubCommands.
104 | *
105 | *
106 | * The SubCommands will be called in First In/First Out (FIFO)
107 | * order.
108 | *
109 | * @param notification the INotification
object to be passsed to each SubCommand.
110 | */
111 | public final function execute( notification:INotification ) : void
112 | {
113 | while ( subCommands.length > 0) {
114 | var commandClassRef : Class = subCommands.shift();
115 | var commandInstance : ICommand = new commandClassRef();
116 | commandInstance.execute( notification );
117 | }
118 | }
119 |
120 | }
121 | }
--------------------------------------------------------------------------------
/src/org/puremvc/as3/patterns/command/SimpleCommand.as:
--------------------------------------------------------------------------------
1 | /*
2 | PureMVC - Copyright(c) 2006-08 Futurescale, Inc., Some rights reserved.
3 | Your reuse is governed by the Creative Commons Attribution 3.0 United States License
4 | */
5 | package org.puremvc.as3.patterns.command
6 | {
7 |
8 | import org.puremvc.as3.interfaces.*;
9 | import org.puremvc.as3.patterns.observer.Notifier;
10 |
11 | /**
12 | * A base ICommand
implementation.
13 | *
14 | *
15 | * Your subclass should override the execute
16 | * method where your business logic will handle the INotification
.
INotification
.
27 | *
28 | *
29 | * In the Command Pattern, an application use-case typically
30 | * begins with some user action, which results in an INotification
being broadcast, which
31 | * is handled by business logic in the execute
method of an
32 | * ICommand
.
INotification
to handle.
35 | */
36 | public function execute( notification:INotification ) : void
37 | {
38 |
39 | }
40 |
41 | }
42 | }
--------------------------------------------------------------------------------
/src/org/puremvc/as3/patterns/mediator/Mediator.as:
--------------------------------------------------------------------------------
1 | /*
2 | PureMVC - Copyright(c) 2006-08 Futurescale, Inc., Some rights reserved.
3 | Your reuse is governed by the Creative Commons Attribution 3.0 United States License
4 | */
5 | package org.puremvc.as3.patterns.mediator
6 | {
7 | import org.puremvc.as3.interfaces.*;
8 | import org.puremvc.as3.patterns.observer.*;
9 | import org.puremvc.as3.patterns.facade.Facade;
10 |
11 | /**
12 | * A base IMediator
implementation.
13 | *
14 | * @see org.puremvc.as3.core.view.View View
15 | */
16 | public class Mediator extends Notifier implements IMediator, INotifier
17 | {
18 |
19 | /**
20 | * The name of the Mediator
.
21 | *
22 | *
23 | * Typically, a Mediator
will be written to serve
24 | * one specific control or group controls and so,
25 | * will not have a need to be dynamically named.
Mediator
.
39 | * @return the Mediator name
40 | */
41 | public function getMediatorName():String
42 | {
43 | return mediatorName;
44 | }
45 |
46 | /**
47 | * Set the IMediator
's view component.
48 | *
49 | * @param Object the view component
50 | */
51 | public function setViewComponent( viewComponent:Object ):void
52 | {
53 | this.viewComponent = viewComponent;
54 | }
55 |
56 | /**
57 | * Get the Mediator
's view component.
58 | *
59 | * 60 | * Additionally, an implicit getter will usually 61 | * be defined in the subclass that casts the view 62 | * object to a type, like this:
63 | * 64 | *INotification
names this
80 | * Mediator
is interested in being notified of.
81 | *
82 | * @return Array the list of INotification
names
83 | */
84 | public function listNotificationInterests():Array
85 | {
86 | return [ ];
87 | }
88 |
89 | /**
90 | * Handle INotification
s.
91 | *
92 | *
93 | * Typically this will be handled in a switch statement,
94 | * with one 'case' entry per INotification
95 | * the Mediator
is interested in.
96 | */
97 | public function handleNotification( notification:INotification ):void {}
98 |
99 | /**
100 | * Called by the View when the Mediator is registered
101 | */
102 | public function onRegister( ):void {}
103 |
104 | /**
105 | * Called by the View when the Mediator is removed
106 | */
107 | public function onRemove( ):void {}
108 |
109 | // the mediator name
110 | protected var mediatorName:String;
111 |
112 | // The view component
113 | protected var viewComponent:Object;
114 | }
115 | }
--------------------------------------------------------------------------------
/src/org/puremvc/as3/patterns/observer/Notification.as:
--------------------------------------------------------------------------------
1 | /*
2 | PureMVC - Copyright(c) 2006-08 Futurescale, Inc., Some rights reserved.
3 | Your reuse is governed by the Creative Commons Attribution 3.0 United States License
4 | */
5 | package org.puremvc.as3.patterns.observer
6 | {
7 | import org.puremvc.as3.interfaces.*;
8 |
9 | /**
10 | * A base INotification
implementation.
11 | *
12 | *
13 | * PureMVC does not rely upon underlying event models such 14 | * as the one provided with Flash, and ActionScript 3 does 15 | * not have an inherent event model.
16 | * 17 | *18 | * The Observer Pattern as implemented within PureMVC exists 19 | * to support event-driven communication between the 20 | * application and the actors of the MVC triad.
21 | * 22 | *
23 | * Notifications are not meant to be a replacement for Events
24 | * in Flex/Flash/Apollo. Generally, IMediator
implementors
25 | * place event listeners on their view components, which they
26 | * then handle in the usual way. This may lead to the broadcast of Notification
s to
27 | * trigger ICommand
s or to communicate with other IMediators
. IProxy
and ICommand
28 | * instances communicate with each other and IMediator
s
29 | * by broadcasting INotification
s.
32 | * A key difference between Flash Event
s and PureMVC
33 | * Notification
s is that Event
s follow the
34 | * 'Chain of Responsibility' pattern, 'bubbling' up the display hierarchy
35 | * until some parent component handles the Event
, while
36 | * PureMVC Notification
s follow a 'Publish/Subscribe'
37 | * pattern. PureMVC classes need not be related to each other in a
38 | * parent/child relationship in order to communicate with one another
39 | * using Notification
s.
40 | *
41 | * @see org.puremvc.as3.patterns.observer.Observer Observer
42 | *
43 | */
44 | public class Notification implements INotification
45 | {
46 |
47 | /**
48 | * Constructor.
49 | *
50 | * @param name name of the Notification
instance. (required)
51 | * @param body the Notification
body. (optional)
52 | * @param type the type of the Notification
(optional)
53 | */
54 | public function Notification( name:String, body:Object=null, type:String=null )
55 | {
56 | this.name = name;
57 | this.body = body;
58 | this.type = type;
59 | }
60 |
61 | /**
62 | * Get the name of the Notification
instance.
63 | *
64 | * @return the name of the Notification
instance.
65 | */
66 | public function getName():String
67 | {
68 | return name;
69 | }
70 |
71 | /**
72 | * Set the body of the Notification
instance.
73 | */
74 | public function setBody( body:Object ):void
75 | {
76 | this.body = body;
77 | }
78 |
79 | /**
80 | * Get the body of the Notification
instance.
81 | *
82 | * @return the body object.
83 | */
84 | public function getBody():Object
85 | {
86 | return body;
87 | }
88 |
89 | /**
90 | * Set the type of the Notification
instance.
91 | */
92 | public function setType( type:String ):void
93 | {
94 | this.type = type;
95 | }
96 |
97 | /**
98 | * Get the type of the Notification
instance.
99 | *
100 | * @return the type
101 | */
102 | public function getType():String
103 | {
104 | return type;
105 | }
106 |
107 | /**
108 | * Get the string representation of the Notification
instance.
109 | *
110 | * @return the string representation of the Notification
instance.
111 | */
112 | public function toString():String
113 | {
114 | var msg:String = "Notification Name: "+getName();
115 | msg += "\nBody:"+(( body == null )?"null":body.toString());
116 | msg += "\nType:"+(( type == null )?"null":type);
117 | return msg;
118 | }
119 |
120 | // the name of the notification instance
121 | private var name : String;
122 | // the type of the notification instance
123 | private var type : String;
124 | // the body of the notification instance
125 | private var body : Object;
126 |
127 | }
128 | }
--------------------------------------------------------------------------------
/src/org/puremvc/as3/patterns/observer/Notifier.as:
--------------------------------------------------------------------------------
1 | /*
2 | PureMVC - Copyright(c) 2006-08 Futurescale, Inc., Some rights reserved.
3 | Your reuse is governed by the Creative Commons Attribution 3.0 United States License
4 | */
5 | package org.puremvc.as3.patterns.observer
6 | {
7 | import org.puremvc.as3.interfaces.*;
8 | import org.puremvc.as3.patterns.facade.Facade;
9 |
10 | /**
11 | * A Base INotifier
implementation.
12 | *
13 | *
14 | * MacroCommand, Command, Mediator
and Proxy
15 | * all have a need to send Notifications
.
16 | *
17 | * The INotifier
interface provides a common method called
18 | * sendNotification
that relieves implementation code of
19 | * the necessity to actually construct Notifications
.
22 | * The Notifier
class, which all of the above mentioned classes
23 | * extend, provides an initialized reference to the Facade
24 | * Singleton, which is required for the convienience method
25 | * for sending Notifications
, but also eases implementation as these
26 | * classes have frequent Facade
interactions and usually require
27 | * access to the facade anyway.
INotification
.
39 | *
40 | *
41 | * Keeps us from having to construct new INotification
42 | * instances in our implementation code.
43 | * @param notificationName the name of the notiification to send
44 | * @param body the body of the notification (optional)
45 | * @param type the type of the notification (optional)
46 | */
47 | public function sendNotification( notificationName:String, body:Object=null, type:String=null ):void
48 | {
49 | facade.sendNotification( notificationName, body, type );
50 | }
51 |
52 | // Local reference to the Facade Singleton
53 | protected var facade:IFacade = Facade.getInstance();
54 | }
55 | }
--------------------------------------------------------------------------------
/src/org/puremvc/as3/patterns/observer/Observer.as:
--------------------------------------------------------------------------------
1 | /*
2 | PureMVC - Copyright(c) 2006-08 Futurescale, Inc., Some rights reserved.
3 | Your reuse is governed by the Creative Commons Attribution 3.0 United States License
4 | */
5 | package org.puremvc.as3.patterns.observer
6 | {
7 | import org.puremvc.as3.interfaces.*;
8 |
9 | /**
10 | * A base IObserver
implementation.
11 | *
12 | *
13 | * An Observer
is an object that encapsulates information
14 | * about an interested object with a method that should
15 | * be called when a particular INotification
is broadcast.
18 | * In PureMVC, the Observer
class assumes these responsibilities:
19 | *
38 | * The notification method on the interested object should take
39 | * one parameter of type INotification
54 | * The notification method should take one parameter of type INotification
.
this
) of the interested object.
87 | */
88 | private function getNotifyContext():Object
89 | {
90 | return context;
91 | }
92 |
93 | /**
94 | * Notify the interested object.
95 | *
96 | * @param notification the INotification
to pass to the interested object's notification method.
97 | */
98 | public function notifyObserver( notification:INotification ):void
99 | {
100 | this.getNotifyMethod().apply(this.getNotifyContext(),[notification]);
101 | }
102 |
103 | /**
104 | * Compare an object to the notification context.
105 | *
106 | * @param object the object to compare
107 | * @return boolean indicating if the object and the notification context are the same
108 | */
109 | public function compareNotifyContext( object:Object ):Boolean
110 | {
111 | return object === this.context;
112 | }
113 | }
114 | }
--------------------------------------------------------------------------------
/src/org/puremvc/as3/patterns/proxy/Proxy.as:
--------------------------------------------------------------------------------
1 | /*
2 | PureMVC - Copyright(c) 2006-08 Futurescale, Inc., Some rights reserved.
3 | Your reuse is governed by the Creative Commons Attribution 3.0 United States License
4 | */
5 | package org.puremvc.as3.patterns.proxy
6 | {
7 | import org.puremvc.as3.interfaces.*;
8 | import org.puremvc.as3.patterns.observer.*;
9 | import org.puremvc.as3.patterns.facade.Facade;
10 |
11 | /**
12 | * A base IProxy
implementation.
13 | *
14 | *
15 | * In PureMVC, Proxy
classes are used to manage parts of the
16 | * application's data model.
19 | * A Proxy
might simply manage a reference to a local data object,
20 | * in which case interacting with it might involve setting and
21 | * getting of its data in synchronous fashion.
24 | * Proxy
classes are also used to encapsulate the application's
25 | * interaction with remote services to save or retrieve data, in which case,
26 | * we adopt an asyncronous idiom; setting data (or calling a method) on the
27 | * Proxy
and listening for a Notification
to be sent
28 | * when the Proxy
has retrieved the data from the service.