New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

events-mixin

Package Overview
Dependencies
Maintainers
4
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

events-mixin - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

examples/multiple.html

79

index.js

@@ -64,4 +64,13 @@

*
* @param {String} event
* @param {String|function} [method]
* Multiple events handling:
*
* events.bind({
* 'click .remove': 'remove',
* 'click .add': 'add'
* });
*
* @param {String|object} - object is used for multiple binding,
* string for single event binding
* @param {String|function} [arg2] - method to call (optional)
* @param {*} [arg3] - data for single event binding (optional)
* @return {Function} callback

@@ -71,37 +80,49 @@ * @api public

Events.prototype.bind = function(event, method){
var e = parse(event);
var el = this.el;
var obj = this.obj;
var name = e.name;
var method = method || 'on' + name;
var args = [].slice.call(arguments, 2);
Events.prototype.bind = function(arg1, arg2){
var bindEvent = function(event, method) {
var e = parse(event);
var el = this.el;
var obj = this.obj;
var name = e.name;
var method = method || 'on' + name;
var args = [].slice.call(arguments, 2);
// callback
function cb(){
var a = [].slice.call(arguments).concat(args);
// callback
function cb(){
var a = [].slice.call(arguments).concat(args);
if (typeof method === 'function') {
method.apply(obj, a);
return;
if (typeof method === 'function') {
method.apply(obj, a);
return;
}
if (!obj[method]) {
throw new Error(method + ' method is not defined');
} else {
obj[method].apply(obj, a);
}
}
if (!obj[method]) {
throw new Error(method + ' method is not defined');
// bind
if (e.selector) {
cb = delegate.bind(el, e.selector, name, cb);
} else {
obj[method].apply(obj, a);
events.bind(el, name, cb);
}
}
// bind
if (e.selector) {
cb = delegate.bind(el, e.selector, name, cb);
// subscription for unbinding
this.sub(name, method, cb);
return cb;
};
if (typeof arg1 == 'string') {
bindEvent.apply(this, arguments);
} else {
events.bind(el, name, cb);
for(var key in arg1) {
if (arg1.hasOwnProperty(key)) {
bindEvent.call(this, key, arg1[key]);
}
}
}
// subscription for unbinding
this.sub(name, method, cb);
return cb;
};

@@ -108,0 +129,0 @@

{
"name": "events-mixin",
"version": "1.2.0",
"version": "1.3.0",
"scripts": {
"build": "browserify -r ./index.js:events > build/build.js"
},
"component": {

@@ -5,0 +8,0 @@ "scripts": {

@@ -99,2 +99,12 @@

There is also a shorthand syntax
for binding multiple events with one call:
```js
events.bind({
'click .remove': 'remove',
'click .close': 'hide'
});
```
### Events.unbind([event], [method])

@@ -101,0 +111,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc