0.0.3 • Published 10 years ago

cocktail-annotation-evented v0.0.3

Weekly downloads
2
License
-
Repository
github
Last release
10 years ago

Build Status

cocktail-annotation-evented

A CocktailJS Annotation Extension

This extension defines a custom annotation to apply Eventable Trait and creates the required glue code into the host class.

Install

npm install cocktail --save
npm install cocktail-annotation-evented --save

Requirements

CocktailJS v0.5.0 or greater is required to use this annotation.

Usage

Using @evented annotation is quite easy. First we need to register the custom annotation with current cocktail instance.

MyClass.js

var cocktail = require('cocktail'),
    Evented  = require('cocktail-annotation-evented');

//register Evented annotation with current cocktail instance
cocktail.use(Evented);

cocktail.mix({
    '@exports': module
    '@as'     : 'class',

    // we can say that our class is evented by passing `true` as a param
    '@evented': true,

    doSomething: function(){
        this.emit('doingSomething', this);
    } 
});

index.js

var MyClass = require('./MyClass'),
    obj;

obj = new MyClass();

obj.on('doingSomething', function(){console.log('obj is doing something!');});

obj.doSomething();

API

  • @evented: parameter
    • parameter: {boolean|Object} if the parameter is true, the evented annotation will create and add a new instance of node's events.EventEmitter. You can as well specify your own EventEmitter instance as a parameter.
0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago