1.0.6 • Published 2 years ago

oseventlistener v1.0.6

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
2 years ago

Build Status npm version Coverage Status Donations via PayPal

OSEventListener

A simple Typescript/VanillaJS Event Listener

Why choose OS Event Listener?

  • It is modern, code written in Typescript with ES2020 target and ES Modules.
  • It is simple to use.
  • It is cross compatible, it works in any browser with at least ES2015 support, NodeJs and more.
  • It is modular, it supports AMD, UMD, CommonJS, SystemJs module loading systems.
  • Works very well in a browser without any deps or tools, because it provides an iife browser bundle that exposes the library on window ready to be used.
  • It is strong typed, thanks to Typescript it provides type definitions, there is no use of "any" type.
  • It is advanced, the behavior can be changed with custom options covering most of use cases.

How to load it

You can check samples here: https://github.com/OrbintSoft/OSEventListener/blob/master/sample

If you checkout the git project you can run npm run server, to start a simple server and test the varius module loading.

Below the supported module loading systems

AMD: https://github.com/OrbintSoft/OSEventListener/blob/master/sample/amd.html

UMD: https://github.com/OrbintSoft/OSEventListener/blob/master/sample/umd.html

System.JS: https://github.com/OrbintSoft/OSEventListener/blob/master/sample/system.html

Browser / IIFE Bundle: https://github.com/OrbintSoft/OSEventListener/blob/master/sample/bundle.html

ES6: https://github.com/OrbintSoft/OSEventListener/blob/master/sample/es.html

NodeJs / CommonJS: https://github.com/OrbintSoft/OSEventListener/blob/master/sample/node_sample.cjs

NodeJs / ES module: https://github.com/OrbintSoft/OSEventListener/blob/master/sample/node_sample.mjs

How to use:

Create an Event

const event = new EventListener('name');

Subscribe to an event

const fn = (sender, data) => {
	console.log(data);
};
event.subscribe(fn);

Subscribe with key

event.subscribeWithKey((sender, data) => {
	console.log(data);
}, 'logdata');

Unsubscribe to an event

event.unsubscribe(fn);

Unsubscribe with key

event.unsubscribeWithKey('logdata');

Dispatch an event

event.dispatch(this, 'my data');

Documentation

For detailed doc, check here:

1.0.6

2 years ago

1.0.6-rc.1

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.0-beta.2

2 years ago

1.0.0-beta.1

2 years ago

1.0.0-alpha.12

2 years ago

1.0.0-alpha.11

2 years ago

1.0.0-alpha.10

2 years ago

1.0.0-alpha.9

2 years ago

1.0.0-alpha.8

2 years ago

1.0.0-alpha.7

2 years ago

1.0.0-alpha.6

2 years ago

1.0.0-alpha.5

2 years ago

1.0.0-alpha.4

2 years ago

1.0.0-alpha.3

2 years ago

1.0.0-alpha.2

2 years ago

1.0.0-alpha.1

2 years ago