Skip to main content

Why did I write a microframework?

I've always been passionate about tools that allow developers makes their lives easier and makes things more fun. Speaking from my agency experience, I've taken the time to do health checks of current developers and analyzed their tool sets. It become clear that there was too much fragmentation between what libraries, APIs, and development approaches -- It's not their fault as each project was being run like a separate silo. To a developer that is being tossed around on to different projects, this is a nightmare. Furthermore, I had this heroic goal of dispelling that nightmare and building a shared vision of a converging toolbox to make us (front-end engineers) faster, more efficient, and reduce the ramp-up time when swapping between different projects/accounts.

At that point, Blast Mojo Framework (v2 rewrite based on jQuery and plugin injection) emerged. We needed a better tool that could provide front-end engineers clear functional separation through implementation silos (controllers). My idea was that all controllers should load asynchronously, never be dependent on each other, as well as, only be mounted when specific contextual elements were on the page (componentized approach to software development). If developers wanted to concatenate all their controllers, they would have the freedom to do so in 'production' mode to indoctrinate a 1-javascript-http-request approach for performance reasons.

In agencies, deployment platforms can be different: sometimes .NET, ATG (Java), PHP, or Python. We needed a way to simply be agnostic to any development environment, which led me to creating a very simple template at the bottom your page:

<script src="js/lib/jquery-1.5.2.min.js"></script>
<script src="../dist/mojo.js"></script>  
<script src="js/app.js"></script>

After taking in many opinions from developers across the company about preferred JavaScript libraries, we crystallized the de-facto groundwork library as jQuery. This was more in line with business decision as most of our developers already attuned to its API, as well as, there were many well-tested plugins that could easily be integrated (carousel, modal dialog). Retraining would've caused some serious concerns, as well as, buy-in from a project management standpoint wouldn't have happened including when their projects are already built on top of jQuery.

Inside app.js, you would find the following:

var app = MOJO.create({ baseSrc: 'js/' });

  .configure('pluginSrc', 'js/lib/plugins/')  
  .configure('plugins', ['jqmodal', 'jcarousel', 'pubsub', 'tmpl'])

  .map('#login-example', [{ controller: "ExampleApp.LoginController" }])

It is highly inspired by Sinatra, Express, and SammyJS. MOJO.create() would return you a new Mojo Application instance. configure() allows you to configure your application. In this particular example, we are telling our application to inject "jqmodal", "jcarousel", and "pubsub" -- All three are well respected jQuery plugins and widely used. This approach provides us with more agility over handling plugin dependencies, you won't need to add new script tags or work with a build script to compile everything (but you certainly can, if you want, it's mainly for convenience).

In the next part we are calling map(), which takes a CSS selector as its first argument (which DOM element do you want to map controllers to?) and an array of controllers in the second argument. This will allow to bind multiple controllers to a particular DOM element, useful for sharing functionality, such as, you could map LoginController as well as CarouselController if they have functional commonality.

The next step would be write your controller:
 * @class   Login Controller
 * @author  Jaime Bueza
MOJO.define('ExampleApp.LoginController', {
  events: [
      ['context', '.btn-login', 'click', 'Login']
    , ['context', '.btn-logout', 'click', 'Logout']    
  methods: {
    Login: function(requestObj) {
      var context = requestObj.getContextElement();
      alert("Logged in from " + this.controllerClass);
    Logout: function(requestObj) {
      alert("Logged out from " + this.controllerClass);
  after: {
    Start: function() {
      console.log("Oh hai! I've initialized myself as Login Controller!");

In the above code piece LoginController, developers can quickly see how structured they are. The first thing they can see is an events array, which tells them which events are binded to which elements within its context. In this case, the context is the DOM element $("#login-example"). Blast Mojo will instinctively use event delegation so if your controller blows away its child elements, you won't have to worry about rebinding.

I will be writing more about my adventures in building better developer tools and developing better approaches that will hopefully make developers' lives easier. Agencies can be a rough place and if we start rethinking our tool-chains and educate each other on more mature software engineering paradigms, we can react quicker to changes and make things easier in the long-run.

In conclusion, while I understand the Blast Mojo is more suited towards agency-style deployments, it primarily focuses on distributed software development teams (for web, mobile, tablet) that want to leverage common software engineering patterns: implementation silos, dependency injection, aspect-oriented programming, as well as, publish subscribe (messaging). It is indeed a more mature approach to front-end engineering and provides structure for your JavaScript so that when you have teammates swapping in and out of different projects, they'll be able to identify where controllers are and how to fix/implement features instinctively -- And best of all, it is built on top of everyone's favourite library, jQuery!

Good luck and have fun,
Jaime Bueza

Jaime Bueza is a software developer in Vancouver, British Columbia, Canada. He has developed web applications for Nintendo, Starbucks, Bacardi, Nike, Electronic Arts, Ritchie Brothers, Kiwi Collections, Cox Communications and Microsoft. When he's not developing useful software that constantly evolves with business requirements, he's creating tutorial videos for aspiring front-end developers.


Popular posts from this blog

TextMate Tutorial: How to add a Strikethrough keybind to your Markdown bundle

Markdown is awesome for quickly generating Readme's on Github. After looking at other projects using the strike tag, I've decided to create a custom keybind for it in my TextMate Markdown bundle. Here's how:

1) Click the + sign on the bottom left and click New Command.
2) Paste this into the editbox and make sure you name your command "Strikethrough".

For the input field, select WORD in the drop down.
For the output field, select "insert as snippet".
As for the keybind, you can totally map it to whatever you're comfortable with but I chose Command-D as it is the same thing in Microsoft Word.


Plenty of Fish - Lessons Learned Meetup

Today, I had the fantastic opportunity of going to a retrospective by Plenty of Fish. As you may know, Plenty of Fish is the largest online dating site and it was all started by a local BCIT graduate named Markus Frind.

Below are notes that were taken on my iPhone. I do apologize as I am continually editing this blogpost.

What is Plenty of Fish? An online dating site.
Why enter the dating market? Back in 2003, it was the only thing that was interesting to build. Markus already knew ASP but wanted to learn more about building web applications with ASP.NET and improve his skills on his resume. 
How do you deal with the network effects problem? In the early days, Plenty of Fish gained traction through Vancouver and Toronto.  There wasn't any silver bullet or magic around it -- Plenty of Fish heavily relied on organic user growth and SEO. The focus was to retain users more than go out and acquire new ones.
What are some early challenges you faced? Markus actually ended up doing every…

World of Warcraft Ninjalist addon: version 0.1 coming along quite nicely

After toying around with more GUI related issues in World of Warcraft's API, I've decided to take a totally different direction. Originally when I architected this addon, I knew in my mind it would be a super simple Console application that a user could easily paste in a name and add it to the database; however, why stop there?

After discovering AceGUI, I can easily start developing UI components in no time! As of right now, I've got it saving data in between game sessions--the interesting part will come when I'll have to develop the web service that will parse the SavedVariable.lua, eliminate duplicate entries, as well as, do a huge merge between their copy and whats on the server's (per realm basis of course).

Here's a screen shot of the responses when adding new Ninjas to your list:
When a user clicks add after entering a name in the textbox, it'll go ahead and add that person to the ninjalist tagging the user's realm and current date/time. Someday, I…