73 | {
74 | /**
75 | Dispatched when the values of the collection change.
76 | */
77 | var changed:Signal0;
78 |
79 | /**
80 | The number of values in this collection.
81 | */
82 | var size(get, null):Int;
83 |
84 | /**
85 | Adds a value to the collection.
86 |
87 | @param value the value to add.
88 | */
89 | function add(value:T):Void;
90 |
91 | /**
92 | Adds a collection of values to this collection.
93 |
94 | @param values the collection of values to add to this collection.
95 | */
96 | function addAll(values:Iterable):Void;
97 |
98 | /**
99 | Removes all values in the collection.
100 | */
101 | function clear():Void;
102 |
103 | /**
104 | Returns true if a value in the collection is equal to the provided value,
105 | using standard equality.
106 |
107 | @param value the value to check for.
108 | @return true
if value exists in collection.
109 | * false
otherwise
110 | */
111 | function contains(value:T):Bool;
112 |
113 | /**
114 | @return true
if collection contains no values.
115 | * false
otherwise
116 | */
117 | function isEmpty():Bool;
118 |
119 | /**
120 | Directly access an iterator contain the values of the collection
121 |
122 | for(foo in collection.iterator())
123 | {
124 | trace(foo.bar);
125 | }
126 |
127 |
128 | @return Iterator for the values in the collection.
129 | */
130 | function iterator():Iterator>;
131 |
132 | /**
133 | Removes a value from the collection if it exists.
134 |
135 | @param value The value to remove.
136 | @return true
if value was successfully removed
137 | * false
otherwise
138 | */
139 | function remove(value:T):Bool;
140 |
141 | /**
142 | Returns a collection containing values for which predicate(value) returns
143 | true.
144 |
145 | @param predicate The filtering function, taking a collection value as an
146 | argument and returning a boolean indicating prescence in the resulting
147 | collection.
148 | @return The filtered collection.
149 | */
150 | function filter(predicate:T -> Bool):Collection;
151 |
152 | /**
153 | Returns an array of the values in the collection.
154 | @return An array of values in the collection.
155 | */
156 | function toArray():Array;
157 | }
158 |
--------------------------------------------------------------------------------
/example/src/mcore/data/CollectionBase.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mcore.data;
24 |
25 | import msignal.Signal;
26 | import mcore.util.Iterables;
27 | import mcore.util.Arrays;
28 | import mcore.util.Types;
29 |
30 | /**
31 | A base collection implementation.
32 | *
33 | @see mcore.data.Collection
34 | */
35 | class CollectionBase implements Collection
36 | {
37 | /**
38 | Dispatched when the values of the collection change.
39 | */
40 | public var changed:Signal0;
41 |
42 | /**
43 | The number of values in this collection.
44 | */
45 | public var size(get, null):Int;
46 | function get_size():Int { return source.length; }
47 |
48 | var source:Array;
49 |
50 | function new()
51 | {
52 | source = [];
53 | changed = new Signal0();
54 | }
55 |
56 | /**
57 | Adds a value to the collection.
58 |
59 | @param value The value to add.
60 | */
61 | public function add(value:T)
62 | {
63 | source.push(value);
64 | notifyChanged();
65 | }
66 |
67 | function notifyChanged()
68 | {
69 | changed.dispatch();
70 | }
71 |
72 | /**
73 | Adds a collection of values to this collection.
74 |
75 | @param values the collection of values to add to this collection.
76 | */
77 | public function addAll(values:Iterable)
78 | {
79 | if (values == null) return;
80 |
81 | var s = source.length;
82 | for (value in values)
83 | {
84 | source.push(value);
85 | }
86 |
87 | if (source.length != s)
88 | notifyChanged();
89 | }
90 |
91 | /**
92 | Removes all values in the colleciton.
93 | */
94 | public function clear()
95 | {
96 | if (isEmpty()) return;
97 |
98 | source.splice(0, source.length);
99 | notifyChanged();
100 | }
101 |
102 | /**
103 | Returns true if a value in the collection is equal to the provided value,
104 | using standard equality.
105 |
106 | @param value The value to check for.
107 | @return A boolean indicating the existence of the value in the collection.
108 | */
109 | public function contains(value:T):Bool
110 | {
111 | return Iterables.contains(source, value);
112 | }
113 |
114 | /**
115 | @return A boolean indicating the abscence of values in the collection.
116 | */
117 | public function isEmpty():Bool
118 | {
119 | return source.length == 0;
120 | }
121 |
122 | /**
123 | @return An iterator for the values in the collection.
124 | */
125 | public function iterator():Iterator>
126 | {
127 | return source.iterator();
128 | }
129 |
130 | /**
131 | Removes a value from the collection if it exists.
132 |
133 | @param value The value to remove.
134 | @return A boolean indicating whether the value was removed.
135 | */
136 | public function remove(value:T):Bool
137 | {
138 | var hasChanged = false;
139 | var i = source.length;
140 | while (i-- > 0)
141 | {
142 | if (source[i] == value)
143 | {
144 | source.splice(0, 1);
145 | hasChanged = true;
146 | }
147 | }
148 | if (hasChanged)
149 | notifyChanged();
150 |
151 | return hasChanged;
152 | }
153 |
154 | /**
155 | Returns a collection containing values for which predicate(value) returns
156 | true.
157 |
158 | @param predicate The filtering function, taking a collection value as an
159 | argument and returning a boolean indicating prescence in the resulting
160 | collection.
161 | @return The filtered collection.
162 | */
163 | public function filter(predicate:T -> Bool):Collection
164 | {
165 | var collectionType = Type.getClass(this);
166 | var collection:Collection = Types.createInstance(collectionType, []);
167 | var filteredValues:Array = Iterables.filter(source, predicate);
168 |
169 | collection.addAll(filteredValues);
170 | return collection;
171 | }
172 |
173 | /**
174 | Returns an array of the values in the collection.
175 |
176 | @return An array of values in the collection.
177 | */
178 | public function toArray():Array
179 | {
180 | return source.copy();
181 | }
182 |
183 | /**
184 | Returns a string representation of the collection.
185 |
186 | @return A String representation of the collection.
187 | */
188 | public function toString():String
189 | {
190 | return Arrays.toString(source);
191 | }
192 | }
193 |
--------------------------------------------------------------------------------
/example/src/mcore/loader/HTTPLoader.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mcore.loader;
24 |
25 | import mcore.loader.Loader;
26 | import msignal.Signal;
27 | import haxe.Http;
28 |
29 | using mcore.util.Strings;
30 |
31 | /**
32 | The HTTPLoader class is responsible for loading HTTP requests. The API also
33 | handles the completed and failed signals.
34 | */
35 |
36 | class HTTPLoader extends LoaderBase
37 | {
38 | /**
39 | The headers to pass through with the http request.
40 | */
41 | public var headers(default, null):Map;
42 |
43 | /**
44 | HTTP status code of response.
45 | */
46 | public var statusCode(default, null):Int;
47 |
48 | var http:Http;
49 |
50 | /**
51 | @param uri the uri to load the resource from
52 | @param http optional Http instance to use for the load request
53 | */
54 | public function new(?uri:String, ?http:Http)
55 | {
56 | super(uri);
57 |
58 | if (http == null)
59 | http = new Http("");
60 |
61 | this.http = http;
62 |
63 | http.onData = httpData;
64 | http.onError = httpError;
65 | http.onStatus = httpStatus;
66 | headers = new Map();
67 | }
68 |
69 | /**
70 | Configures and makes the http request. The load method does not pass
71 | through any data with the request.
72 | */
73 | override public function load()
74 | {
75 | super.load();
76 |
77 | http.url = uri;
78 | httpConfigure();
79 | addHeaders();
80 |
81 | progressed.dispatch(0);
82 |
83 | #if nme
84 | if (uri.indexOf("http:") == 0)
85 | {
86 | haxe.Timer.delay(callback(http.request, false), 10);
87 | }
88 | else
89 | {
90 | var result = nme.installer.Assets.getText("root/" + uri);
91 | haxe.Timer.delay(callback(httpData, result), 10);
92 | }
93 | #elseif neko
94 | if (uri.indexOf("http:") == 0)
95 | {
96 | http.request(false);
97 | }
98 | else
99 | {
100 | loadFromFileSystem(uri);
101 | }
102 | #else
103 | try
104 | {
105 | http.request(false);
106 | }
107 | catch (e:Dynamic)
108 | {
109 | // js can throw synchronous security error
110 | failed.dispatch(SecurityError(Std.string(e)));
111 | }
112 | #end
113 | }
114 |
115 | #if neko
116 |
117 | /**
118 | Workaround to enable loading relative urls in neko
119 | */
120 | function loadFromFileSystem(uri:String)
121 | {
122 | if (!sys.FileSystem.exists(uri))
123 | {
124 | failed.dispatch(IOError("Local file does not exist: " + uri));
125 | }
126 | else
127 | {
128 | var contents = sys.io.File.getContent(uri);
129 | httpData(contents);
130 | }
131 | }
132 | #end
133 |
134 | /**
135 | Configures and makes the http request. The send method can also pass
136 | through data with the request. It also traps any security errors and
137 | dispatches a failed signal.
138 |
139 | @param uri The URI to load.
140 | @param data Data to pass through with the request.
141 | */
142 | public function send(data:Dynamic)
143 | {
144 | if (uri == null)
145 | throw "No uri defined for Loader";
146 |
147 | #if debug
148 | checkListeners();
149 | #end
150 |
151 | if (!headers.exists("Content-Type"))
152 | {
153 | var contentType = getMIMEType(data);
154 | headers.set("Content-Type", contentType);
155 | }
156 |
157 | http.url = uri;
158 | http.setPostData(Std.string(data));
159 |
160 | httpConfigure();
161 | addHeaders();
162 |
163 | progressed.dispatch(0);
164 |
165 | try
166 | {
167 | http.request(true);
168 | }
169 | catch (e:Dynamic)
170 | {
171 | // js can throw synchronous security error
172 | failed.dispatch(SecurityError(Std.string(e)));
173 | }
174 | // #end
175 | }
176 |
177 | /**
178 | Returns the MIME type for the current data.
179 |
180 | Currently only auto-detects Xml and Json. Defaults to 'application/octet-stream'.
181 |
182 | Note: This can be overwritten by adding a 'Content-Type' to the headers hash
183 | */
184 | function getMIMEType(data:Dynamic):String
185 | {
186 | if (Std.is(data, Xml))
187 | {
188 | return "application/xml";
189 | }
190 | else if (Std.is(data, String) && data.length > 0 &&
191 | (data.charAt(0) == "{" && data.charAt(data.length - 1) == "}") ||
192 | (data.charAt(0) == "[" && data.charAt(data.length - 1) == "]"))
193 | {
194 | return "application/json";
195 | }
196 |
197 | return "application/octet-stream";
198 | }
199 |
200 | /**
201 | Cancels the http request. Dispatches the cancelled signal when
202 | called.
203 | */
204 | override public function cancel()
205 | {
206 | super.cancel();
207 | cancelled.dispatch();
208 | }
209 |
210 | function httpConfigure()
211 | {
212 | }
213 |
214 | function addHeaders()
215 | {
216 | for (name in headers.keys())
217 | {
218 | http.setHeader(name, headers.get(name));
219 | }
220 | }
221 |
222 | function httpData(data:String)
223 | {
224 | progressed.dispatch(1);
225 | completed.dispatch(cast data);
226 | }
227 |
228 | function httpStatus(status:Int)
229 | {
230 | statusCode = status;
231 | }
232 |
233 | function httpError(error:String)
234 | {
235 | failed.dispatch(IOError(error));
236 | }
237 | }
238 |
--------------------------------------------------------------------------------
/example/src/mcore/loader/JSONLoader.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mcore.loader;
24 |
25 | import mcore.loader.Loader;
26 | using mcore.util.Strings;
27 |
28 | /**
29 | The JSONLoader is an extension of the HTTPLoader. It's responsible for loading
30 | JSON resources and serializing them into objects.
31 |
32 | Example
33 |
34 | var loader = new JSONLoader();
35 | loader.completed.add(completed);
36 | loader.load("http://some/url/to/load");
37 |
38 | function completed(result:Dynamic)
39 | {
40 | trace(result.someValue)
41 | }
42 | */
43 | class JSONLoader extends HTTPLoader
44 | {
45 | /**
46 | @param uri the uri to load the resource from
47 | @param http optional Http instance to use for the load request
48 | */
49 | public function new(?uri:String, ?http:haxe.Http)
50 | {
51 | super(uri, http);
52 | }
53 |
54 | /**
55 | override httpData to deserialize JSON string into an object.
56 | triggers FormatError if invalid JSON.
57 | */
58 | override function httpData(data:String)
59 | {
60 | progressed.dispatch(1);
61 |
62 | try
63 | {
64 | var json:Dynamic = haxe.Json.parse(data);
65 | completed.dispatch(json);
66 | }
67 | catch (e:Dynamic)
68 | {
69 | failed.dispatch(FormatError(Std.string(e)));
70 | return;
71 | }
72 |
73 |
74 | }
75 |
76 |
77 | /**
78 | Ensures POST data is valid JSON string
79 |
80 | @param uri The URI to load.
81 | @param data object or JSON string to pass through with the request.
82 | */
83 | override public function send(data:Dynamic)
84 | {
85 | if (uri == null)
86 | throw "No uri defined for Loader";
87 |
88 | try
89 | {
90 | if (!Std.is(data, String))
91 | {
92 | data = haxe.Json.stringify(data);
93 | }
94 |
95 | if (!headers.exists("Content-Type"))
96 | {
97 | headers.set("Content-Type", "application/json");
98 | }
99 |
100 | super.send(data);
101 | }
102 | catch(e:Dynamic)
103 | {
104 | failed.dispatch(FormatError(Std.string(e)));
105 | }
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/example/src/mcore/loader/Loader.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mcore.loader;
24 | import msignal.Signal;
25 |
26 | typedef AnyLoader = Loader;
27 |
28 | /**
29 | The Loader class defines an API for loading uri's. The API also defines signals
30 | for progressed, completed and failed requests.
31 | */
32 |
33 | interface Loader
34 | {
35 | var uri:String;
36 | var progress(get, null):Float;
37 |
38 | var progressed(default, null):Signal1;
39 | var completed(default, null):Signal1;
40 | var failed(default, null):Signal1;
41 | var cancelled(default, null):Signal0;
42 |
43 | function load():Void;
44 | function cancel():Void;
45 | }
46 |
47 | enum LoaderError
48 | {
49 | IOError(info:String);
50 | SecurityError(info:String);
51 | FormatError(info:String);
52 | DataError(info:String, data:String);
53 | }
54 |
--------------------------------------------------------------------------------
/example/src/mcore/loader/LoaderBase.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mcore.loader;
24 |
25 | import msignal.Signal;
26 | import mcore.loader.Loader;
27 |
28 | /**
29 | The LoaderBase class is an abstract implementation of the Loader class.
30 | */
31 |
32 | class LoaderBase implements Loader
33 | {
34 | /**
35 | The uri to load the resource from.
36 | */
37 | public var uri:String;
38 |
39 | /**
40 |
41 | */
42 | public var asset(default, null):T;
43 |
44 | /**
45 | The percentage of loading complete. Between 0 and 1.
46 | */
47 | public var progress(get, null):Float;
48 | function get_progress() { return 0; }
49 |
50 | /**
51 | A signal indicating a request has progressed
52 | */
53 | public var progressed(default, null):Signal1;
54 |
55 | /**
56 | A signal indicating a request is completed
57 | */
58 | public var completed(default, null):Signal1;
59 |
60 | /**
61 | A signal indicating a request has failed
62 | */
63 | public var failed(default, null):Signal1;
64 |
65 | /**
66 | A signal indicating a request has been cancelled
67 | */
68 | public var cancelled(default, null):Signal0;
69 |
70 | /**
71 | @param uri the uri to load the resource from
72 | */
73 | public function new(?uri:String)
74 | {
75 | this.uri = uri;
76 |
77 | progressed = new Signal1(Float);
78 | completed = new Signal1(null);
79 | failed = new Signal1(LoaderError);
80 | cancelled = new Signal0();
81 | }
82 |
83 | /**
84 | Called when the loader should begin the loading of a resource from the defined uri.
85 |
86 | Concrete instances should override this method to initiate their loading process.
87 | */
88 | public function load():Void
89 | {
90 | if (uri == null)
91 | throw "No uri defined for Loader";
92 |
93 | #if debug
94 | checkListeners();
95 | #end
96 | }
97 |
98 | /**
99 | Called when the loader should cancel its request to load a resource.
100 | */
101 | public function cancel():Void
102 | {
103 | }
104 |
105 | #if debug
106 | @:IgnoreCover
107 | function checkListeners()
108 | {
109 | var className = Type.getClassName(Type.getClass(this));
110 | if (completed.numListeners == 0) Console.warn("No completed listeners for " + className);
111 | if (failed.numListeners == 0) Console.warn("No failed listeners for " + className);
112 | }
113 | #end
114 | }
115 |
--------------------------------------------------------------------------------
/example/src/mcore/util/Arrays.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mcore.util;
24 |
25 | class Arrays
26 | {
27 | /**
28 | Normalises toString() output between platforms
29 | For example: ["a", "b", "c"] becomes "a,b,c"
30 | Note: in neko array.toString includes the '[]' and has space between each value.
31 | Where as in js/flash it doesnt.
32 |
33 | @param source The source array to convert to string;
34 | @return string in format "a,b,c"
35 | */
36 | public static inline function toString(source:Array):String
37 | {
38 | #if neko
39 | return source.join(",");
40 | #else
41 | return source.toString();
42 | #end
43 | }
44 |
45 | /**
46 | Returns a copy of the source array, with its elements randomly reordered
47 | */
48 | public static function shuffle(source:Array):Array
49 | {
50 | var copy = source.copy();
51 | var shuffled = [];
52 | while (copy.length > 0)
53 | shuffled.push(copy.splice(Std.random(copy.length), 1)[0]);
54 | return shuffled;
55 | }
56 |
57 | /**
58 | Convenience method to get the last item in an array.
59 | */
60 | public static inline function lastItem(source:Array):T
61 | {
62 | return source[source.length - 1];
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/example/src/mcore/util/Iterables.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mcore.util;
24 |
25 | /**
26 | Utility methods to operate on Iterables.
27 |
28 | Has some similarities to Haxe's Lambda class with the following main differences:
29 |
30 | a) Favor native Arrays over Haxe based Lists
31 | b) Inline methods where it makes sense for speed.
32 | */
33 | class Iterables
34 | {
35 | /**
36 | Determine if a value is present in an iterable.
37 | Standard equality is used for comparison.
38 | */
39 | public static inline function contains(iterable:Iterable, value:T):Bool
40 | {
41 | return indexOf(iterable, value) != -1;
42 | }
43 |
44 | /**
45 | Returns the index of a value in an iterable, or -1 if not found.
46 | Standard equality is used for comparison.
47 | */
48 | public static function indexOf(iterable:Iterable, value:T):Int
49 | {
50 | var i = 0;
51 | for (member in iterable)
52 | {
53 | if (member == value)
54 | return i;
55 | i++;
56 | }
57 | return -1;
58 | }
59 |
60 | /**
61 | Returns the first element of an iterable that satisfies the predicate, or null
62 | if there is no such element.
63 | */
64 | public static inline function find(iterable:Iterable, predicate:T->Bool):Null
65 | {
66 | var item:Null = null;
67 | for (member in iterable)
68 | {
69 | if (predicate(member))
70 | {
71 | item = member;
72 | break;
73 | }
74 | }
75 | return item;
76 | }
77 |
78 | /**
79 | Filter an iterable by a predicate and return the matching elements in an array.
80 | */
81 | public static inline function filter(iterable:Iterable, predicate:T -> Bool):Array
82 | {
83 | var items:Array = [];
84 | for (member in iterable)
85 | if (predicate(member))
86 | items.push(member);
87 | return items;
88 | }
89 |
90 | /**
91 | Concatenate the elements of two iterables into a single array.
92 | */
93 | public static inline function concat(iterableA:Iterable, iterableB:Iterable):Array
94 | {
95 | var items:Array = [];
96 | for (iterable in [iterableA, iterableB])
97 | for (item in iterable)
98 | items.push(item);
99 | return items;
100 | }
101 |
102 | /**
103 | Apply a selector function to each element of an iterable, and return the array of results.
104 | */
105 | public static inline function map(iterable:Iterable, selector:A -> B):Array
106 | {
107 | var items:Array = [];
108 | for (item in iterable)
109 | items.push(selector(item));
110 | return items;
111 | }
112 |
113 | /**
114 | Apply a selector function to each element of an iterable, also passing in the index, and return the array of results.
115 | */
116 | public static inline function mapWithIndex(iterable:Iterable, selector:A -> Int -> B):Array
117 | {
118 | var items:Array = [];
119 | for (item in iterable)
120 | items.push(selector(item, items.length));
121 | return items;
122 | }
123 |
124 | /**
125 | Perform a functional left fold.
126 |
127 | From tail to head, each element of the iterable is passed to the aggregator function along with the
128 | current aggregate. This should then return the new aggregate.
129 |
130 | @return the final aggregate of the fold
131 | */
132 | public static inline function fold(iterable:Iterable, aggregator:A -> B -> B, seed:B):B
133 | {
134 | for (member in iterable)
135 | seed = aggregator(member, seed);
136 | return seed;
137 | }
138 |
139 | /**
140 | Perform a functional right fold.
141 |
142 | From head to tail, each element of the iterable is passed to the aggregator function along with the
143 | current aggregate. This should then return the new aggregate.
144 |
145 | @return the final aggregate of the fold
146 | */
147 | public static inline function foldRight(iterable:Iterable, aggregator:A -> B -> B, seed:B):B
148 | {
149 | return fold(reverse(iterable), aggregator, seed);
150 | }
151 |
152 | /**
153 | Reverse an iterable's order and return as an array.
154 | */
155 | public static inline function reverse(iterable:Iterable):Array
156 | {
157 | var items:Array = [];
158 | for (member in iterable)
159 | items.unshift(member);
160 | return items;
161 | }
162 |
163 | /**
164 | Determine if an iterable has any elements.
165 | */
166 | public static inline function isEmpty(iterable:Iterable):Bool
167 | {
168 | return !iterable.iterator().hasNext();
169 | }
170 |
171 | /**
172 | Convert an iterable to an array.
173 | */
174 | public static inline function toArray(iterable:Iterable):Array
175 | {
176 | var result:Array = [];
177 | for (member in iterable)
178 | result.push(member);
179 | return result;
180 | }
181 |
182 | /**
183 | Return the number of elements in an iterable.
184 | */
185 | public static inline function size(iterable:Iterable):Int
186 | {
187 | var i = 0;
188 | for (member in iterable)
189 | i++;
190 | return i;
191 | }
192 |
193 | /**
194 | Count the number of elements in an iterable which fulfill a given predicate.
195 | */
196 | public static inline function count(iterable:Iterable, predicate:T->Bool):Int
197 | {
198 | var i = 0;
199 | for (member in iterable)
200 | if (predicate(member))
201 | i++;
202 | return i;
203 | }
204 | }
205 |
--------------------------------------------------------------------------------
/example/src/mcore/util/Strings.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mcore.util;
24 |
25 | /**
26 | Utility methods for working with strings.
27 | */
28 | class Strings
29 | {
30 | /**
31 | Removes all the HTML markup from a string
32 |
33 | @param content the string to strip
34 | @return the stripped string
35 | */
36 | public static function stripHTML(content:String):String
37 | {
38 | var pattern:EReg = ~/<[^>]*>/g;
39 | return pattern.replace(content, "");
40 | }
41 |
42 | /**
43 | Capitalizes a string of words separated by spaces.
44 |
45 | @param value the string to capitalize
46 | @return the capitalized string
47 | */
48 | public static function capitalize(value:String):String
49 | {
50 | // dp: this function really needs improvement
51 |
52 | var words = value.split(" ");
53 | for (i in 0...words.length)
54 | {
55 | var word = words[i];
56 | words[i] = word.charAt(0).toUpperCase() + word.substr(1);
57 | }
58 |
59 | return words.join(" ");
60 | }
61 |
62 |
63 | /**
64 | Replaces token markers in source string with supplied token values.
65 | The index of a token value maps to its id in the source string.
66 |
67 | e.g. StringTools.substitute("Red {0} {1}", ["Green", "Blue"]); // outputs Red Green Blue
68 |
69 | @param source the string with tokens to be substituted
70 | @param values an array of substitute tokens
71 | @return a copy of the source string with any substitutions made
72 | */
73 | public static function substitute(source:String, values:Array):String
74 | {
75 | for (i in 0...values.length)
76 | source = source.split("{" + i + "}").join(values[i]);
77 | return source;
78 | }
79 |
80 | /**
81 | Returns true if the subject string is found within the source string
82 |
83 | @param source the string to search
84 | @param subject the string to search for in source
85 |
86 | @return true if the subject is found, false if not
87 | */
88 | public static inline function contains(source:String, subject:String):Bool
89 | {
90 | return source.indexOf(subject) != -1;
91 | }
92 |
93 | /**
94 | Convenience method to the get the last character in a string.
95 |
96 | @param source the string to grab the last character from
97 | @return the last character in the source string
98 | */
99 | public static inline function lastChar(source:String):String
100 | {
101 | return (source == "") ? "" : source.charAt(source.length - 1);
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/example/src/mcore/util/Types.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mcore.util;
24 |
25 | /**
26 | Utility methods for working with types.
27 | */
28 | class Types
29 | {
30 | /**
31 | Checks if an object is an instance of, or instance of a subclass of
32 | a given type.
33 |
34 | @param object the instance to check
35 | @param type the type to compare against
36 | @return true if object is instance of type or subclass else false
37 | */
38 | public static function isSubClassOf(object:Dynamic, type:Dynamic):Bool
39 | {
40 | return (Std.is(object, type) && Type.getClass(object) != type);
41 | }
42 |
43 | /**
44 | Wraps Type.createInstance to support optional constructor arguments in neko
45 |
46 | @param forClass the class type to instanciate
47 | @param args optional array of arguments
48 | @return instance of type
49 | */
50 | public static function createInstance(forClass:Class, ?args:Array):T
51 | {
52 | if (args == null) args = [];
53 |
54 | #if !neko
55 | try
56 | {
57 | return Type.createInstance(forClass, args);
58 | }
59 | catch(e:Dynamic)
60 | {
61 | throw "Error creating instance of " + Type.getClassName(forClass) + "(" + args.toString() + ")";
62 | }
63 |
64 | #else
65 | var attempts = 0;
66 | do
67 | {
68 | try
69 | {
70 | return Type.createInstance(forClass, args);
71 | }
72 | catch(e:Dynamic)
73 | {
74 | if (e != "Invalid call")
75 | {
76 | throw "Error creating instance of " + Type.getClassName(forClass) + "(" + args.toString() + ")";
77 | }
78 | }
79 |
80 | attempts ++;
81 | args.push(null);
82 | }
83 | while (attempts < 10);
84 |
85 | throw "Unable to create instance of " + Type.getClassName(forClass);
86 |
87 | return null;
88 | #end
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/lib.json:
--------------------------------------------------------------------------------
1 | {
2 | "hamcrest":"1.2.1",
3 | "mconsole":"1.6.1",
4 | "mcore":"1.3.12",
5 | "mcover":"2.1.1",
6 | "minject":"1.6.0",
7 | "mlib":"2.0.2",
8 | "msignal":"1.2.3",
9 | "msys":"1.2.2",
10 | "mtask":"3.7.0",
11 | "munit":"2.1.1"
12 | }
--------------------------------------------------------------------------------
/mdk/info.config:
--------------------------------------------------------------------------------
1 | name: mmvc
2 | version: 1.6.1
3 | dependencies:
4 | minject: ^1.4.0
5 | msignal: ^1.2.0
6 | dev-dependencies:
7 | mcover: ^2.0.0
8 | hamcrest: ^1.0.0
9 | mtask: ^3.0.0
10 | munit: ^2.0.0
11 | hxcpp:
12 | source: haxelib
13 | version: ^3.1.0
14 |
--------------------------------------------------------------------------------
/mdk/lib.config:
--------------------------------------------------------------------------------
1 | hamcrest: 1.2.1
2 | hxcpp: 3.2.81
3 | mconsole: 1.6.1
4 | mcore: 1.3.13
5 | mcover: 2.1.1
6 | minject: 1.6.0
7 | mlib: 2.0.2
8 | msignal: 1.2.3
9 | msys: 1.2.2
10 | mtask: 3.7.1
11 | munit: 2.1.1
--------------------------------------------------------------------------------
/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "project":
3 | {
4 | "name": "MassiveMVC",
5 | "version": "1.6.3",
6 | "id": "mmvc",
7 | "devDependencies":
8 | {
9 | "mcover": "2.x",
10 | "hamcrest": "1.x",
11 | "mtask": "3.x",
12 | "munit": "2.x"
13 | },
14 | "dependencies":
15 | {
16 | "minject": ">=1.4 <2",
17 | "msignal": ">=1.2 <2"
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/src/haxelib.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "mmvc",
3 | "license": "MIT",
4 | "tags": [
5 | "cross",
6 | "massive",
7 | "mvc"
8 | ],
9 | "description": "A Haxe port of the ActionScript 3 RobotLegs MVC framework with signals and Haxe refinements. Supports AVM1, AVM2, JavaScript, Neko and C++.",
10 | "contributors": [
11 | "massive"
12 | ],
13 | "releasenote": "Add TriggerMap",
14 | "version": "1.6.3",
15 | "url": "http://github.com/massiveinteractive/mmvc",
16 | "dependencies":
17 | {
18 | "minject": "",
19 | "msignal": ""
20 | }
21 | }
--------------------------------------------------------------------------------
/src/haxelib.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/mmvc/api/ICommand.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.api;
24 |
25 | interface ICommand
26 | {
27 | public function execute():Void;
28 | }
29 |
--------------------------------------------------------------------------------
/src/mmvc/api/ICommandMap.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.api;
24 |
25 | import msignal.Signal;
26 | import mmvc.api.ICommand;
27 |
28 | typedef CommandClass = Class;
29 | typedef SignalClass = Class;
30 |
31 | interface ICommandMap
32 | {
33 | function mapSignal(signal:AnySignal, commandClass:CommandClass, ?oneShot:Bool=false):Void;
34 |
35 | function mapSignalClass(signalClass:SignalClass, commandClass:CommandClass, ?oneShot:Bool=false):AnySignal;
36 |
37 | function hasSignalCommand(signal:AnySignal, commandClass:CommandClass):Bool;
38 |
39 | function unmapSignal(signal:AnySignal, commandClass:CommandClass):Void;
40 |
41 | function unmapSignalClass(signalClass:SignalClass, commandClass:CommandClass):Void;
42 |
43 | function detain(command:ICommand):Void;
44 |
45 | function release(command:ICommand):Void;
46 | }
47 |
--------------------------------------------------------------------------------
/src/mmvc/api/IContext.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.api;
24 |
25 | /**
26 | The mmvc Context contract
27 | **/
28 | interface IContext
29 | {
30 | var commandMap(get, null):ICommandMap;
31 | }
32 |
--------------------------------------------------------------------------------
/src/mmvc/api/IGuard.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.api;
24 |
25 | interface IGuard
26 | {
27 | function approve():Bool;
28 | }
29 |
--------------------------------------------------------------------------------
/src/mmvc/api/IGuardedCommandMap.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.api;
24 |
25 | import msignal.Signal;
26 | import mmvc.api.ICommand;
27 | import mmvc.api.ICommandMap;
28 | import mmvc.api.IGuard;
29 |
30 | typedef GuardClassArray = Array>;
31 |
32 | interface IGuardedCommandMap extends ICommandMap
33 | {
34 | /**
35 | Map a Command to an instance of a Signal, with Guards
36 |
37 | - The `signal` - an instance of `Signal`
38 | - The `commandClass` must implement an `execute()` method
39 | - The `guards` must be a class which implements an `approve()` method or an `Array` of
40 | classes which implement an `approve()` method
41 |
42 | @param signal The signal instance to trigger this command. Values dispatched by this signal
43 | are available for injection into guards and the command.
44 | @param commandClass The class to instantiate - must have an `execute()` method
45 | @param guards The Classes of the guard or guards to instantiate - must have an `approve()` method
46 | @param oneshot Unmap the class after execution
47 | @throws `mmvc.base.ContextError`
48 | **/
49 | function mapGuardedSignal(signal:AnySignal, commandClass:CommandClass, guards:GuardClassArray,
50 | oneshot:Bool=false):Void;
51 |
52 | /**
53 | Map a Command to an instance of a Signal, with Guards
54 |
55 | - The `signalClass` - a class implementing ISignal
56 | - The `commandClass` must implement an `execute()` method
57 | - The `guards` must be a class which implements an `approve()` method
58 | - or an `Array` of Classes which implements an `approve()` method
59 |
60 | @param commandClass The signal class to be created - an instance of this class is then
61 | available for injection as a singleton in the main Injector.
62 | @param commandClass The class to instantiate - must have an `execute()` method
63 | @param guards The Classes of the guard or guards to instantiate - must have an
64 | `approve()` method
65 | @param oneshot Unmap the class after execution?
66 | @throws `mmvc.base.ContextError`
67 | **/
68 | function mapGuardedSignalClass(signalClass:SignalClass, commandClass:CommandClass,
69 | guards:GuardClassArray, oneShot:Bool=false):AnySignal;
70 |
71 | /**
72 | Map a Command to an instance of a Signal, with Guards and a fallback Command
73 |
74 | - The `signal` - an instance of ISignal
75 | - The `commandClass` must implement an `execute()` method - executed if the guards approve
76 | - The `fallbackCommandClass` must implement an `execute()` method
77 | - executed if the guards disapprove
78 | - The `guards` must be a class which implements an `approve()` method
79 | - or an `Array` of Classes which implements an `approve()` method
80 |
81 | @param signal The signal instance to trigger this command. Values dispatched by this signal
82 | are available for injection into guards and the command.
83 | @param commandClass The class to instantiate - must have an `execute()` method - executed if
84 | the guards approve
85 | @param fallbackCommandClass The class to instantiate - must have an `execute()` method -
86 | executed if the guards disapprove
87 | @param guards The Classes of the guard or guards to instantiate - must have an
88 | `approve()` method
89 | @param oneshot Unmap the class after execution?
90 | @throws `mmvc.base.ContextError`
91 | **/
92 | function mapGuardedSignalWithFallback(signal:AnySignal, commandClass:CommandClass,
93 | fallbackCommandClass:CommandClass, guards:GuardClassArray, oneShot:Bool=false):Void;
94 |
95 | /**
96 | Map a Command to an instance of a Signal, with Guards and a fallback Command
97 |
98 | - The `signalClass` - a class implementing ISignal
99 | - The `commandClass` must implement an `execute()` method - executed if the guards approve
100 | - The `fallbackCommandClass` must implement an `execute()` method
101 | - executed if the guards disapprove
102 | - The `guards` must be a class which implements an `approve()` method
103 | - or an `Array` of Classes which implements an `approve()` method
104 |
105 | @param signal The signal class to be created - an instance of this class is then available
106 | for injection as a singleton in the main Injector.
107 | @param commandClass The class to instantiate - must have an `execute()` method - executed
108 | if the guards approve
109 | @param fallbackCommandClass The class to instantiate - must have an `execute()` method -
110 | executed if the guards disapprove
111 | @param guards The Classes of the guard or guards to instantiate - must have an
112 | `approve()` method
113 | @param oneshot Unmap the class after execution?
114 | @throws `mmvc.base.ContextError`
115 | **/
116 | function mapGuardedSignalClassWithFallback(signalClass:SignalClass, commandClass:CommandClass,
117 | fallbackCommandClass:CommandClass, guards:GuardClassArray, oneShot:Bool=false):AnySignal;
118 | }
119 |
--------------------------------------------------------------------------------
/src/mmvc/api/IMediator.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | **/
22 |
23 | package mmvc.api;
24 |
25 | /**
26 | The mmvc Mediator contract
27 | **/
28 | interface IMediator
29 | {
30 | /**
31 | Should be invoked by the `IMediatorMap` during `IMediator` registration
32 | **/
33 | function preRegister():Void;
34 |
35 | /**
36 | Should be invoked by the `IMediator` itself when it is ready to be interacted with.
37 |
38 | Override and place your initialization code here.
39 | **/
40 | function onRegister():Void;
41 |
42 | /**
43 | Invoked when the `IMediator` has been removed by the `IMediatorMap`.
44 | **/
45 | function preRemove():Void;
46 |
47 | /**
48 | Should be invoked by the `IMediator` itself when it is ready to for cleanup.
49 |
50 | Override and place your cleanup code here.
51 | **/
52 | function onRemove():Void;
53 |
54 | /**
55 | The `IMediator`'s view component
56 |
57 | @return The view component
58 | **/
59 | function getViewComponent():Dynamic;
60 |
61 | /**
62 | The `IMediator`'s view component
63 |
64 | @param The view component
65 | **/
66 | function setViewComponent(viewComponent:Dynamic):Void;
67 | }
68 |
--------------------------------------------------------------------------------
/src/mmvc/api/IMediatorMap.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.api;
24 |
25 | import mmvc.api.IViewContainer;
26 |
27 | /**
28 | The mmvc MediatorMap contract
29 | **/
30 | interface IMediatorMap
31 | {
32 |
33 | /**
34 | Map an `IMediator` to a view class
35 |
36 | @param viewClassOrName The concrete view class or Fully Qualified classname
37 | @param mediatorClass The `IMediator` class
38 | @param injectViewAs The explicit view Interface or class that the mediator depends on *or*
39 | an Array of such Interfaces/Classes.
40 | @param autoCreate Automatically construct and register an instance of class `mediatorClass`
41 | when an instance of class `viewClass` is detected
42 | @param autoRemove Automatically remove an instance of class `mediatorClass` when its
43 | `viewClass` leaves the ancestory of the context view
44 | **/
45 | function mapView(viewClassOrName:Dynamic, mediatorClass:Class,
46 | ?injectViewAs:Dynamic = null, ?autoCreate:Bool = true, ?autoRemove:Bool = true):Void;
47 |
48 | /**
49 | Unmap a view class
50 |
51 | @param viewClassOrName The concrete view class or Fully Qualified classname
52 | **/
53 | function unmapView(viewClassOrName:Dynamic):Void;
54 |
55 | /**
56 | Create an instance of a mapped `IMediator`
57 |
58 | This will instantiate and register a Mediator for a given View Component. Mediator
59 | dependencies will be automatically resolved.
60 |
61 | @param viewComponent An instance of the view class previously mapped to an `IMediator` class
62 | @return The `IMediator`
63 | **/
64 | function createMediator(viewComponent:Dynamic):IMediator;
65 |
66 | /**
67 | Manually register an `IMediator` instance
68 |
69 | > Registering a Mediator will *not* inject its dependencies. It is assumed that
70 | > dependencies are already satisfied.
71 |
72 | @param viewComponent The view component for the `IMediator`
73 | @param mediator The `IMediator` to register
74 | **/
75 | function registerMediator(viewComponent:Dynamic, mediator:IMediator):Void;
76 |
77 | /**
78 | Remove a registered `IMediator` instance
79 |
80 | @param mediator The `IMediator` to remove
81 | @return The `IMediator` that was removed
82 | **/
83 | function removeMediator(mediator:IMediator):IMediator;
84 |
85 | /**
86 | Remove a registered `IMediator` instance
87 |
88 | @param viewComponent The view that the `IMediator` was registered with
89 | @return The `IMediator` that was removed
90 | **/
91 | function removeMediatorByView(viewComponent:Dynamic):IMediator;
92 |
93 | /**
94 | Retrieve a registered `IMediator` instance
95 |
96 | @param viewComponent The view that the `IMediator` was registered with
97 | @return The `IMediator`
98 | **/
99 | function retrieveMediator(viewComponent:Dynamic):IMediator;
100 |
101 | /**
102 | Check if the view class has been mapped or not
103 |
104 | @param viewClassOrName The concrete view class or Fully Qualified classname
105 | @return Whether this view class has been mapped
106 | **/
107 | function hasMapping(viewClassOrName:Dynamic):Bool;
108 |
109 | /**
110 | Check if the `IMediator` has been registered
111 |
112 | @param mediator The `IMediator` instance
113 | @return Whether this `IMediator` has been registered
114 | **/
115 | function hasMediator(mediator:IMediator):Bool;
116 |
117 | /**
118 | Check if an `IMediator` has been registered for a view instance
119 |
120 | @param viewComponent The view that the `IMediator` was registered with
121 | @return Whether an `IMediator` has been registered for this view instance
122 | **/
123 | function hasMediatorForView(viewComponent:Dynamic):Bool;
124 |
125 | /**
126 | The `IMediatorMap`'s `IViewContainer`
127 |
128 | @return view The `IViewContainer` to use as scope for this `IMediatorMap`
129 | **/
130 | var contextView(default, set):IViewContainer;
131 |
132 | /**
133 | The `IMediatorMap`'s enabled status
134 |
135 | @return Whether the `IMediatorMap` is enabled
136 | **/
137 | var enabled(default, set):Bool;
138 | }
139 |
--------------------------------------------------------------------------------
/src/mmvc/api/ITriggerMap.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.api;
24 |
25 | interface ITriggerMap
26 | {
27 | /**
28 | Map trigger to a command. Trigger can be instance of a class, string or enum value.
29 |
30 | @param trigger Class to trigger the command
31 | @param trigger Command to be triggered
32 | **/
33 | function map(trigger:Dynamic, command:Class):Void;
34 |
35 | /**
36 | Unmap trigger and a command. Trigger can be instance of a class, string or enum value.
37 |
38 | @param trigger Class to unmap
39 | **/
40 | function unmap(trigger:Dynamic, command:Class):Void;
41 |
42 | /**
43 | Dispatch a trigger. A class of the trigger is evaluated and mapped command is executed.
44 |
45 | @param trigger Instance of a class
46 | **/
47 | function dispatch(trigger:Dynamic):Void;
48 | }
--------------------------------------------------------------------------------
/src/mmvc/api/IViewContainer.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.api;
24 |
25 | interface IViewContainer
26 | {
27 | var viewAdded:Dynamic -> Void;
28 | var viewRemoved:Dynamic -> Void;
29 |
30 | function isAdded(view:Dynamic):Bool;
31 | }
32 |
--------------------------------------------------------------------------------
/src/mmvc/api/IViewMap.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.api;
24 |
25 | import mmvc.api.IViewContainer;
26 |
27 | /**
28 | The mmvc ViewMap contract. All IViewMap automatic injections occur AFTER
29 | the view components are added to the stage.
30 | **/
31 | interface IViewMap
32 | {
33 | /**
34 | Map an entire package (including sub-packages) for automatic injection
35 |
36 | @param packageName The substring to compare
37 | **/
38 | function mapPackage(packageName:String):Void;
39 |
40 | /**
41 | Unmap a package
42 |
43 | @param packageName The substring to compare
44 | **/
45 | function unmapPackage(packageName:String):Void;
46 |
47 | /**
48 | Check if a package has been registered for automatic injection
49 |
50 | @param packageName The substring to compare
51 | @return Whether a package has been registered for automatic injection
52 | **/
53 | function hasPackage(packageName:String):Bool;
54 |
55 | /**
56 | Map a view component class or interface for automatic injection
57 |
58 | @param type The concrete view Interface
59 | **/
60 | function mapType(type:Class):Void;
61 |
62 | /**
63 | Unmap a view component class or interface
64 |
65 | @param type The concrete view Interface
66 | **/
67 | function unmapType(type:Class):Void;
68 |
69 | /**
70 | Check if a class or interface has been registered for automatic injection
71 |
72 | @param type The concrete view interface
73 | @return Whether an interface has been registered for automatic injection
74 | **/
75 | function hasType(type:Class):Bool;
76 |
77 | /**
78 | The `IViewMap`'s `IViewContainer`
79 |
80 | @return view The `IViewContainer` to use as scope for this `IViewMap`
81 | **/
82 | var contextView(default, set):IViewContainer;
83 |
84 | /**
85 | The `IViewMap`'s enabled status
86 |
87 | @return Whether the `IViewMap` is enabled
88 | **/
89 | var enabled(default, set):Bool;
90 | }
91 |
--------------------------------------------------------------------------------
/src/mmvc/base/CommandMap.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.base;
24 |
25 | import msignal.Signal;
26 | import minject.Injector;
27 | import minject.ClassMap;
28 | import mmvc.api.ICommand;
29 | import mmvc.api.ICommandMap;
30 |
31 | class CommandMap implements ICommandMap
32 | {
33 | var injector:Injector;
34 | var signalMap:Map>;
35 | var signalClassMap:ClassMap;
36 | var detainedCommands:Map;
37 |
38 | public function new(injector:Injector)
39 | {
40 | this.injector = injector;
41 |
42 | signalMap = new Map();
43 | signalClassMap = new ClassMap();
44 | detainedCommands = new Map();
45 | }
46 |
47 | public function mapSignalClass(signalClass:SignalClass, commandClass:CommandClass, ?oneShot:Bool=false):AnySignal
48 | {
49 | var signal = getSignalClassInstance(signalClass);
50 | mapSignal(signal, commandClass, oneShot);
51 | return signal;
52 | }
53 |
54 | public function mapSignal(signal:AnySignal, commandClass:CommandClass, ?oneShot:Bool=false):Void
55 | {
56 | if (hasSignalCommand(signal, commandClass)) return;
57 |
58 | var signalCommandMap:ClassMap;
59 |
60 | if (signalMap.exists(signal))
61 | {
62 | signalCommandMap = signalMap.get(signal);
63 | }
64 | else
65 | {
66 | signalCommandMap = new ClassMap();
67 | signalMap.set(signal, signalCommandMap);
68 | }
69 |
70 | var me = this;
71 | var callbackFunction = Reflect.makeVarArgs(function(args)
72 | {
73 | me.routeSignalToCommand(signal, args, commandClass, oneShot);
74 | });
75 |
76 | signalCommandMap.set(commandClass, callbackFunction);
77 | signal.add(callbackFunction);
78 | }
79 |
80 | public function unmapSignalClass(signalClass:SignalClass, commandClass:CommandClass)
81 | {
82 | var signal = getSignalClassInstance(signalClass);
83 | unmapSignal(signal, commandClass);
84 | if (!hasCommand(signal))
85 | {
86 | injector.unmap(signalClass);
87 | signalClassMap.remove(signalClass);
88 | }
89 | }
90 |
91 | public function unmapSignal(signal:AnySignal, commandClass:CommandClass)
92 | {
93 | var callbacksByCommandClass = signalMap.get(signal);
94 | if (callbacksByCommandClass == null) return;
95 |
96 | var callbackFunction = callbacksByCommandClass.get(commandClass);
97 | if (callbackFunction == null) return;
98 |
99 | if (!hasCommand(signal)) signalMap.remove(signal);
100 | signal.remove(callbackFunction);
101 | callbacksByCommandClass.remove(commandClass);
102 | }
103 |
104 | function getSignalClassInstance(signalClass:SignalClass):AnySignal
105 | {
106 | if (signalClassMap.exists(signalClass))
107 | {
108 | return cast(signalClassMap.get(signalClass), AnySignal);
109 | }
110 |
111 | return createSignalClassInstance(signalClass);
112 | }
113 |
114 | function createSignalClassInstance(signalClass:SignalClass):AnySignal
115 | {
116 | var injectorForSignalInstance = injector;
117 |
118 | if (injector.hasMapping(Injector))
119 | {
120 | injectorForSignalInstance = injector.getInstance(Injector);
121 | }
122 |
123 | var signal:AnySignal = injectorForSignalInstance.instantiate(signalClass);
124 | injectorForSignalInstance.mapValue(signalClass, signal);
125 | signalClassMap.set(signalClass, signal);
126 |
127 | return signal;
128 | }
129 |
130 | public function hasCommand(signal:AnySignal):Bool
131 | {
132 | var callbacksByCommandClass = signalMap.get(signal);
133 | if (callbacksByCommandClass == null) return false;
134 |
135 | var count = 0;
136 | for (key in callbacksByCommandClass) count ++;
137 | return count > 0;
138 | }
139 |
140 | public function hasSignalCommand(signal:AnySignal, commandClass:Class):Bool
141 | {
142 | var callbacksByCommandClass = signalMap.get(signal);
143 | if (callbacksByCommandClass == null) return false;
144 |
145 | var callbackFunction = callbacksByCommandClass.get(commandClass);
146 | return callbackFunction != null;
147 | }
148 |
149 | function routeSignalToCommand(signal:AnySignal, valueObjects:Array, commandClass:CommandClass, oneshot:Bool)
150 | {
151 | injector.mapValue(AnySignal, signal);
152 |
153 | mapSignalValues(signal.valueClasses, valueObjects);
154 | var command = createCommandInstance(commandClass);
155 | injector.unmap(AnySignal);
156 | unmapSignalValues(signal.valueClasses, valueObjects);
157 | command.execute();
158 | injector.attendedToInjectees.remove(command);
159 |
160 | if (oneshot)
161 | {
162 | unmapSignal(signal, commandClass);
163 | }
164 | }
165 |
166 | function createCommandInstance(commandClass:CommandClass):ICommand
167 | {
168 | return injector.instantiate(commandClass);
169 | }
170 |
171 | function mapSignalValues(valueClasses:Array, valueObjects:Array):Void
172 | {
173 | for (i in 0...valueClasses.length)
174 | {
175 | injector.mapValue(valueClasses[i], valueObjects[i]);
176 | }
177 | }
178 |
179 | function unmapSignalValues(valueClasses:Array, valueObjects:Array)
180 | {
181 | for (i in 0...valueClasses.length)
182 | {
183 | injector.unmap(valueClasses[i]);
184 | }
185 | }
186 |
187 | public function detain(command:ICommand)
188 | {
189 | detainedCommands.set(command, true);
190 | }
191 |
192 | public function release(command:ICommand)
193 | {
194 | if (detainedCommands.exists(command))
195 | {
196 | detainedCommands.remove(command);
197 | }
198 | }
199 | }
200 |
--------------------------------------------------------------------------------
/src/mmvc/base/ContextError.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.base;
24 |
25 | /**
26 | A framework Error implementation
27 | **/
28 | class ContextError
29 | {
30 | public var message:String;
31 | public var id:Int;
32 |
33 | public function new(?message:String = "", ?id:Int = 0)
34 | {
35 | this.message = message;
36 | this.id = id;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/mmvc/base/GuardedCommandMap.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.base;
24 |
25 | import msignal.Signal;
26 | import minject.ClassMap;
27 | import minject.Injector;
28 | import mmvc.api.ICommandMap;
29 | import mmvc.api.IGuardedCommandMap;
30 | import mmvc.api.IGuard;
31 | import mmvc.api.ICommand;
32 |
33 | class GuardedCommandMap extends CommandMap implements IGuardedCommandMap
34 | {
35 | public function new(injector:Injector)
36 | {
37 | super(injector);
38 | }
39 |
40 | public function mapGuardedSignal(signal:AnySignal, commandClass:CommandClass, guards:GuardClassArray, oneShot:Bool=false):Void
41 | {
42 | mapGuardedSignalWithFallback(signal, commandClass, null, guards, oneShot);
43 | }
44 |
45 | public function mapGuardedSignalClass(signalClass:SignalClass, commandClass:CommandClass, guards:GuardClassArray, oneShot:Bool=false):AnySignal
46 | {
47 | return mapGuardedSignalClassWithFallback(signalClass, commandClass, null, guards, oneShot);
48 | }
49 |
50 | public function mapGuardedSignalWithFallback(signal:AnySignal, commandClass:CommandClass, fallbackCommandClass:CommandClass, guards:GuardClassArray, oneShot:Bool=false):Void
51 | {
52 | if (hasSignalCommand(signal, commandClass))
53 | {
54 | return;
55 | }
56 |
57 | var signalCommandMap:ClassMap;
58 |
59 | if (!signalMap.exists(signal))
60 | {
61 | signalCommandMap = new ClassMap();
62 | signalMap.set(signal, signalCommandMap);
63 | }
64 | else
65 | {
66 | signalCommandMap = signalMap.get(signal);
67 | }
68 |
69 | var me = this;
70 | var callbackFunction = Reflect.makeVarArgs(function(args)
71 | {
72 | me.routeSignalToGuardedCommand(signal, args, commandClass, fallbackCommandClass, oneShot, guards);
73 | });
74 |
75 | signalCommandMap.set(commandClass, callbackFunction);
76 | signal.add(callbackFunction);
77 | }
78 |
79 | public function mapGuardedSignalClassWithFallback(signalClass:SignalClass, commandClass:CommandClass, fallbackCommandClass:CommandClass, guards:GuardClassArray, oneShot:Bool=false):AnySignal
80 | {
81 | var signal = getSignalClassInstance(signalClass);
82 | mapGuardedSignalWithFallback(signal, commandClass, fallbackCommandClass, guards, oneShot);
83 | return signal;
84 | }
85 |
86 | function routeSignalToGuardedCommand(signal:AnySignal, valueObjects:Array, commandClass:CommandClass, fallbackCommandClass:CommandClass, oneshot:Bool, guardClasses:GuardClassArray):Void
87 | {
88 | mapSignalValues(signal.valueClasses, valueObjects);
89 |
90 | var approved:Bool = true;
91 |
92 | for (guardClass in guardClasses)
93 | {
94 | var nextGuard:IGuard = injector.instantiate(guardClass);
95 | approved = (approved && nextGuard.approve());
96 |
97 | if ((!approved) && (fallbackCommandClass == null))
98 | {
99 | unmapSignalValues(signal.valueClasses, valueObjects);
100 | return;
101 | }
102 | }
103 |
104 | var commandToInstantiate:Class = approved ? commandClass : fallbackCommandClass;
105 |
106 | var command:ICommand = injector.instantiate(commandToInstantiate);
107 | unmapSignalValues(signal.valueClasses, valueObjects);
108 | command.execute();
109 |
110 | if (oneshot) unmapSignal(signal, commandClass);
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/src/mmvc/base/MediatorBase.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.base;
24 |
25 | import mmvc.api.IMediator;
26 | import msignal.Slot;
27 |
28 | /**
29 | An abstract `IMediator` implementation
30 | **/
31 | @:keepSub class MediatorBase implements IMediator
32 | {
33 | /**
34 | This Mediator's View - used by the mmvc framework internally. You should declare a
35 | dependency on a concrete view component in your implementation instead of working with
36 | this property
37 | **/
38 | public var view:T;
39 |
40 | /*
41 | In the case of deffered instantiation, onRemove might get called before
42 | `onCreationComplete` has fired. This here Bool helps us track that scenario.
43 | **/
44 | var removed:Bool;
45 |
46 | /**
47 | An array of slots to remove when the mediator is removed to ensure garbage collection.
48 | **/
49 | var slots:Array;
50 |
51 | public function new()
52 | {
53 | slots = [];
54 | }
55 |
56 | public function preRegister():Void
57 | {
58 | removed = false;
59 | onRegister();
60 | }
61 |
62 | public function onRegister():Void
63 | {
64 | }
65 |
66 | public function preRemove():Void
67 | {
68 | removed = true;
69 | onRemove();
70 | }
71 |
72 | public function onRemove():Void
73 | {
74 | for (slot in slots) slot.remove();
75 | }
76 |
77 | public function getViewComponent():Dynamic
78 | {
79 | return view;
80 | }
81 |
82 | public function setViewComponent(viewComponent:Dynamic):Void
83 | {
84 | view = viewComponent;
85 | }
86 |
87 | /**
88 | Stores reference to any signal listeners, ensuring they are removed during onRemove
89 |
90 | ```haxe
91 | mediate(something.completed.add(completed));
92 | ```
93 | **/
94 | function mediate(slot:AnySlot)
95 | {
96 | slots.push(slot);
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/mmvc/base/ViewMap.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.base;
24 |
25 | import haxe.ds.ObjectMap;
26 |
27 | import minject.Injector;
28 | import minject.ClassMap;
29 | import mmvc.api.IViewMap;
30 | import mmvc.api.IViewContainer;
31 |
32 | using Lambda;
33 |
34 | /**
35 | An abstract `IViewMap` implementation
36 | **/
37 | class ViewMap extends ViewMapBase implements IViewMap
38 | {
39 | var mappedPackages:Array;
40 | var mappedTypes:ClassMap>;
41 | var injectedViews:ObjectMap<{}, Dynamic>;
42 |
43 | /**
44 | Creates a new `ViewMap` object
45 |
46 | @param contextView The root view node of the context.
47 | @param injector An `Injector` to use for this context
48 | **/
49 | public function new(contextView:IViewContainer, injector:Injector)
50 | {
51 | super(contextView, injector);
52 | mappedPackages = new Array();
53 | mappedTypes = new ClassMap();
54 | injectedViews = new ObjectMap();
55 | }
56 |
57 | public function mapPackage(packageName:String):Void
58 | {
59 | if (mappedPackages.indexOf(packageName) > -1) return;
60 | mappedPackages.push(packageName);
61 | viewListenerCount++;
62 | if (viewListenerCount == 1) addListeners();
63 | }
64 |
65 | public function unmapPackage(packageName:String):Void
66 | {
67 | if (!mappedPackages.remove(packageName)) return;
68 | viewListenerCount--;
69 | if (viewListenerCount == 0) removeListeners();
70 | }
71 |
72 | public function mapType(type:Class):Void
73 | {
74 | if (mappedTypes.exists(type)) return;
75 | mappedTypes.set(type, type);
76 | viewListenerCount++;
77 | if (viewListenerCount == 1) addListeners();
78 | if (contextView != null && Std.is(contextView, type)) injectInto(contextView);
79 | }
80 |
81 | public function unmapType(type:Class):Void
82 | {
83 | if (!mappedTypes.exists(type)) return;
84 | mappedTypes.remove(type);
85 | viewListenerCount--;
86 | if (viewListenerCount == 0) removeListeners();
87 | }
88 |
89 | public function hasType(type:Class):Bool
90 | {
91 | return mappedTypes.exists(type);
92 | }
93 |
94 | public function hasPackage(packageName:String):Bool
95 | {
96 | return mappedPackages.indexOf(packageName) > -1;
97 | }
98 |
99 | override function addListeners():Void
100 | {
101 | if (contextView == null || !enabled) return;
102 | contextView.viewAdded = onViewAdded;
103 | contextView.viewRemoved = onViewAdded;
104 | }
105 |
106 | override function removeListeners():Void
107 | {
108 | if (contextView == null) return;
109 | contextView.viewAdded = null;
110 | contextView.viewRemoved = null;
111 | }
112 |
113 | override function onViewAdded(view:Dynamic):Void
114 | {
115 | if (injectedViews.exists(view)) return;
116 |
117 | for (type in mappedTypes)
118 | {
119 | if (Std.is(view, type))
120 | {
121 | injectInto(view);
122 | return;
123 | }
124 | }
125 |
126 | var len = mappedPackages.length;
127 |
128 | if (len > 0)
129 | {
130 | var className = Type.getClassName(Type.getClass(view));
131 |
132 | for (i in 0...len)
133 | {
134 | var packageName = mappedPackages[i];
135 |
136 | if (className.indexOf(packageName) == 0)
137 | {
138 | injectInto(view);
139 | return;
140 | }
141 | }
142 | }
143 | }
144 |
145 | override function onViewRemoved(view:Dynamic):Void
146 | {
147 | // abstract
148 | }
149 |
150 | function injectInto(view:Dynamic):Void
151 | {
152 | injector.injectInto(view);
153 | injectedViews.set(view, true);
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/src/mmvc/base/ViewMapBase.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.base;
24 |
25 | import minject.Injector;
26 | import mmvc.api.IViewContainer;
27 |
28 | /**
29 | A base ViewMap implementation
30 | **/
31 | class ViewMapBase
32 | {
33 | var injector:Injector;
34 | var viewListenerCount:Int;
35 |
36 | public var contextView(default, set):IViewContainer;
37 | public var enabled(default, set):Bool;
38 |
39 | /**
40 | Creates a new `ViewMap` object
41 |
42 | @param contextView The root view node of the context
43 | @param injector An `Injector` to use for this context
44 | **/
45 | public function new(contextView:IViewContainer, injector:Injector)
46 | {
47 | viewListenerCount = 0;
48 | enabled = true;
49 | this.injector = injector;
50 | // this must come last, see the setter
51 | this.contextView = contextView;
52 | }
53 |
54 | public function set_contextView(value:IViewContainer):IViewContainer
55 | {
56 | if (value != contextView)
57 | {
58 | removeListeners();
59 | contextView = value;
60 | if (viewListenerCount > 0) addListeners();
61 | }
62 | return contextView;
63 | }
64 |
65 | public function set_enabled(value:Bool):Bool
66 | {
67 | if (value != enabled)
68 | {
69 | removeListeners();
70 | enabled = value;
71 | if (viewListenerCount > 0) addListeners();
72 | }
73 | return value;
74 | }
75 |
76 | function addListeners():Void {}
77 | function removeListeners():Void {}
78 |
79 | function onViewAdded(view:Dynamic):Void {}
80 | function onViewRemoved(view:Dynamic):Void {}
81 | }
82 |
--------------------------------------------------------------------------------
/src/mmvc/impl/Actor.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.impl;
24 |
25 | import minject.Injector;
26 |
27 | /**
28 | As part of the MVCS implementation the `Actor` provides core functionality to an applications
29 | various working parts.
30 |
31 | Some possible uses for the `Actor` include, but are no means limited to:
32 |
33 | - Service classes
34 | - Model classes
35 | - Controller classes
36 | - Presentation model classes
37 |
38 | Essentially any class where it might be advantageous to have basic dependency injection supplied
39 | is a candidate for extending `Actor`.
40 | **/
41 | @:keepSub class Actor
42 | {
43 | @inject public var injector:Injector;
44 |
45 | public function new():Void {}
46 | }
47 |
--------------------------------------------------------------------------------
/src/mmvc/impl/Command.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.impl;
24 | import msignal.Signal;
25 | import minject.Injector;
26 | import mmvc.api.ICommandMap;
27 | import mmvc.api.ICommand;
28 | import mmvc.api.IMediatorMap;
29 | import mmvc.api.IViewContainer;
30 |
31 | /**
32 | Abstract MVCS command implementation
33 | **/
34 | @:keepSub class Command implements ICommand
35 | {
36 | @inject public var contextView:IViewContainer;
37 |
38 | @inject public var commandMap:ICommandMap;
39 |
40 | @inject public var injector:Injector;
41 |
42 | @inject public var mediatorMap:IMediatorMap;
43 |
44 | @inject public var signal:AnySignal;
45 |
46 | public function new():Void {}
47 |
48 | public function execute():Void {}
49 | }
50 |
--------------------------------------------------------------------------------
/src/mmvc/impl/Context.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.impl;
24 |
25 | import mmvc.api.ICommandMap;
26 | import mmvc.api.IContext;
27 | import mmvc.api.IMediatorMap;
28 | import mmvc.api.ITriggerMap;
29 | import mmvc.api.IViewContainer;
30 | import mmvc.api.IViewMap;
31 | import mmvc.base.CommandMap;
32 | import mmvc.base.MediatorMap;
33 | import mmvc.base.TriggerMap;
34 | import mmvc.base.ViewMap;
35 | import minject.Injector;
36 | import minject.Reflector;
37 |
38 | /**
39 | Abstract MVCS `IContext` implementation
40 | **/
41 | class Context implements IContext
42 | {
43 | var autoStartup:Bool;
44 |
45 | public var contextView(default, set):IViewContainer;
46 |
47 | public var commandMap(get, null):ICommandMap;
48 |
49 | public var injector(get, null):Injector;
50 |
51 | public var mediatorMap(get, null):IMediatorMap;
52 |
53 | public var reflector(get, null):Reflector;
54 |
55 | public var viewMap(get, null):IViewMap;
56 |
57 | public var triggerMap(get, null):ITriggerMap;
58 |
59 | /**
60 | Abstract Context Implementation
61 |
62 | Extend this class to create a Framework or Application context.
63 |
64 | @param contextView The root view node of the context.
65 | @param autoStartup Should this context automatically invoke it's `startup` method when it's
66 | `contextView` arrives on Stage
67 | **/
68 | public function new(?contextView:IViewContainer=null, ?autoStartup:Bool=true)
69 | {
70 | this.autoStartup = autoStartup;
71 | this.contextView = contextView;
72 | }
73 |
74 | /**
75 | The startup hook. Override this in your Application context.
76 | **/
77 | public function startup():Void {}
78 |
79 | /**
80 | The shutdown hook. Override this in your Application context.
81 | **/
82 | public function shutdown():Void {}
83 |
84 | public function set_contextView(value:IViewContainer):IViewContainer
85 | {
86 | if (contextView != value)
87 | {
88 | contextView = value;
89 | commandMap = null;
90 | mediatorMap = null;
91 | viewMap = null;
92 | triggerMap = null;
93 |
94 | mapInjections();
95 | checkAutoStartup();
96 | }
97 |
98 | return value;
99 | }
100 |
101 | /**
102 | The `Injector` for this `IContext`
103 | **/
104 | public function get_injector():Injector
105 | {
106 | if (injector == null)
107 | {
108 | return createInjector();
109 | }
110 |
111 | return injector;
112 | }
113 |
114 | /**
115 | The `Reflector` for this `IContext`
116 | **/
117 | function get_reflector():Reflector
118 | {
119 | if (reflector == null)
120 | {
121 | reflector = new Reflector();
122 | }
123 |
124 | return reflector;
125 | }
126 |
127 | /**
128 | The `ICommandMap` for this `IContext`
129 | **/
130 | function get_commandMap():ICommandMap
131 | {
132 | if (commandMap == null)
133 | {
134 | commandMap = new CommandMap(createChildInjector());
135 | }
136 |
137 | return commandMap;
138 | }
139 |
140 | /**
141 | The `IMediatorMap` for this `IContext`
142 | **/
143 | function get_mediatorMap():IMediatorMap
144 | {
145 | if (mediatorMap == null)
146 | {
147 | mediatorMap = new MediatorMap(contextView, createChildInjector(), reflector);
148 | }
149 |
150 | return mediatorMap;
151 | }
152 |
153 | /**
154 | The `IViewMap` for this `IContext`
155 | **/
156 | function get_viewMap():IViewMap
157 | {
158 | if (viewMap == null)
159 | {
160 | viewMap = new ViewMap(contextView, injector);
161 | }
162 |
163 | return viewMap;
164 | }
165 |
166 | /**
167 | The `ITriggerMap` for this `IContext`
168 | **/
169 | function get_triggerMap():ITriggerMap
170 | {
171 | if (triggerMap == null)
172 | {
173 | triggerMap = new TriggerMap(injector);
174 | }
175 |
176 | return triggerMap;
177 | }
178 |
179 | /**
180 | Injection Mapping Hook
181 |
182 | Override this in your application context to change the default configuration
183 |
184 | > Beware of collisions in your container
185 | **/
186 | function mapInjections():Void
187 | {
188 | injector.mapValue(Reflector, reflector);
189 | injector.mapValue(Injector, injector);
190 | injector.mapValue(IViewContainer, contextView);
191 | injector.mapValue(ICommandMap, commandMap);
192 | injector.mapValue(IMediatorMap, mediatorMap);
193 | injector.mapValue(IViewMap, viewMap);
194 | injector.mapValue(ITriggerMap, triggerMap);
195 | }
196 |
197 | function checkAutoStartup():Void
198 | {
199 | if (autoStartup && contextView != null)
200 | {
201 | startup();
202 | }
203 | }
204 |
205 | function createInjector():Injector
206 | {
207 | injector = new Injector();
208 | return injector;
209 | }
210 |
211 | function createChildInjector():Injector
212 | {
213 | return injector.createChildInjector();
214 | }
215 | }
216 |
--------------------------------------------------------------------------------
/src/mmvc/impl/Mediator.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.impl;
24 |
25 | import mmvc.base.MediatorBase;
26 | import mmvc.api.IMediatorMap;
27 | import mmvc.api.IViewContainer;
28 | import minject.Injector;
29 |
30 | /**
31 | Abstract MVCS `IMediator` implementation
32 | **/
33 | class Mediator extends MediatorBase
34 | {
35 | @inject public var injector:Injector;
36 |
37 | @inject public var contextView:IViewContainer;
38 |
39 | @inject public var mediatorMap:IMediatorMap;
40 |
41 | public function new()
42 | {
43 | super();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/mmvc/impl/TriggerCommand.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.impl;
24 |
25 | import minject.Injector;
26 |
27 | import mmvc.api.ICommand;
28 | import mmvc.api.ICommandMap;
29 | import mmvc.api.IMediatorMap;
30 | import mmvc.api.ITriggerMap;
31 | import mmvc.api.IViewContainer;
32 |
33 | // @:generic
34 | class TriggerCommand implements ICommand
35 | {
36 | @inject public var contextView:IViewContainer;
37 | @inject public var commandMap:ICommandMap;
38 | @inject public var injector:Injector;
39 | @inject public var mediatorMap:IMediatorMap;
40 | @inject public var triggerMap:ITriggerMap;
41 |
42 | public var trigger:T;
43 |
44 | public function new():Void{}
45 | public function execute(){}
46 |
47 | function dispatch(trigger:Dynamic)
48 | {
49 | triggerMap.dispatch(trigger);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/mmvc/impl/TriggerMediator.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.impl;
24 |
25 | import mmvc.api.ITriggerMap;
26 |
27 | class TriggerMediator extends Mediator
28 | {
29 | @inject public var triggerMap:ITriggerMap;
30 |
31 | function dispatch(trigger:Dynamic)
32 | {
33 | triggerMap.dispatch(trigger);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/target/haxelib/haxedoc.xml.hxml:
--------------------------------------------------------------------------------
1 | -js haxedoc.js
2 | --no-output
3 | -cp src
4 | -lib msignal
5 | -lib minject
6 | --macro include('mmvc')
--------------------------------------------------------------------------------
/test/TestMain.hx:
--------------------------------------------------------------------------------
1 | import massive.munit.client.PrintClient;
2 | import massive.munit.client.RichPrintClient;
3 | import massive.munit.client.HTTPClient;
4 | import massive.munit.client.JUnitReportClient;
5 | import massive.munit.client.SummaryReportClient;
6 | import massive.munit.TestRunner;
7 |
8 | /**
9 | * Auto generated Test Application.
10 | * Refer to munit command line tool for more information (haxelib run munit)
11 | */
12 | class TestMain
13 | {
14 | static function main(){ new TestMain(); }
15 |
16 | public function new()
17 | {
18 | var suites = new Array>();
19 | suites.push(TestSuite);
20 |
21 | #if MCOVER
22 | var client = new mcover.coverage.munit.client.MCoverPrintClient();
23 | var httpClient = new HTTPClient(new mcover.coverage.munit.client.MCoverSummaryReportClient());
24 | #else
25 | var client = new RichPrintClient();
26 | var httpClient = new HTTPClient(new SummaryReportClient());
27 | #end
28 |
29 | var runner:TestRunner = new TestRunner(client);
30 | runner.addResultClient(httpClient);
31 | runner.addResultClient(new HTTPClient(new JUnitReportClient()));
32 |
33 | runner.completionHandler = completionHandler;
34 | runner.run(suites);
35 | }
36 |
37 | /*
38 | updates the background color and closes the current browser
39 | for flash and html targets (useful for continous integration servers)
40 | */
41 | function completionHandler(successful:Bool):Void
42 | {
43 | try
44 | {
45 | #if flash
46 | flash.external.ExternalInterface.call("testResult", successful);
47 | #elseif js
48 | js.Lib.eval("testResult(" + successful + ");");
49 | #elseif (neko || cpp || php)
50 | Sys.exit(0);
51 | #end
52 | }
53 | // if run from outside browser can get error which we can ignore
54 | catch (e:Dynamic)
55 | {
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/test/mmvc/base/TriggerMapTest.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.base;
24 |
25 | import massive.munit.Assert;
26 |
27 | import mmvc.base.support.MockClass;
28 | import mmvc.base.support.MockEnum;
29 | import mmvc.base.support.MockResult;
30 | import mmvc.base.support.TriggerCommand_EnumValue;
31 | import mmvc.base.support.TriggerCommand_Instance;
32 | import mmvc.base.support.TriggerCommand_Int;
33 | import mmvc.base.support.TriggerCommand_MockClass;
34 | import mmvc.base.support.TriggerCommand_String;
35 | import mmvc.impl.Context;
36 |
37 | class TriggerMapTest
38 | {
39 | public function new(){}
40 |
41 | @Before
42 | public function before():Void
43 | {
44 | }
45 |
46 | @After
47 | public function after():Void
48 | {
49 | }
50 |
51 | @Test
52 | public function dispatched_triggers_command():Void
53 | {
54 | MockResult.result = null;
55 | MockResult.count = 0;
56 | var valueClass = new MockClass();
57 | var valueString = "asdwe8fw4f";
58 | var valueEnumValue = MockEnum.A;
59 |
60 | var context = new Context(new mmvc.base.support.TestContextView());
61 | context.triggerMap.map(MockClass, TriggerCommand_MockClass);
62 | context.triggerMap.unmap(MockClass, TriggerCommand_MockClass);
63 | context.triggerMap.map(MockClass, TriggerCommand_MockClass);
64 | context.triggerMap.map(MockClass, TriggerCommand_MockClass);
65 |
66 | context.triggerMap.map(valueString, TriggerCommand_String);
67 | context.triggerMap.unmap(valueString, TriggerCommand_String);
68 | context.triggerMap.map(valueString, TriggerCommand_String);
69 | context.triggerMap.map(valueString, TriggerCommand_String);
70 |
71 | context.triggerMap.map(valueEnumValue, TriggerCommand_EnumValue);
72 | context.triggerMap.unmap(valueEnumValue, TriggerCommand_EnumValue);
73 | context.triggerMap.map(valueEnumValue, TriggerCommand_EnumValue);
74 | context.triggerMap.map(valueEnumValue, TriggerCommand_EnumValue);
75 |
76 | context.triggerMap.dispatch(valueClass);
77 | Assert.areEqual(valueClass, MockResult.result);
78 | Assert.areEqual(2, MockResult.count);
79 |
80 | context.triggerMap.dispatch(valueString);
81 | Assert.areEqual(valueString, MockResult.result);
82 | Assert.areEqual(4, MockResult.count);
83 |
84 | context.triggerMap.dispatch(valueEnumValue);
85 | Assert.areEqual(valueEnumValue, MockResult.result);
86 | Assert.areEqual(6, MockResult.count);
87 | }
88 |
89 | @Test
90 | public function dispatched_class_triggers_command():Void
91 | {
92 | MockResult.result = null;
93 | var mockClass = new MockClass();
94 |
95 | var context = new Context(new mmvc.base.support.TestContextView());
96 | var triggerMap:TriggerMap = cast context.triggerMap;
97 | triggerMap.mapClass(MockClass, TriggerCommand_MockClass);
98 | triggerMap.dispatchClass(mockClass);
99 |
100 | Assert.areEqual(mockClass, MockResult.result);
101 | }
102 |
103 | @Test
104 | public function dispatched_string_triggers_command():Void
105 | {
106 | MockResult.result = null;
107 | var value = "hello world";
108 |
109 | var context = new Context(new mmvc.base.support.TestContextView());
110 | var triggerMap:TriggerMap = cast context.triggerMap;
111 | triggerMap.mapString(value, TriggerCommand_String);
112 | triggerMap.dispatchString(value);
113 |
114 | Assert.areEqual(value, MockResult.result);
115 | }
116 |
117 | @Test
118 | public function dispatched_enumValue_triggers_command():Void
119 | {
120 | MockResult.result = null;
121 |
122 | var context = new Context(new mmvc.base.support.TestContextView());
123 | var triggerMap:TriggerMap = cast context.triggerMap;
124 | triggerMap.mapEnumValue(MockEnum.A, TriggerCommand_EnumValue);
125 | triggerMap.dispatchEnumValue(MockEnum.A);
126 |
127 | Assert.areEqual(MockEnum.A, MockResult.result);
128 | }
129 |
130 | @Test
131 | public function dispatched_int_triggers_command():Void
132 | {
133 | MockResult.result = null;
134 | var value = 1;
135 |
136 | var context = new Context(new mmvc.base.support.TestContextView());
137 | var triggerMap:TriggerMap = cast context.triggerMap;
138 | triggerMap.mapInt(value, TriggerCommand_Int);
139 | triggerMap.dispatchInt(value);
140 |
141 | Assert.areEqual(value, MockResult.result);
142 | }
143 |
144 | @Test
145 | public function dispatched_instance_triggers_command():Void
146 | {
147 | MockResult.result = null;
148 |
149 | var value = new MockClass();
150 |
151 | var context = new Context(new mmvc.base.support.TestContextView());
152 | var triggerMap:TriggerMap = cast context.triggerMap;
153 | triggerMap.mapInstance(value, TriggerCommand_Instance);
154 | triggerMap.dispatchInstance(value);
155 |
156 | Assert.areEqual(value, MockResult.result);
157 | }
158 |
159 | @Test
160 | public function dispatched_invalid_trigger_type_throws_exception():Void
161 | {
162 | var context = new Context(new mmvc.base.support.TestContextView());
163 | var triggerMap:TriggerMap = cast context.triggerMap;
164 | var myDynamic:Dynamic = 1;
165 | var isError:Bool;
166 |
167 | isError = false;
168 | try
169 | {
170 | triggerMap.dispatch(1.1);
171 | }
172 | catch(error:Dynamic)
173 | {
174 | isError = true;
175 | }
176 | Assert.isTrue(isError);
177 |
178 | isError = false;
179 | try
180 | {
181 | triggerMap.dispatch(MockClass);
182 | }
183 | catch(error:Dynamic)
184 | {
185 | isError = true;
186 | }
187 | Assert.isTrue(isError);
188 |
189 | isError = false;
190 | try
191 | {
192 | triggerMap.dispatch(MockEnum);
193 | }
194 | catch(error:Dynamic)
195 | {
196 | isError = true;
197 | }
198 | Assert.isTrue(isError);
199 |
200 | isError = false;
201 | try
202 | {
203 | triggerMap.dispatchInstance("a");
204 | }
205 | catch(error:Dynamic)
206 | {
207 | isError = true;
208 | }
209 | Assert.isTrue(isError);
210 |
211 | isError = false;
212 | try
213 | {
214 | triggerMap.dispatchInstance(myDynamic);
215 | }
216 | catch(error:Dynamic)
217 | {
218 | isError = true;
219 | }
220 | Assert.isTrue(isError);
221 |
222 | isError = false;
223 | try
224 | {
225 | triggerMap.dispatchInstance(MockClass);
226 | }
227 | catch(error:Dynamic)
228 | {
229 | isError = true;
230 | }
231 | Assert.isTrue(isError);
232 |
233 | isError = false;
234 | try
235 | {
236 | triggerMap.dispatchInstance(MockEnum);
237 | }
238 | catch(error:Dynamic)
239 | {
240 | isError = true;
241 | }
242 | Assert.isTrue(isError);
243 | }
244 | }
245 |
--------------------------------------------------------------------------------
/test/mmvc/base/ViewMapTest.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 |
24 | package mmvc.base;
25 |
26 | import massive.munit.Assert;
27 | import minject.Injector;
28 | import minject.Reflector;
29 | import mmvc.base.support.TestView;
30 | import mmvc.base.support.ITestView;
31 | import mmvc.base.support.TestContextView;
32 | import minject.Injector;
33 | import minject.Reflector;
34 | import mmvc.api.IViewMap;
35 | import mmvc.api.IViewContainer;
36 |
37 | class ViewMapTest
38 | {
39 | public function new(){}
40 |
41 | static var INJECTION_NAME = "injectionName";
42 | static var INJECTION_STRING = "injectionString";
43 |
44 | var contextView:TestContextView;
45 | var testView:TestView;
46 | var injector:Injector;
47 | var reflector:Reflector;
48 | var viewMap:IViewMap;
49 |
50 | @Before
51 | public function before():Void
52 | {
53 | contextView = new TestContextView();
54 | testView = new TestView();
55 | injector = new Injector();
56 | reflector = new Reflector();
57 | viewMap = new ViewMap(contextView, injector);
58 |
59 | injector.mapValue(String, INJECTION_STRING, INJECTION_NAME);
60 | }
61 |
62 | @After
63 | public function after():Void
64 | {
65 | contextView = null;
66 | testView = null;
67 | injector = null;
68 | reflector = null;
69 | viewMap = null;
70 | injector = null;
71 | }
72 |
73 | @Test
74 | public function map_type():Void
75 | {
76 | viewMap.mapType(TestView);
77 | var mapped = viewMap.hasType(TestView);
78 | Assert.isTrue(mapped);
79 | }
80 |
81 | @Test
82 | public function unmap_type():Void
83 | {
84 | viewMap.mapType(TestView);
85 | viewMap.unmapType(TestView);
86 | var mapped = viewMap.hasType(TestView);
87 | Assert.isFalse(mapped);
88 | }
89 |
90 | @Test
91 | public function map_type_and_add_to_display():Void
92 | {
93 | viewMap.mapType(TestView);
94 | contextView.addView(testView);
95 | Assert.areEqual(INJECTION_STRING, testView.injectionPoint);
96 | }
97 |
98 | @Test
99 | public function unmap_type_and_add_to_display():Void
100 | {
101 | viewMap.mapType(TestView);
102 | viewMap.unmapType(TestView);
103 | contextView.addView(testView);
104 | Assert.isNull(testView.injectionPoint);
105 | }
106 |
107 | @Test
108 | public function map_type_and_add_to_display_twice():Void
109 | {
110 | viewMap.mapType(TestView);
111 | contextView.addView(testView);
112 | testView.injectionPoint = null;
113 | contextView.removeView(testView);
114 | contextView.addView(testView);
115 | Assert.isNull(testView.injectionPoint);
116 | }
117 |
118 | @Test
119 | public function map_type_of_context_view_should_inject_into_it():Void
120 | {
121 | viewMap.mapType(TestContextView);
122 | Assert.areEqual(INJECTION_STRING, contextView.injectionPoint);
123 | }
124 |
125 | @Test
126 | public function map_type_of_context_view_twice_should_inject_only_once():Void
127 | {
128 | viewMap.mapType(TestContextView);
129 | contextView.injectionPoint = null;
130 | viewMap.mapType(TestContextView);
131 | Assert.isNull(testView.injectionPoint);
132 | }
133 |
134 | @Test
135 | public function map_package():Void
136 | {
137 | viewMap.mapPackage('mmvc');
138 | var mapped = viewMap.hasPackage('mmvc');
139 | Assert.isTrue(mapped);
140 | }
141 |
142 | @Test
143 | public function unmap_package():Void
144 | {
145 | viewMap.mapPackage("mmvc");
146 | viewMap.unmapPackage("mmvc");
147 | var mapped = viewMap.hasPackage("mmvc");
148 | Assert.isFalse(mapped);
149 | }
150 |
151 | @Test
152 | public function mapped_package_is_injected():Void
153 | {
154 | viewMap.mapPackage("mmvc");
155 | contextView.addView(testView);
156 | Assert.areEqual(INJECTION_STRING, testView.injectionPoint);
157 | }
158 |
159 | @Test
160 | public function mapped_absolute_package_is_injected():Void
161 | {
162 | viewMap.mapPackage("mmvc.base.support");
163 | contextView.addView(testView);
164 | Assert.areEqual(INJECTION_STRING, testView.injectionPoint);
165 | }
166 |
167 | @Test
168 | public function unmapped_package_should_not_be_injected():Void
169 | {
170 | viewMap.mapPackage("mmvc");
171 | viewMap.unmapPackage("mmvc");
172 | contextView.addView(testView);
173 | Assert.isNull(testView.injectionPoint);
174 | }
175 |
176 | @Test
177 | public function mapped_package_not_injected_twice_when_removed_and_added():Void
178 | {
179 | viewMap.mapPackage("mmvc");
180 | contextView.addView(testView);
181 | testView.injectionPoint = null;
182 | contextView.removeView(testView);
183 | contextView.addView(testView);
184 |
185 | Assert.isNull(testView.injectionPoint);
186 | }
187 |
188 | @Test
189 | public function map_interface():Void
190 | {
191 | viewMap.mapType(ITestView);
192 | var mapped = viewMap.hasType(ITestView);
193 | Assert.isTrue(mapped);
194 | }
195 |
196 | @Test
197 | public function unmap_interface():Void
198 | {
199 | viewMap.mapType(ITestView);
200 | viewMap.unmapType(ITestView);
201 | var mapped = viewMap.hasType(ITestView);
202 | Assert.isFalse(mapped);
203 | }
204 |
205 | @Test
206 | public function mapped_interface_is_injected():Void
207 | {
208 | viewMap.mapType(ITestView);
209 | contextView.addView(testView);
210 | Assert.areEqual(INJECTION_STRING, testView.injectionPoint);
211 | }
212 |
213 | @Test
214 | public function unmapped_interface_should_not_be_injected():Void
215 | {
216 | viewMap.mapType(ITestView);
217 | viewMap.unmapType(ITestView);
218 | contextView.addView(testView);
219 | Assert.isNull(testView.injectionPoint);
220 | }
221 |
222 | @Test
223 | public function mapped_interface_not_injected_twice_when_removed_and_added():Void
224 | {
225 | viewMap.mapType(ITestView);
226 | contextView.addView(testView);
227 | testView.injectionPoint = null;
228 | contextView.removeView(testView);
229 | contextView.addView(testView);
230 | Assert.isNull(testView.injectionPoint);
231 | }
232 |
233 | @Test
234 | public function setting_enabled_does_stuff():Void
235 | {
236 | viewMap.enabled = true;
237 | viewMap.enabled = false;
238 | viewMap.enabled = true;
239 |
240 | viewMap.contextView = contextView;
241 | viewMap.contextView = null;
242 | viewMap.contextView = contextView;
243 | Assert.isTrue(true);
244 | }
245 | }
246 |
--------------------------------------------------------------------------------
/test/mmvc/base/support/ITestView.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.base.support;
24 |
25 | interface ITestView {}
26 |
--------------------------------------------------------------------------------
/test/mmvc/base/support/MockClass.hx:
--------------------------------------------------------------------------------
1 | package mmvc.base.support;
2 |
3 | class MockClass
4 | {
5 | public function new(){}
6 | }
--------------------------------------------------------------------------------
/test/mmvc/base/support/MockEnum.hx:
--------------------------------------------------------------------------------
1 | package mmvc.base.support;
2 |
3 | enum MockEnum
4 | {
5 | A; B; C;
6 | }
--------------------------------------------------------------------------------
/test/mmvc/base/support/MockResult.hx:
--------------------------------------------------------------------------------
1 | package mmvc.base.support;
2 |
3 | class MockResult
4 | {
5 | public static var result:Dynamic;
6 | public static var count:Int = 0;
7 | }
--------------------------------------------------------------------------------
/test/mmvc/base/support/TestCommand.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.base.support;
24 |
25 | import mmvc.impl.support.ICommandTester;
26 |
27 | class TestCommand implements mmvc.api.ICommand
28 | {
29 | public function new(){}
30 |
31 | @inject
32 | public var testSuite:ICommandTester;
33 |
34 | public function execute():Void
35 | {
36 | testSuite.markCommandExecuted();
37 | }
38 | }
39 |
40 | class TestCommand_InjectSignal implements mmvc.api.ICommand
41 | {
42 | public function new() { }
43 |
44 | @inject
45 | public var testSignal:TestSignal;
46 |
47 | @inject
48 | public var testSuite:ICommandTester;
49 |
50 | public function execute():Void
51 | {
52 | testSuite.markCommandExecuted();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/test/mmvc/base/support/TestCommand1.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.base.support;
24 |
25 | import mmvc.impl.support.ICommandTester;
26 |
27 | class TestCommand1 implements mmvc.api.ICommand
28 | {
29 | public function new(){}
30 |
31 | @inject public var testSuite:ICommandTester;
32 |
33 | public function execute():Void
34 | {
35 | testSuite.markCommandExecuted();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/test/mmvc/base/support/TestCommand2.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.base.support;
24 |
25 | import mmvc.impl.support.ICommandTester;
26 |
27 | class TestCommand2 implements mmvc.api.ICommand
28 | {
29 | public function new(){}
30 |
31 | @inject public var testSuite:ICommandTester;
32 |
33 | @inject public var param1:Int;
34 | @inject public var param2:String;
35 |
36 | public function execute():Void
37 | {
38 | testSuite.markCommand2Executed(param1, param2);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/test/mmvc/base/support/TestContextView.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.base.support;
24 |
25 | import haxe.ds.ObjectMap;
26 |
27 | import mmvc.api.IViewContainer;
28 |
29 | class TestContextView implements IViewContainer
30 | {
31 | var views:ObjectMap<{}, Bool>;
32 |
33 | public var viewAdded:Dynamic -> Void;
34 | public var viewRemoved:Dynamic -> Void;
35 |
36 | @inject("injectionName")
37 | public var injectionPoint:String;
38 |
39 | public function new()
40 | {
41 | views = new ObjectMap<{}, Bool>();
42 | }
43 |
44 | public function addView(view:Dynamic)
45 | {
46 | views.set(view, true);
47 |
48 | if (viewAdded != null)
49 | {
50 | viewAdded(view);
51 | }
52 | }
53 |
54 | public function removeView(view:Dynamic)
55 | {
56 | views.remove(view);
57 |
58 | if (viewRemoved != null)
59 | {
60 | viewRemoved(view);
61 | }
62 | }
63 |
64 | public function isAdded(view:Dynamic)
65 | {
66 | return views.exists(view);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/test/mmvc/base/support/TestSignal.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.base.support;
24 |
25 | import msignal.Signal;
26 |
27 | class TestSignal extends Signal0
28 | {
29 | public function new()
30 | {
31 | super();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/test/mmvc/base/support/TestSignal2.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.base.support;
24 |
25 | import msignal.Signal;
26 |
27 | class TestSignal2 extends Signal2
28 | {
29 | public function new()
30 | {
31 | super(Int, String);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/test/mmvc/base/support/TestView.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.base.support;
24 |
25 | class TestView implements ITestView
26 | {
27 | @inject("injectionName")
28 | public var injectionPoint:String;
29 |
30 | public function new()
31 | {
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/test/mmvc/base/support/TriggerCommand_EnumValue.hx:
--------------------------------------------------------------------------------
1 | package mmvc.base.support;
2 |
3 | class TriggerCommand_EnumValue extends mmvc.impl.TriggerCommand
4 | {
5 | override function execute()
6 | {
7 | MockResult.result = trigger;
8 | MockResult.count++;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/test/mmvc/base/support/TriggerCommand_Instance.hx:
--------------------------------------------------------------------------------
1 | package mmvc.base.support;
2 |
3 | class TriggerCommand_Instance extends mmvc.impl.TriggerCommand
4 | {
5 | override public function execute()
6 | {
7 | MockResult.result = trigger;
8 | MockResult.count++;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/test/mmvc/base/support/TriggerCommand_Int.hx:
--------------------------------------------------------------------------------
1 | package mmvc.base.support;
2 |
3 | class TriggerCommand_Int extends mmvc.impl.TriggerCommand
4 | {
5 | override function execute()
6 | {
7 | MockResult.result = trigger;
8 | MockResult.count++;
9 | }
10 | }
--------------------------------------------------------------------------------
/test/mmvc/base/support/TriggerCommand_MockClass.hx:
--------------------------------------------------------------------------------
1 | package mmvc.base.support;
2 |
3 | class TriggerCommand_MockClass extends mmvc.impl.TriggerCommand
4 | {
5 | override public function execute()
6 | {
7 | MockResult.result = trigger;
8 | MockResult.count++;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/test/mmvc/base/support/TriggerCommand_String.hx:
--------------------------------------------------------------------------------
1 | package mmvc.base.support;
2 |
3 | class TriggerCommand_String extends mmvc.impl.TriggerCommand
4 | {
5 | override function execute()
6 | {
7 | MockResult.result = trigger;
8 | MockResult.count++;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/test/mmvc/impl/ActorTest.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.impl;
24 |
25 | import massive.munit.Assert;
26 |
27 | class ActorTest
28 | {
29 | public function new(){}
30 |
31 | @Test
32 | public function passingTest():Void
33 | {
34 | var actor = new Actor();
35 | Assert.isType(actor, Actor);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/test/mmvc/impl/CommandTest.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.impl;
24 |
25 | import massive.munit.Assert;
26 |
27 | class CommandTest
28 | {
29 | public function new(){}
30 |
31 | @Test
32 | public function create_command()
33 | {
34 | var command = new Command();
35 | Assert.isType(command, Command);
36 | command.execute();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/test/mmvc/impl/ContextTest.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.impl;
24 |
25 | import massive.munit.Assert;
26 | import massive.munit.async.AsyncFactory;
27 | import mmvc.api.IViewContainer;
28 | import mmvc.impl.support.TestContext;
29 | import mmvc.impl.support.ICommandTester;
30 | import mmvc.base.support.TestContextView;
31 |
32 | class ContextTest implements ICommandTester
33 | {
34 | var context:TestContext;
35 | var contextView:TestContextView;
36 | var commandExecuted:Bool;
37 |
38 | public function new(){}
39 |
40 | @Before
41 | public function before():Void
42 | {
43 | commandExecuted = true;
44 | contextView = new TestContextView();
45 | }
46 |
47 | @After
48 | public function after():Void
49 | {
50 | contextView = null;
51 | }
52 |
53 | @Test
54 | public function context_has_view_map():Void
55 | {
56 | var viewMap = context.viewMap;
57 | Assert.areEqual(viewMap, context.viewMap);
58 | }
59 |
60 | @Test
61 | public function autoStartupWithViewComponent():Void
62 | {
63 | context = new TestContext(contextView, true);
64 | Assert.isTrue(context.startupComplete);
65 | }
66 |
67 | @Test
68 | public function autoStartupWithLateViewComponent():Void
69 | {
70 | context = new TestContext(null, true);
71 | Assert.isFalse(context.startupComplete);
72 | context.contextView = contextView;
73 | Assert.isTrue(context.startupComplete);
74 | }
75 |
76 | @Test
77 | public function manualStartupWithViewComponent():Void
78 | {
79 | context = new TestContext(contextView, false);
80 | Assert.isFalse(context.startupComplete);
81 | context.startup();
82 | Assert.isTrue(context.startupComplete);
83 | }
84 |
85 | @Test
86 | public function manualStartupWithLateViewComponent():Void
87 | {
88 | context = new TestContext(null, false);
89 | Assert.isFalse(context.startupComplete);
90 | context.contextView = contextView;
91 | context.startup();
92 | Assert.isTrue(context.startupComplete);
93 | }
94 |
95 | @Test
96 | public function contextInitializationComplete():Void
97 | {
98 | context = new TestContext(contextView);
99 | Assert.isTrue(context.isInitialized);
100 | }
101 |
102 | @Test
103 | public function command_map_works():Void
104 | {
105 | context = new TestContext(contextView);
106 | context.injector.mapValue(ICommandTester, this);
107 |
108 | var signal = new mmvc.base.support.TestSignal();
109 | context.commandMap.mapSignal(signal, mmvc.base.support.TestCommand);
110 | signal.dispatch();
111 |
112 | Assert.isTrue(commandExecuted);
113 | }
114 |
115 | public function markCommandExecuted():Void
116 | {
117 | commandExecuted = true;
118 | }
119 |
120 | public function markCommand2Executed(param1:Int, param2:String){}
121 |
122 | public function resetCommandExecuted():Void
123 | {
124 | commandExecuted = false;
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/test/mmvc/impl/support/ICommandTester.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.impl.support;
24 |
25 | interface ICommandTester
26 | {
27 | function resetCommandExecuted():Void;
28 | function markCommandExecuted():Void;
29 | function markCommand2Executed(param1:Int, param2:String):Void;
30 | }
31 |
--------------------------------------------------------------------------------
/test/mmvc/impl/support/TestActor.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.impl.support;
24 |
25 | import mmvc.impl.Actor;
26 | import mmvc.impl.ActorTest;
27 |
28 | class TestActor extends Actor
29 | {
30 | public function new()
31 | {
32 | super();
33 | }
34 |
35 | public function dispatchTestEvent():Void
36 | {
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/test/mmvc/impl/support/TestCommand.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.impl.support;
24 |
25 | class TestCommand
26 | {
27 | public function new(){}
28 |
29 | @inject
30 | public var testSuite:ICommandTester;
31 |
32 | public function execute():Void
33 | {
34 | testSuite.markCommandExecuted();
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/test/mmvc/impl/support/TestContext.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.impl.support;
24 |
25 | import minject.Injector;
26 | import mmvc.api.IViewContainer;
27 | import mmvc.impl.Context;
28 |
29 | class TestContext extends Context
30 | {
31 | public var isInitialized(get, null):Bool;
32 | public var startupComplete:Bool ;
33 |
34 | public function new(?contextView:IViewContainer=null, ?autoStartup:Bool=true)
35 | {
36 | startupComplete = false;
37 | super(contextView, autoStartup);
38 | }
39 |
40 | public override function startup():Void
41 | {
42 | startupComplete = true;
43 | super.startup();
44 | }
45 |
46 | public function getInjector():Injector
47 | {
48 | return this.injector;
49 | }
50 |
51 | public function get_isInitialized():Bool
52 | {
53 | var initialized:Bool = true;
54 | initialized = (commandMap != null && initialized);
55 | initialized = (mediatorMap != null && initialized);
56 | return initialized;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/test/mmvc/impl/support/TestContextView.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.impl.support;
24 |
25 | import haxe.ds.ObjectMap;
26 |
27 | import mmvc.api.IViewContainer;
28 |
29 | class TestContextView implements IViewContainer
30 | {
31 | var views:ObjectMap<{}, Bool>;
32 |
33 | public var viewAdded:Dynamic -> Void;
34 | public var viewRemoved:Dynamic -> Void;
35 |
36 | @inject("injectionName")
37 | public var injectionPoint:String;
38 |
39 | public function new()
40 | {
41 | views = new ObjectMap();
42 | }
43 |
44 | public function addView(view:Dynamic)
45 | {
46 | views.set(view, true);
47 |
48 | if (viewAdded != null)
49 | {
50 | viewAdded(view);
51 | }
52 | }
53 |
54 | public function removeView(view:Dynamic)
55 | {
56 | views.remove(view);
57 |
58 | if (viewRemoved != null)
59 | {
60 | viewRemoved(view);
61 | }
62 | }
63 |
64 | public function isAdded(view:Dynamic)
65 | {
66 | return views.exists(view);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/test/mmvc/impl/support/TestContextViewMediator.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.impl.support;
24 |
25 | import mmvc.impl.Mediator;
26 | import msignal.Signal;
27 |
28 | class TestContextViewMediator extends Mediator
29 | {
30 | public var registered(default, null):Signal0;
31 |
32 | public function new()
33 | {
34 | super();
35 |
36 | registered = new Signal0();
37 | }
38 |
39 | public override function onRegister():Void
40 | {
41 | registered.dispatch();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/test/mmvc/impl/support/ViewComponent.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.impl.support;
24 |
25 | class ViewComponent
26 | {
27 | public function new()
28 | {
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/test/mmvc/impl/support/ViewComponentAdvanced.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.impl.support;
24 |
25 | class ViewComponentAdvanced extends ViewComponent
26 | {
27 | public function new()
28 | {
29 | super();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/test/mmvc/impl/support/ViewMediator.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.impl.support;
24 |
25 | import mmvc.impl.Mediator;
26 |
27 | class ViewMediator extends Mediator
28 | {
29 | public function new()
30 | {
31 | super();
32 | }
33 |
34 | public override function onRegister():Void
35 | {
36 |
37 | }
38 |
39 | public override function onRemove():Void
40 | {
41 |
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/test/mmvc/impl/support/ViewMediatorAdvanced.hx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012 Massive Interactive
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | package mmvc.impl.support;
24 |
25 | class ViewMediatorAdvanced extends ViewMediator
26 | {
27 | @inject
28 | public var viewAdvanced:ViewComponentAdvanced;
29 |
30 | public function new()
31 | {
32 | super();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/test/targets.hxml:
--------------------------------------------------------------------------------
1 | -main TestMain
2 | -debug
3 | -lib munit
4 | -lib hamcrest
5 | -lib msignal
6 | -lib minject
7 | -cp src
8 | -cp test
9 | -swf-version 9
10 | -swf bin/test/as3_test.swf
11 |
12 | --next
13 |
14 | -main TestMain
15 | -debug
16 | -lib munit
17 | -lib hamcrest
18 | -lib msignal
19 | -lib minject
20 | -cp src
21 | -cp test
22 | -js bin/test/js_test.js
23 |
24 | --next
25 |
26 | -main TestMain
27 | -debug
28 | -lib munit
29 | -lib hamcrest
30 | -lib msignal
31 | -lib minject
32 | -cp src
33 | -cp test
34 | -neko bin/test/neko_test.n
35 |
36 | --next
37 |
38 | -main TestMain
39 | -debug
40 | -lib munit
41 | -lib hamcrest
42 | -lib msignal
43 | -lib minject
44 | -cp src
45 | -cp test
46 | -cpp bin/test/cpp_test
47 |
--------------------------------------------------------------------------------