Skip to content
Browse files

API changed, renamed create to enable

  • Loading branch information...
1 parent f27d3bf commit c715f4e17729d6460a8e1bdeda4436664f5a3b6f @bermi committed
Showing with 29 additions and 29 deletions.
  1. +5 −5 README.md
  2. +2 −2 dist/eventify.min.js
  3. +1 −1 lib/ender.js
  4. +3 −3 lib/eventify.js
  5. +1 −1 package.json
  6. +17 −17 test/eventify.test.js
View
10 README.md
@@ -31,7 +31,7 @@ Eventify is a module that can be mixed in to any object, giving the object the a
var object = {};
- Eventify.create(object);
+ Eventify.enable(object);
object.on("alert", function(msg) {
alert("Triggered " + msg);
@@ -40,13 +40,13 @@ Eventify is a module that can be mixed in to any object, giving the object the a
object.trigger("alert", "an event");
-### *create* Eventify.create(destination)
+### *enable* Eventify.enable(destination)
Copies the methods on, off and trigger to the destination object, and returns the destination object.
For example, to make a handy event dispatcher that can coordinate events among different areas of your application:
- var dispatcher = Eventify.create()
+ var dispatcher = Eventify.enable()
### *on* object.on(event, callback, [context])
@@ -93,7 +93,7 @@ Trigger callbacks for the given event, or space-delimited list of events. Subseq
Returns the Eventify object back to its original value. You can use the return value of Eventify.noConflict() to keep a local reference to Eventify. Useful for embedding Eventify on third-party websites, where you don't want to clobber the existing Eventify object.
var localEventify = Eventify.noConflict();
- var model = localEventify.create();
+ var model = localEventify.enable();
Another option is to bind the Eventify library to the window object using a different name. You can do so by declaring the localEventifyLibraryName before loading the Eventify library code. For example:
@@ -101,7 +101,7 @@ Another option is to bind the Eventify library to the window object using a diff
<script>var localEventifyLibraryName = 'EventManager';</script>
<script src="/dist/eventify.min.js" type="text/javascript"></script>
<script>
- var dispatcher = EventManager.create();
+ var dispatcher = EventManager.enable();
</script>
View
4 dist/eventify.min.js
@@ -1,7 +1,7 @@
-// eventify - v0.2.1 (2012-05-17)
+// eventify - v0.3.1 (2012-05-17)
// -----------------
// Copyright(c) 2010-2012 Jeremy Ashkenas, DocumentCloud
// Copyright(c) 2012 Bermi Ferrer <bermi@bermilabs.com>
// MIT Licensed
-(function(a){"use strict";var b,c=a.Eventify,d=/\s+/,e=a.localEventifyLibraryName||"Eventify",f=Object.keys||function(a){if(typeof a!="object"&&typeof a!="function"||a===null)throw new TypeError("keys() called on a non-object");var b,c=[];for(b in a)a.hasOwnProperty(b)&&(c[c.length]=b);return c},g=function(a){return this};g.prototype={version:"0.2.1",on:function(a,b,c){var e,f,g;if(!b)return this;a=a.split(d),e=this._callbacks||(this._callbacks={}),f=a.shift();while(f)g=e[f]||(e[f]=[]),g.push(b,c),f=a.shift();return this},off:function(a,b,c){var e,g,h,i;if(!(g=this._callbacks))return this;if(!(a||b||c))return delete this._callbacks,this;a?a=a.split(d):a=f(g),e=a.shift();while(e){if(!(h=g[e])||!b&&!c){delete g[e],e=a.shift();continue}for(i=h.length-2;i>=0;i-=2)b&&h[i]!==b||c&&h[i+1]!==c||h.splice(i,2);e=a.shift()}return this},trigger:function(a){var b,c,e,f,g,h,i,j;if(!(c=this._callbacks))return this;j=[],a=a.split(d);for(f=1,g=arguments.length;f<g;f=f+1)j[f-1]=arguments[f];b=a.shift();while(b){i=c.all,i&&(i=i.slice()),e=c[b],e&&(e=e.slice());if(e)for(f=0,g=e.length;f<g;f+=2)e[f].apply(e[f+1]||this,j);if(i){h=[b].concat(j);for(f=0,g=i.length;f<g;f+=2)i[f].apply(i[f+1]||this,h)}b=a.shift()}return this},noConflict:function(){return a.Eventify=c,this},create:function(a){var b,c,d=["on","off","trigger"];a=a||{};for(b=0,c=d.length;b<c;b=b+1)a[d[b]]=this[d[b]];return a}},b=new g,(typeof exports!="undefined"?exports:a)[e]=new g,typeof exports!="undefined"&&typeof module!="undefined"&&module.exports&&(module.exports=new g)})(this);
+(function(a){"use strict";var b,c=a.Eventify,d=/\s+/,e=a.localEventifyLibraryName||"Eventify",f=Object.keys||function(a){if(typeof a!="object"&&typeof a!="function"||a===null)throw new TypeError("keys() called on a non-object");var b,c=[];for(b in a)a.hasOwnProperty(b)&&(c[c.length]=b);return c},g=function(a){return this};g.prototype={version:"0.3.1",on:function(a,b,c){var e,f,g;if(!b)return this;a=a.split(d),e=this._callbacks||(this._callbacks={}),f=a.shift();while(f)g=e[f]||(e[f]=[]),g.push(b,c),f=a.shift();return this},off:function(a,b,c){var e,g,h,i;if(!(g=this._callbacks))return this;if(!(a||b||c))return delete this._callbacks,this;a?a=a.split(d):a=f(g),e=a.shift();while(e){if(!(h=g[e])||!b&&!c){delete g[e],e=a.shift();continue}for(i=h.length-2;i>=0;i-=2)b&&h[i]!==b||c&&h[i+1]!==c||h.splice(i,2);e=a.shift()}return this},trigger:function(a){var b,c,e,f,g,h,i,j;if(!(c=this._callbacks))return this;j=[],a=a.split(d);for(f=1,g=arguments.length;f<g;f=f+1)j[f-1]=arguments[f];b=a.shift();while(b){i=c.all,i&&(i=i.slice()),e=c[b],e&&(e=e.slice());if(e)for(f=0,g=e.length;f<g;f+=2)e[f].apply(e[f+1]||this,j);if(i){h=[b].concat(j);for(f=0,g=i.length;f<g;f+=2)i[f].apply(i[f+1]||this,h)}b=a.shift()}return this},noConflict:function(){return a.Eventify=c,this},enable:function(a){var b,c,d=["on","off","trigger"];a=a||{};for(b=0,c=d.length;b<c;b=b+1)a[d[b]]=this[d[b]];return a}},b=new g,(typeof exports!="undefined"?exports:a)[e]=new g,typeof exports!="undefined"&&typeof module!="undefined"&&module.exports&&(module.exports=new g)})(this);
View
2 lib/ender.js
@@ -1,6 +1,6 @@
(function ($) {
var Events = require('events');
$.ender({
- eventify: Events.create
+ eventify: Events.enable
});
}(ender));
View
6 lib/eventify.js
@@ -10,7 +10,7 @@
// to an event; trigger`-ing an event fires all callbacks in succession.
//
// var object = {};
-// Eventify.create(object);
+// Eventify.enable(object);
// object.on('expand', function(){ alert('expanded'); });
// object.trigger('expand');
(function (root) {
@@ -55,7 +55,7 @@
Eventify.prototype = {
- version: "0.2.1",
+ version: "0.3.1",
// Event Functions
// -----------------
@@ -183,7 +183,7 @@
},
// Adds the methods on, off and trigger to a target Object
- create: function (target) {
+ enable: function (target) {
var i, len,
methods = ['on', 'off', 'trigger'];
target = target || {};
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "eventify",
- "version": "0.2.1",
+ "version": "0.3.1",
"description": "Lightweight module that can be mixed in to any object in order to provide it with custom events. For node.js and the browser. Based on Backbone.Events",
"author": "Bermi Ferrer <bermi@bermilabs.com>",
"keywords": [
View
34 test/eventify.test.js
@@ -23,7 +23,7 @@
describe("On and trigger", function () {
var obj = { counter: 0 };
- Eventify.create(obj);
+ Eventify.enable(obj);
it('should increment counter', function () {
obj.on('event', function () { obj.counter += 1; });
obj.trigger('event');
@@ -40,7 +40,7 @@
describe("Binding and triggering multiple events", function () {
var obj = { counter: 0 };
- Eventify.create(obj);
+ Eventify.enable(obj);
obj.on('a b c', function () { obj.counter += 1; });
@@ -61,7 +61,7 @@
it('should trigger all for each event', function () {
var a, b, obj = { counter: 0 };
- Eventify.create(obj);
+ Eventify.enable(obj);
obj.on('all', function (event) {
obj.counter = obj.counter + 1;
if (event === 'a') {
@@ -82,7 +82,7 @@
describe("On, then unbind all functions", function () {
var callback,
obj = { counter: 0 };
- Eventify.create(obj);
+ Eventify.enable(obj);
callback = function () { obj.counter = obj.counter + 1; };
obj.on('event', callback);
obj.trigger('event');
@@ -96,7 +96,7 @@
describe("Bind two callbacks, unbind only one", function () {
var callback,
obj = { counterA: 0, counterB: 0 };
- Eventify.create(obj);
+ Eventify.enable(obj);
callback = function () { obj.counterA = obj.counterA + 1; };
obj.on('event', callback);
obj.on('event', function () { obj.counterB = obj.counterB + 1; });
@@ -114,7 +114,7 @@
describe("Unbind a callback in the midst of it firing", function () {
var callback,
obj = {counter: 0};
- Eventify.create(obj);
+ Eventify.enable(obj);
callback = function () {
obj.counter = obj.counter + 1;
obj.off('event', callback);
@@ -130,7 +130,7 @@
describe("Two binds that unbind themeselves", function () {
var obj = { counterA: 0, counterB: 0 };
- Eventify.create(obj);
+ Eventify.enable(obj);
function incrA() {
obj.counterA = obj.counterA + 1;
obj.off('event', incrA);
@@ -162,7 +162,7 @@
expect(true).to.be(true);
done();
};
- obj = Eventify.create();
+ obj = Eventify.enable();
obj.on('event', function () {
this.assertTrue();
}, (new TestClass()));
@@ -172,7 +172,7 @@
describe("nested trigger with unbind", function () {
var obj = { counter: 0 };
- Eventify.create(obj);
+ Eventify.enable(obj);
function incr1() {
obj.counter = obj.counter + 1;
obj.off('event', incr1);
@@ -193,7 +193,7 @@
describe("callback list is not altered during trigger", function () {
var counter = 0,
- obj = Eventify.create();
+ obj = Eventify.enable();
function incr() {
counter = counter + 1;
}
@@ -218,7 +218,7 @@
describe("#1282 - 'all' callback list is retrieved after each event.", function () {
var counter = 0,
- obj = Eventify.create();
+ obj = Eventify.enable();
function incr() {
counter = counter + 1;
}
@@ -232,12 +232,12 @@
});
describe("if no callback is provided, `on` is a noop", function () {
- Eventify.create().on('test').trigger('test');
+ Eventify.enable().on('test').trigger('test');
});
describe("remove all events for a specific context", function () {
it("should remove context", function (done) {
- var obj = Eventify.create();
+ var obj = Eventify.enable();
obj.on('x y all', function () {
expect(true).to.be(true);
});
@@ -252,7 +252,7 @@
describe("remove all events for a specific callback", function () {
it("should remove callback", function (done) {
- var obj = Eventify.create();
+ var obj = Eventify.enable();
function success() {
expect(true).to.be(true);
}
@@ -269,7 +269,7 @@
describe("off is chainable", function () {
it("should be chainable", function () {
- var obj = Eventify.create();
+ var obj = Eventify.enable();
// With no events
expect(obj.off() === obj).to.be(true);
// When removing all events
@@ -283,7 +283,7 @@
describe("#1310 - off does not skip consecutive events", function () {
it("should not skip", function (done) {
- var obj = Eventify.create();
+ var obj = Eventify.enable();
obj.on('event', function () { expect(true).to.be(false); }, obj);
obj.on('event', function () { expect(true).to.be(false); }, obj);
obj.off(null, null, obj);
@@ -294,7 +294,7 @@
describe("Additional parameters", function () {
it("should include aditional parameters", function (done) {
- var obj = Eventify.create(),
+ var obj = Eventify.enable(),
param1 = "one",
param2 = ["two"];
obj.on('event', function (one, two) {

0 comments on commit c715f4e

Please sign in to comment.
Something went wrong with that request. Please try again.