Ceejbot

jquery -> ender; some notes.

Yesterday I migrated my project from jquery to Ender. Ender isn’t a library itself, but instead a tool for building javascript libraries from components. It offers something close to the jquery feature set at a much smaller size. If you don’t need everything that jquery does, or if you don’t need the massive backwards compatibility with broken browsers it gives you, ender might be a win.

I had the problem of making my client-side router (davis.js), my client-side templating, and some jquery plugins work.

First, davis.js. The minimal ender build for this needs events, selectors, a dom manipulator, and a dom ready check, aka their “jeesh” package:

ender build bonzo bean qwery domready

I encountered two minor problems. First, davis.js explicitly looks for jquery, not for anything pretending to be jquery in the infamous $. So before you construct your app, tell Davis to use the Ender $:

Davis.$ = $;
var myapp = new Davis.App();
// etc

Second, Bean, the ender events library, doesn’t appear to stop the propagation of delegated events the way jquery does. So Davis needs to do so explicitly in its delegates:

var handler = function (targetExtractor) {
    return function (event) {
      if (differentOrigin(this)) return true
      var request = new Davis.Request (targetExtractor.call(Davis.$(this)));
      Davis.location.assign(request)
      event.stopPropagation();
      event.preventDefault();
      return false;
    };
  };

Davis should now work.

That was the easy part of the migration. Far more annoying was migrating from jquery’s ajax api to reqwest’s.

Next, jquery plugins. Rewrite them. They were not invented by you, so they’re probably awful. Okay, that’s a little unrealistic for some things. If you’re using Bootstrap and its plugins, the ender rewrite will be handy. Note that I couldn’t make its meta-package work. I had to build a library with individual plugins one at a time using ender add.

The other thing I did was rewrite ICanHaz to use the faster mote.js instead of the default mustache javascript implementation, as well as to be agnostic about jquery, zepto, and ender. This isn’t enough code to deserve a github repo, so have it in a gist.

The secret is that mostly nobody notices or cares.

I released a simple node.js tool on npm earlier today. I was surprisingly nervous about it. I’ve been shipping software for a long time now, but always in the context of organizations that agree yes, it’s done, yes, it’s tested, yes, it’s worth using by other people. In this case I knew it was working well enough (it’s been quietly chugging inside my big project for a while now), but I wasn’t sure it was significant enough. Who the heck cares? Then I asked myself why I’d written it. Answer: because I went on npm looking for something suitable and found either things that were too complicated (solving a different problem) or simple enough but with notable bugs. Or even worse: with zero documentation. So what the hell. If one person can run off with my code and find it useful, that’s enough.

My beanstalkd client is probably more notable & useful for more people, but I’m not sure I’m happy with the job worker design yet. Must fiddle some more.

Actually, no. I’m going to go finish this user-facing feature instead. FOCUS.

I should post a lifting update too.

Scratch that previous stack. Ember.js turned out to be heavyweight and confusing. At the moment I’m doing a spike implementation with spine.js and it’s looking far more like a winner despite the CoffeeScript.

In my free time I’m hunting around for deployment tools. Don’t have to solve that problem just yet, however.

Node.js evented i/o is five minutes away.

One. Install the homebrew package manager.
ruby -e “$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)”

Two. Use brew to install node.
brew install node

Three. Install npm, the node package manager.
curl http://npmjs.org/install.sh | sh

Observe that you are now cooking with gas, and it was easy.