Skip to content

Instantly share code, notes, and snippets.

@steveluscher
Created August 11, 2011 16:56
Show Gist options
  • Save steveluscher/1140173 to your computer and use it in GitHub Desktop.
Save steveluscher/1140173 to your computer and use it in GitHub Desktop.
A Mojo->Dojo connector; re-implement these methods in another library, and you can use Mojo 2.0 without Dojo.
/* Mojo-Dojo connector */
(function() {
if(typeof mojo == 'undefined') mojo = {};
mojo.addOnUnload = dojo.addOnUnload;
mojo.clone = dojo.clone;
mojo.config = dojo.config;
mojo.connect = dojo.connect;
mojo.declare = dojo.declare;
mojo.destroyElement = dojo._destroyElement;
mojo.disconnect = dojo.disconnect;
mojo.hasClass = dojo.hasClass;
mojo.hitch = dojo.hitch;
mojo.isArray = dojo.isArray;
mojo.isObject = dojo.isObject;
mojo.isString = dojo.isString;
mojo.place = dojo.place;
mojo.provide = dojo.provide;
mojo.publish = dojo.publish;
mojo.query = dojo.query;
mojo.registerModulePath = dojo.registerModulePath;
mojo.require = dojo.require;
mojo.string = dojo.string;
mojo.style = dojo.style;
mojo.subscribe = dojo.subscribe;
mojo.unsubscribe = dojo.unsubscribe;
})();
@jbueza
Copy link

jbueza commented Aug 24, 2011

Yo @steveluscher, have you checked out CoffeeScript out? cc/ @loyalchow

class app.controller.RegistrationController extends mojo.controller.Controller
  addObservers: ->
     @addObserver "li", "click", "ServiceCommand"
  addCommands: ->
     @addCommand "ServiceCommand", "stdlib.command.ServiceCommand"
  addIntercepts: ->

Compiles to

var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
  for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
  function ctor() { this.constructor = child; }
  ctor.prototype = parent.prototype;
  child.prototype = new ctor;
  child.__super__ = parent.prototype;
  return child;
};
app.controller.RegistrationController = (function() {
  __extends(RegistrationController, mojo.controller.Controller);
  function RegistrationController() {
    RegistrationController.__super__.constructor.apply(this, arguments);
  }
  RegistrationController.prototype.addObservers = function() {
    return this.addObserver("li", "click", "ServiceCommand");
  };
  RegistrationController.prototype.addCommands = function() {
    return this.addCommand("ServiceCommand", "stdlib.command.ServiceCommand");
  };
  RegistrationController.prototype.addIntercepts = function() {};
  return RegistrationController;
})();

If Mojo were to go CoffeeScript, we'd be able to detach our dependencies to libraries for features like class creation / inheritance -- things that typically come with the language itself, as well as, make controllers/commands/services easier to write.

The initiative to proxy everything through mojo.* is great but I feel like it's too much of a short-term solution as it doesn't address the problems with writing a controller. I feel like there's little value in being library agnostic if there's no gains on productivity (unless the developers really love jQuery or something). There's just too much cruft in writing a controller, command, service and it should ultimately be easier/quicker/cleaner. Let me know what you think about CoffeeScript though! :o)

You may know this already but Rails 3.1 will land with sass and coffeescript! Exciting times for people who love transpilers!

Things to discuss in regards to a coffeescript rewrite

  • Dependency injection via _____ library
  • Aspect-oriented programming via ____ library
  • Debugging: how do other developers debug the compiled JavaScript back to the CoffeeScript?
  • Performance impact of all the compiled code? CoffeeScript generates a ton of code to help with inheritance and scope correction -- how will this affect the size of a production system?

Doh, now it feels like 2 steps forward, 1 step back -- our core features still need to be tied to a library.

These are just my thoughts on the subject of upgrades to Blast Mojo Framework. I haven't actually dove into coding any prototypes yet.

@steveluscher
Copy link
Author

Yeah. CoffeeScript kind of bums me out. I don't know why. I'm sure I'll warm up to transpilers, someday. Maybe.

Anyway – I agree with everything you've just said, but it doesn't satisfy my original requirements, which were to fire Dojo and hire some other library on a legacy Mojo project.

@jbueza
Copy link

jbueza commented Sep 3, 2011

If you like PHP: http://www.harmony-framework.com/
If you like C#: http://jsil.org/
If you like Skulpt: http://www.skulpt.org/

One day, every developer can write in their favourite language and it'll just compile to JavaScript!

@jbueza
Copy link

jbueza commented Sep 4, 2011

https://gist.github.com/1192286

mojo.define("app.controller.RegistrationController", {
  addObservers: function() {

  },
  addCommands: function() {

  },
  addIntercepts: function() {

  }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment