0.4.3 • Published 11 years ago

asEvented v0.4.3

Weekly downloads
41
License
-
Repository
github
Last release
11 years ago

#asEvented

Description

asEvented is a micro event emitter which provides the observer pattern to JavaScript object. It works in the browser and server (node.js). The code follows a functional mixins pattern described by Angus Croll a-fresh-look-at-javascript-mixins.

Usage

In browser include single JavaScript file:

<script src="asevented.js"></script>

On server install asEvented via npm first:

npm install asEvented

and then include it in your project with:

var asEvented = require('asEvented');

##Example Usage Define the constructor which will make use of asEvented:

function Model() {
  this.id = 0;
}

Add (mixin) asEvented functionality to Model with:

asEvented.call(Model.prototype);

model now has access to trigger, bind and unbind functions

Add some functions to Model:

Model.prototype.setId = function (id) {
  this.id = id;
  this.trigger('change:id', id); // Model has now access to trigger
}

Create a new object and bind to change:id event:

var model = new Model();
model.bind('change:id', function (id) {
  console.log('id changed to: ' +  id);
});

Set a few model ids in order to trigger change:id event:

model.setId(1);
model.setId(2);
model.setId(3);

##License:

0.4.3

11 years ago

0.4.2

11 years ago

0.4.1

11 years ago

0.4.0

11 years ago

0.3.3

12 years ago

0.3.2

12 years ago

0.3.1

12 years ago

0.3.0

12 years ago

0.2.1

12 years ago

0.2.0

12 years ago

0.1.0

12 years ago

0.0.1

13 years ago