HTML5 Brief: in one paragraph | Alex Kessinger

Hoptoad and Javascript, Sitting in a Tree, S-E-N-D-I-N-G – GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS

Hoptoad and Javascript, Sitting in a Tree, S-E-N-D-I-N-G – GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS.

I’m really excited about this new feature of HopToad.  I’ve played around with ExceptionHub but it was missing some important features like team management.  Leveraging HopToad to do this kind of JavaScript/browser level error tracking really cleanly combines two useful and similar tools for debugging a running system.

I should add that I echo the concerns of some of the commenters on the linked to blog post about security concerns.  It would be helpful if ThoughtBot followed this up with a post to address this concern in a bit more detail.

All in all though, this is nice

Back to jQuery

So I tried Red for a while (short while) and was all excited and thought it was really cool and I’d be using it forever. Then I tried to make a Ajax call to a rails app and got back JSON, crap. Red doesn’t support parsing JSON. I eventually figured it out and made a pretty cool billing summary widget using Red. But that took me a few days. And it was really hard. Much harder than it needed to be.

I like what Red was trying to do, but looking back I think I knew it was too good to be true. It’s not quite there and requires a lot of hacking to do most practical things. I’m now using jQuery. I reimplemented the billing summary using jQuery in a couple of hours, and most of that time was spent re-learning jQuery. I’m actually pretty happy with it after using it for a few weeks. I thought I would always return to Prototype.

In my excitement for learning a new tool I discovered the extension jQuery UI and their Themeroller. This has got to be one of the cooler javascript library extensions that I’ve seen. ExtJS tries to provide a will UI toolkit and has a theme API, but the Themeroller for jQuery UI is really sweet and super simple. As a basis for a back office admin it is ideal, and I can see a number of opportunities in a broader set of situations. The icon library alone has made producing simple, intuitive interfaces really easy.

JSON for Red

I’ve been playing around more with Red.  I alternate between really liking it and totally pulling my hair out.  On a order form app that I’m building I made some very quick work of a dynamically updating billing summary div.  It came together very quickly until I added the AJAX piece.  AJAX support in Red is actually very good, but JSON support is non-existent.  This made Ryan a sad boy.  I dug around to see what other people have done and found that they haven’t done much.  There is some stub code for a Request::JSON that my be what I’m looking for at some point, but I need it now.  So here is what I did:

class Module
  def define_method(sym, &block)
    `this.prototype['m$'+sym.__value__]=block.__block__.__unbound__`
    `Red.updateChildren(this)`
    `Red.updateIncluders(this)`
    return `block`
  end
end

class Object
  def self.from_json(text)
    ret = Object.new
    meths = []
    `var v = eval("("+#{text}.__value__+")")`
    `for(var member in v){#{meths}.push(new Array($q(member), $q(v[member])))}`
    meths.each do |meth|
      ret.class.send(:define_method, meth[0]) do
        meth[1]
      end
    end
    return ret
  end
end

Now doing a simple AJAX call that returns JSON becomes really easy:

@req = Request.new(:url => '/orders')
@req.upon(:response) do |response|
  new_data = Object.from_json(response.text)
  @summary = new_data.summary
  @subtotal = new_data.subtotal
  @total = new_data.total
end
@req.execute(:data => {'plan_id' => @plan, 'promo' => @promo})

A few things to note here.  The section that defines `define_method` on `Module` is actually back ported from the current master branch of Red.  This works pretty well, though I haven’t tried it with a JSON string that describes a living object.  But I don’t think it’s too far from being able to handle that.

Red its like Ruby for Javascript

If you had asked me about doing this 6 months ago I would have said that it would be worth it.  It would be too hard and be a ton of work to get it functional and even then it wouldn’t be good enough to actually use.  After seeing this video I’m glad I am wrong.  This is totally sweet.