ampersand-events
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -107,3 +107,6 @@ /*$AMPERSAND_VERSION*/ | ||
Events.bind = Events.on; | ||
Events.unbind = Events.off; | ||
// Implement fancy features of the Events API such as multiple event | ||
@@ -110,0 +113,0 @@ // names `"change blur"` and jQuery-style event maps `{change: action}` |
{ | ||
"name": "ampersand-events", | ||
"description": "Module that can be mixed into any object to provide eventing. Heavily based on Backbone Events.", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"author": "Henrik Joreteg <henrik@andyet.net>", | ||
@@ -6,0 +6,0 @@ "browserify": { |
@@ -91,2 +91,4 @@ # ampersand-events | ||
(aliased as `bind` for backwards compatibility) | ||
Bind a function to be called each time the `eventName` is triggered on that object. | ||
@@ -104,3 +106,3 @@ | ||
### once `eventObj.on(eventName, callback, [context])` | ||
### once `eventObj.once(eventName, callback, [context])` | ||
@@ -111,2 +113,4 @@ Exactly like `on` but removes itself after getting called once no matter how many times the event is triggered. | ||
(aliased as `unbind` for backwards compatibility) | ||
Remove previously bound callback(s) from the object. If no context is specified all versions of callback no matter what context was given will be removed. If no callback was specified, all callbacks for that given `eventName` will be removed. If no `eventName` was specified callbacks for all events are removed. | ||
@@ -118,2 +122,3 @@ | ||
These can be used in any combination as shown below: | ||
@@ -120,0 +125,0 @@ |
@@ -28,2 +28,24 @@ var test = require('tape'); | ||
test('bind/unbind and trigger (for backwards compatibility)', function (t) { | ||
t.plan(3); | ||
var obj = { | ||
counter: 0 | ||
}; | ||
extend(obj, Events); | ||
obj.bind('event', function () { | ||
obj.counter += 1; | ||
}); | ||
obj.trigger('event'); | ||
t.equal(obj.counter,1,'counter should be incremented.'); | ||
obj.trigger('event'); | ||
obj.trigger('event'); | ||
obj.trigger('event'); | ||
obj.trigger('event'); | ||
t.equal(obj.counter, 5, 'counter should be incremented five times.'); | ||
obj.unbind('event'); | ||
obj.trigger('event'); | ||
t.equal(obj.counter, 5, 'counter should not be further incremented as unbound.'); | ||
t.end(); | ||
}); | ||
test('binding and triggering multiple events', function (t) { | ||
@@ -30,0 +52,0 @@ t.plan(4); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35647
705
209
1