Blog archives

Stapes 0.5 released

I’ve just released version 0.5 of my little Javascript MVC framework, Stapes.js.

New features and improvements in this release are focused around events. The most important one is the ability to add Stapes’ event handlers to any Javascript object or function:

var person = {
    "sayName" : function() {
        this.emit('name', 'Johnny');
    }
};

Stapes.mixinEvents(person);

person.on('name', function(name) {
    console.log('my name is: ' + name);
});

person.sayName(); // 'my name is Johnny'

So you don’t need to create a Stapes object to get event handlers in an object.

mixinEvents also works with functions and the new, operator, just make sure you set the mixin in the constructor.

var Person = function(name) {
    Stapes.mixinEvents(this);
    this.name = name;
}

Person.prototype.sayName = function() {
    this.emit('name', this.name);
};

var p = new Person("Emmylou");

p.on('name', function(name) {
    console.log('my name is: ' + name);
})

p.sayName(); // 'my name is Emmylou'

The cool thing is that all mixed-in events are also thrown on the global Stapes
object, so you can also do stuff like this:

Stapes.on('all', function(data, e) {
    console.log(e.type + ':' + data);
});

p.sayName(); // 'name:Emmylou'

The other big feature of 0.5 is the addition of the off method for event handlers. I haven’t come across many usecases where you need this, but it is an obvious addition if you also have on and emit methods.

So, please check out the new release! What would you like to see in the 0.6 release?

Add a comment