Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: on multiple events accept array #163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,13 @@ manager.on('event#1 event#2', function (evt, data) {
Note that you can listen to multiple events at once by separating
them either with a space or a comma (or both, I don't care).

You can also separate events in an array.
```javascript
manager.on(['event#1', 'event#2'], function (evt, data) {
// Do something.
});
```

#### `manager.off([type, handler])`

To remove an event handler :
Expand Down
2 changes: 1 addition & 1 deletion example/codepen-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
createNipple('dynamic');

function bindNipple () {
joystick.on('start end', function (evt, data) {
joystick.on(['start', 'end'], function (evt, data) {
dump(evt.type);
debug(data);
}).on('move', function (evt, data) {
Expand Down
2 changes: 1 addition & 1 deletion src/super.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function Super () {}
// Basic event system.
Super.prototype.on = function (arg, cb) {
var self = this;
var types = arg.split(/[ ,]+/g);
var types = Array.isArray(arg) ? arg: arg.split(/[ ,]+/g);
var type;
self._handlers_ = self._handlers_ || {};

Expand Down