Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/modernize'
Browse files Browse the repository at this point in the history
  • Loading branch information
pirxpilot committed Feb 21, 2024
2 parents 7abbec2 + 401d6d8 commit 8b41b90
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 53 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/check.yaml
@@ -0,0 +1,12 @@
name: check
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- uses: actions/setup-node@main
with:
node-version: 'lts/*'
- run: yarn install
- run: make check
4 changes: 2 additions & 2 deletions .jshintrc
Expand Up @@ -4,12 +4,12 @@
"eqnull": true,
"immed": true,
"latedef": "nofunc",
"mocha" : true,
"newcap": true,
"noarg": true,
"node": true,
"sub": true,
"undef": true,
"unused": true,
"browser": true
"browser": true,
"esversion": 11
}
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -4,6 +4,6 @@ lint:
./node_modules/.bin/jshint *.js test

test:
./node_modules/.bin/mocha --recursive --require should --require jsdom-global/register
node --require should --require jsdom-global/register --test

.PHONY: check lint test
14 changes: 7 additions & 7 deletions Readme.md
@@ -1,6 +1,6 @@
[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Dependency Status][gemnasium-image]][gemnasium-url]
[![Build Status][build-image]][build-url]
[![Dependency Status][deps-image]][deps-url]

# events

Expand Down Expand Up @@ -55,13 +55,13 @@ remove event listener for specific `event`, if `event` is not specified remove a

MIT © [Damian Krzeminski](https://pirxpilot.me)

[npm-image]: https://img.shields.io/npm/v/@pirxpilot/events.svg
[npm-image]: https://img.shields.io/npm/v/@pirxpilot/events
[npm-url]: https://npmjs.org/package/@pirxpilot/events

[travis-url]: https://travis-ci.org/pirxpilot/events
[travis-image]: https://img.shields.io/travis/pirxpilot/events.svg
[build-url]: https://github.com/pirxpilot/events/actions/workflows/check.yaml
[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/events/check.yaml?branch=main

[gemnasium-image]: https://img.shields.io/gemnasium/pirxpilot/events.svg
[gemnasium-url]: https://gemnasium.com/pirxpilot/events
[deps-image]: https://img.shields.io/librariesio/release/npm/@pirxpilot/events
[deps-url]: https://libraries.io/npm/@pirxpilot%2Fevents

[component/events]: https://github.com/component/events
14 changes: 7 additions & 7 deletions index.js
@@ -1,24 +1,24 @@
module.exports = events;

function events(el, obj) {
var handlers = {};
const handlers = {};

function bind(name, handler, opts) {
if (!handler) {
handler = name;
}
if (typeof(handler) === 'string') {
if (typeof (handler) === 'string') {
handler = obj[handler].bind(obj);
}
el.addEventListener(name, handler, opts);
handlers[name] = {
handler: handler,
opts: opts
handler,
opts
};
}

function do_unbind(name) {
var h = handlers[name];
const h = handlers[name];
if (!h) { return; }
el.removeEventListener(name, h.handler, h.opts);
delete handlers[name];
Expand All @@ -34,7 +34,7 @@ function events(el, obj) {
}

return {
bind: bind,
unbind: unbind
bind,
unbind
};
}
9 changes: 4 additions & 5 deletions package.json
Expand Up @@ -7,18 +7,17 @@
"email": "pirxpilot@furkot.com",
"url": "https://pirxpilot.me"
},
"repository": "pirxpilot/events",
"repository": "github:pirxpilot/events",
"license": "MIT",
"keywords": [
"browser",
"event",
"dom"
],
"devDependencies": {
"jsdom": "~11",
"@pirxpilot/jshint": "~3",
"jsdom": "~24",
"jsdom-global": "~3",
"jshint": "~2",
"mocha": "~4",
"should": "~13"
},
"scripts": {
Expand All @@ -27,4 +26,4 @@
"files": [
"index.js"
]
}
}
51 changes: 24 additions & 27 deletions test/events.js
@@ -1,13 +1,14 @@
// var should = require('should');
var events = require('../');
const { describe, it } = require('node:test');

const events = require('../');

describe('events', function () {
it('must bind event', function () {
var clicks = 0;
var handlers = {
click: function() { clicks++; }
let clicks = 0;
const handlers = {
click() { clicks++; }
};
var div = document.createElement('div');
const div = document.createElement('div');

events(div, handlers).bind('click');

Expand All @@ -18,11 +19,11 @@ describe('events', function () {
});

it('must bind event when method name is passed', function () {
var clicks = 0;
var handlers = {
onclick: function() { clicks++; }
let clicks = 0;
const handlers = {
onclick() { clicks++; }
};
var div = document.createElement('div');
const div = document.createElement('div');

events(div, handlers).bind('click', 'onclick');

Expand All @@ -32,15 +33,14 @@ describe('events', function () {
clicks.should.eql(2);
});


it('must unbind event', function () {
var clicks = 0;
var handlers = {
click: function() { clicks++; }
let clicks = 0;
const handlers = {
click() { clicks++; }
};
var div = document.createElement('div');
const div = document.createElement('div');

var e = events(div, handlers);
const e = events(div, handlers);

e.bind('click');

Expand All @@ -53,18 +53,17 @@ describe('events', function () {
clicks.should.eql(1);
});


it('must unbind all events when no event name is passed', function () {
var clicks = 0;
var foos = 0;
var handlers = {
click: function() { clicks++; },
foo: function() { foos++; }
let clicks = 0;
let foos = 0;
const handlers = {
click() { clicks++; },
foo() { foos++; }
};
var div = document.createElement('div');
var ev = new CustomEvent('foo');
const div = document.createElement('div');
const ev = new CustomEvent('foo');

var e = events(div, handlers);
const e = events(div, handlers);

e.bind('click');
e.bind('foo');
Expand All @@ -84,6 +83,4 @@ describe('events', function () {
clicks.should.eql(1);
foos.should.eql(1);
});


});

0 comments on commit 8b41b90

Please sign in to comment.