Latest posts
0

Dependency injection for JavaScript with injector.js

Do you recognise the problem with gaining access to an object that is defined somewhere else in the application than where you will want to use it? In order to do this you either need to pass a reference along throughout your application or pollutte your global namespace. Say for example a UserModel having properties such as username, email, etc… This UserModel is populated with data once the user provides this information or as a result from a service call to the backend. The username might be needed in multiple views throughout your application and it would not be elegant nor safe to put an instance of this in the global namespace by doing something like window.userModel = new UserModel();. Neither would it be elegant to pass along the instance of the model to all the views that need access to it. Especially not when the view that needs access is nested deep down inside a chain of other views. It is not practical and on top of that it couples the whole chain.

This problem is not new and it is something that is addressed in many programming languages in many different ways. In the days where I still worked as a Flash developer SwiftSuspenders offered me the solution to this problem. I really felt bad that there was no such thing yet for JavaScript (in 2010). Fortunately I had the privilege to be working with Michiel van der Ros on a client project. We both sat down and created a very simplistic way to make this work for our project.

A while after completing the project with Michiel I silently started working on an open sourced version and injector.js was born. SwiftSuspenders clearly inspired me hence the many similarities between both API’s.

Read the rest of this entry »

17

Robotlegs Away3D 4 Broomstick integration with a wink at Unity

Since the beginning of this year I got in touch with Robotlegs thanks to Erik van Nieuwburg. In case you have’t heard of Robotlegs or haven’t used it, you should really check it out sometime soon. It is a micro framework that helps separating your application tiers in a very elegant way. I’ve developed a couple of projects myself using Robotlegs and I really have to say that I’m loving it. Once you know the trick, it seems like a natural way develop your applications like this. It makes your life as a developer a lot easier.

Once I got this into my fingers I suddenly realized that how Robotlegs handles views with mediators is somehow similar to how Unity works with game objects (models aka views in Robotlegs) and components (scripts/predefined functionality aka mediators in Robotlegs). The big difference between Unity components and mediators in Robotlegs is that Unity can work with multiple components on an object and Robotlegs doesn’t.

With the recent public beta release of Flash Player 11 (Incubator) and SDK with the Molehill functionality (native 3D), the alpha release of Away3D 4 “Broomstick” and the announcement by Unity regarding Flash publishing, it became time to get started with this experiment.

Read the rest of this entry »

Older posts