| View previous topic :: View next topic |
| Author |
Message |
sitron
Joined: 03 Jul 2009 Posts: 23
|
Posted: Thu Jul 09, 2009 9:09 am Post subject: 2 basic examples with Parsley 2.0 |
|
|
Hello!
i put up 2 _very_ basic examples using Parsley 2.0. The first one is using Flex (with the nice flex view wiring feature) and the second one is a pureAS project (ie: not flex).
Both examples are really useless but show a way (among others i guess) of creating a simple MVC structure with Parsley.
http://www.sitronnier.com/blog/parsley-2-basic-flex-example
http://www.sitronnier.com/blog/parsley-2-basic-flash-example
(view source enabled)
Jens, if you have 2 minutes and want to double-check that they are not completely wrong...
Just hope it can help people that feel a bit lost after reading the -fantastic btw- manual... |
|
| Back to top |
|
 |
Jens Halm Site Admin
Joined: 21 Sep 2007 Posts: 1488 Location: Cologne Germany
|
Posted: Thu Jul 09, 2009 12:05 pm Post subject: |
|
|
Thanks a lot. Will have a look at them this evening. _________________ Jens Halm
Spicefactory |
|
| Back to top |
|
 |
darscan
Joined: 12 Jul 2009 Posts: 5
|
Posted: Sun Jul 12, 2009 3:42 pm Post subject: 2 basic examples with Parsley 2.0 |
|
|
Hello Sitron, Jens
I've just started looking into Parsley; I must say, version 2 is looking pretty awesome! I'm still reading the Developer Manual, but the approach seems very much in line with something I've been developing / thinking about called RobotLegs (concepts from PureMVC, but built on Dependency Injection).
Sitron, I've had a quick skim through your two examples. Thanks for putting them together. To make the examples more portable (and hence easier for others to download and import), I would suggest removing references to local folders in your Build Path, and using the SWC folder (libs) instead.
Jens, I would love to know what you think of these examples. Approach, structure, best practice. IE, are these valid, recommended ways to build applications using Parsley?
Many thanks. Excited to find Parsley.. can't wait to get stuck in properly! |
|
| Back to top |
|
 |
Jens Halm Site Admin
Joined: 21 Sep 2007 Posts: 1488 Location: Cologne Germany
|
Posted: Mon Jul 13, 2009 2:41 pm Post subject: |
|
|
Ok, finally found the time to look at these examples. I think they work quite well as a basic example for a minimal setup using the two major features of Parsley (dependency injection and messaging).
I'd have one suggestion for an improvement though: Like already discussed in another thread there usually is no need to push some kind of application-ready event from the outside to the objects living in the container. There are metadata tags for the object lifecycle ([PostConstruct] and [PreDestroy]) which you can use instead. So I would change this:
| Code: | [MessageHandler(selector="ON_APPLICATION_COMPLETE")]
public function onApplicationComplete (event:FlowEvent) : void |
to this:
| Code: | [PostConstruct]
public function init () : void |
You can always rely on the container invoking this method only after all injections have been performed.
Furthermore with Parsley you are not required to work with event type String constants. If a particular event is unique (does not have multiple type constant for the same event class) you can omit the selector attribute and just declare the type of event you are interested in through the method parameter. So you could change this:
| Code: | [MessageHandler(selector="CHANGE_TEXT")]
public function onChangeTextRequest (event:FlowEvent) : void |
to this:
| Code: | [MessageHandler]
public function changeText (event:ChangeTextRequest) : void |
(Note that I also changed the name of the event class to closer reflect the semantics of this type of event). _________________ Jens Halm
Spicefactory |
|
| Back to top |
|
 |
sitron
Joined: 03 Jul 2009 Posts: 23
|
Posted: Wed Jul 15, 2009 2:13 pm Post subject: |
|
|
Darscan, Jens thanks for your comments.
i updated the flex example so that it uses the [PostConstruct] metadata, works like a charm. tx.
obviously i wanted to do the same for the flash example... which was a bit trickier as the view is added to the stage after the context is parsed, so "postconstruct" has already happened. Fixed it using a Added_to_stage event listener to get the initial data.
thanks again. |
|
| Back to top |
|
 |
sitron
Joined: 03 Jul 2009 Posts: 23
|
Posted: Wed Jul 15, 2009 2:21 pm Post subject: |
|
|
oh! and as of the possibility to use event class in the [MessageHandler] instead of binding to a string property... even though i see it as a cool feature, i don't know... i guess i m just used to string constants...
defining an event class with just 1 constant is meaningless in this case, but i usually end up with a few constants per event class. |
|
| Back to top |
|
 |
|