Tuesday, December 16, 2008

Announcing JumpShip 4.0

JumpShip 4.0 has been released. The new version, although not significantly different from the last, takes a slight philosophical departure from the last. And since it was a significant enough change to possibly break compatibility with older version, I've decided to call it a new major revision.

The most significant change in JumpShip 4.0 is that, now the framework actively discourages the use of Singleton that have become widely popular in other frameworks. Although JumpShip has always touted it's diminished use of Singletons and therefore it's advantage when using it a an application framework or a component framework, the framework itself has never taken an opinion on the use of the Singleton pattern and in face included a few Singletons itself.

There has been a recent backlash against the Singleton pattern in the design pattern world ( See the post on http://www.as3dp.com, Scott Densmore's post, or Miško Hevery's thoughts ). The Singleton has been used as a substitue for global variables ( you know, those things good programmers never use ), and have all of the drawbacks of globals. They can be very convenient but make your code hard to read, hard to test, and hard to debug.

For all these reasons, the latest version of JumpShip has removed ( almost ) all of the Singletons in the Framework. The one exception being the JSRuntimeEnvironment class which is used to make your application behave slightly differently ( logging, throwing errors, etc. ) in a development environment than it does in a production environment ( stability at all costs ).

Eliminating Singletons meant eliminating some classes from the framework, namely the service locator classes, and changing others, JSApplicationState and JSRailsGatewayBase, so that they do not have Singleton implementations.

This has effected the Rails Gateway classes the most and hopefully made the easier to use. You now no longer need to extend JSRailsGatewayBase in order to use it. Instead of having to define a service locator in the implementation, you simply pass in the base path of your Rails app when you create a new JSRailsGatewayBase instance.

The JSApplicationState class is also no longer a Singleton which means you can have as many different state objects as you want.

The other big change in JumpShip 4.0 is that now the JSDataRecord class recognizes when another JSDataRecord instance has been added as an attribute and will automatically listen for data binding events, rebroadcasting them upward if one is received. This allows multi-dimensional data structures that maintain data binding all the way down the tree. Although, JumpShip still encourages flat data structures, there may be occasions when you need data binding for multi-dimensional data.

Finally, JumpShip 4.0 includes improved documentation and a few bug fixes for potential memory leaks.

Saturday, July 19, 2008

Using JumpShip inside Flex. A roadmap.

Using JumpShip inside Flex. A roadmap.

All files can be found at: http://www.youbits.com/jumpship/FlexAndJumpShip.zip for your convenience the entire JumpShip Framework is also included.

        The JSDataModel and JSControllerBase can be used inside of an mxml document as they are. The only trick to using JumpShip in Flex is in using JSViewBase. 

JSViewBase extends Sprite in order to add the ability to add, remove and manipulate DisplayObject's to itself and have those DisplayObjects be part of the Display List. It extends Sprite as opposed to Flex's UIComponent so that it can be used in both Flash and Flex but this decision adds a small amount of complexity for the Flex developer since You can't attach a Sprite directly to most Flex components because all children of a Flex component must extend UIComponent. 

    There are several ways to get past this small annoyance, however. 

    First of all you should realize that you don't need to add JSViewBase to the the Display List in order to use it. JSViewBase is Just a mediator between your Model / Controller and a group of one or more components. It is meant to handle communication between other pieces of the MVC framework. This allows you to build components which don't have any code that is JumpShip Framework specific and wrap them in a JSViewBase instance which takes care of all of the interaction within JumpShip.

    You can create and use JSViewBase just as if it didn't extent Sprite by creating a new instance but not bothering to attach it to the display list. In this case the only thing you loose is the ability to use add components directly to JSViewBase and have them show up on the display list. Instead you would use JSViewBase to store references to it's components which would sit somewhere on the display list. An example of this is provided along with this post.

    Included is a demo Flex project that uses the JSViewBase as a mediator for the Flex compnents contained in the main application.

    Another way to use JSViewBase would be to wrap the class in a proxy component that extends UIComponent. The JSViewBase proxy would just pass all references straight to the JSViewBase instance and the rest of the JumpShip Framework would not know the difference. An example of a JSViewBase proxy class is provided as part of this post.

    A third solution is just to give up the utility function that JSViewBase provides and simply create a new Flex component that implements IView. Although you would loose some of the nicer things that JSViewBase provides, you may decide that those features aren't particularly useful to you anyway. Or you could implement a subset of the JSViewBase functionality in your new component. But as long as your component implements IView, it is capable of fully participating in the JumpShip Framework. Note that IView doesn't require that your implementation be a DisplayObject at all.

    Most MVC frameworks don't even attempt to provide a standard View implementation because as this article illustrates, it can be tricky to implement a View class flexible enough for everyone to use. But JumpShip attempts to go where other frameworks do not, realizing that there is value to establishing conventions even if those conventions get away on rare occasion. But I hope this article illustrates that what may seem like a barrier, really is no big deal when you understand the broader intentions of the JumpShip Framework.

All files can be found at: http://www.youbits.com/jumpship/FlexAndJumpShip.zip for your convenience the entire JumpShip Framework is also included.

Monday, June 16, 2008

JumpShip 3.2 Update Released.

JumpShip 3.2 Update Released.

This minor update of the JumpShip Framework fixes bugs in the JSDataModel and JSViewBase classes.

JumpShip Framework An MVC Based ActionScript with the following features:

  • A Ruby on Rails like Data Mode
  • A Command Pattern Based Controller (similar to ARP and Cairngorm
  • A standardized View with asset loading tools.
  • Model / View Data Binding
  • Controller Before / After filtering
  • Controller Command Cascading (the ability for commands to call other commands).

The following bugs have been fixed:
  • JSDataModel: Fixed a bug in the ‘getItemIndex()’ method that returned an improper value.
  • JSViewBase: Fixed a scope issue that prevented proper data binding.

Wednesday, May 21, 2008

Awesomeness with JSEnumerable and JSArrayEnumerable

JSEnumerable and JSArrayEnumerable are included in the core JumpShip library but are powerful classes in their own right and can even be used outside of the JumpShip Framework.

The enumerable classes provide standard methods for traversing and manipulating collections of data. The methods they define are meant to mirror standard Enumerable modules in other programing languages like Ruby. A lot of the time one of the more tedious tasks of managing data is the need to iterate over the entire data set to find the specific piece of data you need to retrieve or perform a transformation on.

The two enumerable classes in JumpShip each provide the same functionality but in two different ways. JSEnumerable is a class that can be extended by your data model so that it inherits all of the enumerable functionality. JSArrayEnumerable is a static class that manipulates the prototype of the standard Array class so that all Arrays in your app gain the enumerable functionality. Even though prototype manipulation has become a frowned upon practice in AS3, the Array is the most often used class for enumeration. If you want to make extensive use of the enumerable methods, using JSArrayEnumerable can save you a lot of work by simply allowing you to use Array objects throughout your application instead of sub-classes of JSEnumerable. Either way is fine, however, and will allow you to take full advantage of the enumerable methods to do some great tricks with your data. Let's see some examples.

Let's start with some dummy data. We're using JSDataModel as our data collection. It extends JSEnumerable:

var test = new JSDataModel();

var rec1:JSDataRecord = new JSDataRecord();
var rec2:JSDataRecord = new JSDataRecord();
var rec3:JSDataRecord = new JSDataRecord();
var rec4:JSDataRecord = new JSDataRecord();

rec1.create({firstname:"joe", lastname:"smith", purchases:10});
rec2.create({firstname:"jamie", lastname:"doe", purchases:1});
rec3.create({firstname:"jamie", lastname:"scanlon", purchases:50});
rec4.create({firstname:"mickey", lastname:"mouse", purchases:16});


Let's also turn on the JSArrayEnumerable class to make all Array objects enumerable:

JSArrayEnumerable.enable = true;

Now the fun part. Let's say we want a way to quickly compile a list of all of the last names in our data set.

var names:Array = test.pluck("lastname"); // smith,doe,scanlon,mouse

The 'pluck' method pulls out a filed from the records in the collection and presents it as an Array. If you were to think of the data in the form of a table, pluck returns a column. In this case we pluck the 'lastname' column. Now lets say we want to only pull out the last names that contain the letter 's'.

var sortedNames:Array = names.grep( /s/, function(item, index) {
return item;
}); // smith,scanlon,mouse

Notice that we have called the 'grep' method on the 'names' variable which is an Array. Since we have enabled JSArrayEnumerable, all Array's now have this method. If we hadn't enabled JSArrayEnumerable, this would throw a compile error. The 'grep' method is one of the most powerful. It lets you use a RegExp ( Regular Expression ) to filter which records to return in the form of an Array. The capability to filter the records in your data set is only limited by your ability to create a good Regular Expression. The 'grep' method calls toString() on each item in the data set so it is also valuable to make sure that you implement a meaningful toString() method if you are working with complex datatypes, ( here we are only dealing with Strings and Numbers so this isn't an issue ). 

Hopefully you can begin to see the power of using the enumerable classes. We just performed two operations that would normally require a loop and at least one 'if' statement. Here's another example. Let's say we want to get a running total of all customer purchases.

var total:Number = 0;
total = test.inject(total, function(memo, item, index) {
return Number(memo) + Number(item.purchases);
}); // 77

The 'inject' method allows you to specify a variable ( in this case a Number ) that will be submitted to a function for each item in the data set. The function also gets the item in the data set and the index. Whatever is returned by the function is submitted to the next item in the data set. This is a great way to apply a recursive function to every item in the data set. In this case, we use it to tally the values of the 'purchases' field.

JumpShip, an AS3 MVC Framework for Flex and Flash, has been updated.

JumpShip, an AS3 MVC Framework for Flex and Flash, has been updated.

This update features the following changes:
  • Addition of a new core class JSArrayEnumerable which adds Enumerable methods to Array objects.
  • Minor bug fixes for JSDataRecord.

Thursday, April 10, 2008

JumpShip mxmlc Compiler Bug

An email from a member of the community pointed out that certain JumpShip Framework's JSEnumerabler Class and it's descending JSDataModel Class might cause errors due to a compiler bug which is documented here:

It is a bug that has been fixed as of Flex 3.

Wednesday, April 9, 2008

I've ditched my site and turned it into a Flash blog.

I've decided to ditch my two year old web desing site in favor of a Flash blog. http://www.jsjstudios.com.

There you will find articles related to Flash / Flex but not Jumpship specific. There is a lot of great content there already, hope you enjoy it.