Spicefactory Forum Index Spicefactory
Discuss Spicefactory Open Source Projects
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

2 basic examples with Parsley 2.0

 
Post new topic   Reply to topic    Spicefactory Forum Index -> Spicefactory - General Discussions
View previous topic :: View next topic  
Author Message
sitron



Joined: 03 Jul 2009
Posts: 23

PostPosted: Thu Jul 09, 2009 9:09 am    Post subject: 2 basic examples with Parsley 2.0 Reply with quote

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
View user's profile Send private message
Jens Halm
Site Admin


Joined: 21 Sep 2007
Posts: 1488
Location: Cologne Germany

PostPosted: Thu Jul 09, 2009 12:05 pm    Post subject: Reply with quote

Thanks a lot. Will have a look at them this evening.
_________________
Jens Halm
Spicefactory
Back to top
View user's profile Send private message
darscan



Joined: 12 Jul 2009
Posts: 5

PostPosted: Sun Jul 12, 2009 3:42 pm    Post subject: 2 basic examples with Parsley 2.0 Reply with quote

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
View user's profile Send private message
Jens Halm
Site Admin


Joined: 21 Sep 2007
Posts: 1488
Location: Cologne Germany

PostPosted: Mon Jul 13, 2009 2:41 pm    Post subject: Reply with quote

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
View user's profile Send private message
sitron



Joined: 03 Jul 2009
Posts: 23

PostPosted: Wed Jul 15, 2009 2:13 pm    Post subject: Reply with quote

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
View user's profile Send private message
sitron



Joined: 03 Jul 2009
Posts: 23

PostPosted: Wed Jul 15, 2009 2:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Spicefactory Forum Index -> Spicefactory - General Discussions All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group