From c7c9e7980dcb713327c48569b5096d508d4b4360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9ni=20Gauffier?= Date: Sun, 20 Jun 2021 14:54:09 +0200 Subject: [PATCH] feat: on multiple events accept array --- README.md | 7 +++++++ example/codepen-demo.html | 2 +- src/super.js | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7ac01a2..ac31aa4 100644 --- a/README.md +++ b/README.md @@ -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 : diff --git a/example/codepen-demo.html b/example/codepen-demo.html index b7946a1..3e8478c 100644 --- a/example/codepen-demo.html +++ b/example/codepen-demo.html @@ -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) { diff --git a/src/super.js b/src/super.js index dec15ef..b569550 100644 --- a/src/super.js +++ b/src/super.js @@ -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_ || {};