The Architect

A Technical Architects Thoughts

January 31st, 2010

Its best I quote the creator (Jens Halm www.spicefactory.com) of the Parsley framework to explain contexts an scopes.

Jens Halm:

In Parsley 2.0 every child Context simply shared the message router with its parent Context. This way messages were always dispatched globally. An approach that may turn out to be too simplistic for large and modular applications where a loaded module, a window or a popup may wish to create its own local messaging context while still being able to inject objects from the root Context or dispatching selected messages globally. The scope feature introduced with version 2.1 offers that flexibility, allowing to dispatch into a subset of Contexts only.

In the new default scope setup for Parsley 2.1 there is a global scope that is created for each Context that does not have a parent (usually only the one root Context created at application startup) and then shared will all children of that Context (including grandchildren of course). Additionally each Context will create its own local scope which will not be shared with its children.

Finally you can also create your own custom scope when neither global nor local messaging is the right choice. This may be the case when you create a large AIR window for example. The root window component may create a Context with the root application Context as a parent but then also a few child Contexts for parts within that window. If you then want to setup a messaging scope for that window only you need a scope that spans multiple Contexts but still is not global.

The window scope is a custom scope that exists side-by-side with the two default scopes. Now how do you instruct the framework to create that scope? This has to be done for the root Context of the scope, in this case the two root Contexts for the two window scopes.

———————–

What I have done is to demonstrate the use of scopes in the following example I wrote.

Each Local Box has its own context, and is either added directly as a child to the main context or added as a child to a container context with a custom scope defined.  Click the buttons to see events being dispatched and handled in specified scopes.

The code is also available for your download.

  • admin (4)
  • 3 Responses to “ Parsley Scope Example ”

    1. Nice blog, just book marked it for later reference

    2. Just imagine I read it twice. While I am not as accomplished on this issue, I match with your determinations because they create sense. Thanks and goodluck to you.

    3. hey this blog is great. I’m glad I came by this blog. Maybe I can contribute in the near future. PM ME on Yahoo AmandaLovesYou702 Thank you day658

    Leave a Reply