Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Cocktail Extension Annotation: @evented
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib Fixing issue with EventEmitter instance creation. Upgrade version
test/unit
.gitignore
.jshintrc
.npmignore
.travis.yml
Gruntfile.js first commit
README.md
package.json

README.md

Build Status NPM version

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} if the parameter is true, the evented annotation will create and add a new instance of node's events.EventEmitter.
Something went wrong with that request. Please try again.