Permalink
Browse files

API changed, renamed create to enable

  • Loading branch information...
bermi committed May 17, 2012
1 parent f27d3bf commit c715f4e17729d6460a8e1bdeda4436664f5a3b6f
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
@@ -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,15 +93,15 @@ 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:
<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

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,6 +1,6 @@
(function ($) {
var Events = require('events');
$.ender({
- eventify: Events.create
+ eventify: Events.enable
});
}(ender));
View
@@ -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
@@ -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
@@ -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.