Ben Bradley
  • Fur Sale

NodeJS Class for Eventing

9/26/2013

1 Comment

 
I've been doing some work lately with the Isogenic Engine framework and it's exposed me to the concept of classes in JavaScript.  Now, classes are nothing new to programming, but I've never really been formally introduced to them so it was a big eye-opener for me to learn about how they work.

What I found out was that I had actually been using classes for a while since Backbone is built on the concept.  But actually understanding the application of the concept was a great help in advancing my understanding.

The short version (as I interpret it) is that with classes, a developer can write well-defined and scoped code and then make that well-written code available elsewhere in the application without re-writing it.  As with most concepts in coding, actual code is often more helpful than textual descriptions, so I'd recommend looking at a blog article that John Resig wrote about this very topic and even shared a smallish bit of code to make it easy to use classes.

I thought this was pretty awesome and I immediately set about putting it to use in some code that I was working on at the time.  At the moment, the most useful class that I've written is one that allows for simply inheriting the EventEmitter in NodeJS.

Using the 'class.extend' module, which is a copy/paste of Resig's code, I created this batch of code that I use as the parent for most of my other classes so that the resulting objects can emit and consume events.

With this pattern, I can write very focused classes and tie them together with something of an event bus where data is passed back and forth in an evented manner.   Nesting callbacks is gone, but tracking event chains is in.
1 Comment

Trolling the User

9/18/2013

0 Comments

 
I've been developing an app that is strictly for the use of one guy and all it does is provide a graphical interface for the guy so that he doesn't have to learn how to interact with a Mongo database.  This one user started complaining recently that the app is too plain, "There's not enough color on it," he says.  "Can you put a tye-dyed background on it or something?"

"Sure," I say as I look for a picture of a TIE fighter exploding.  A minute later I send the user a note saying, "Ok, it's got a TIE die background now."

The joke lasted for a day and he started complaining that the picture was too distracting.  He asked that I remove the picture and expand the text boxes to fill the space that the picture was consuming.

"Ok," I said again.  But this time, I modified a troll-face picture and stuck it in the background of each textarea in the app.  It's pretty faint, so I doubt he'll notice it, but I get a kick out of it =)
Picture
0 Comments
    Picture
    I am a geek.  This is where I share my geekery.
    • GitHub.com
    • JSBin.com
    • NodeJS.org
    • npmjs.org

    Archives

    December 2013
    September 2013
    June 2013
    May 2013

    Categories

    All

    RSS Feed

Powered by Create your own unique website with customizable templates.