Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/townland-project/eventer
Townland event emitter
https://github.com/townland-project/eventer
library npm townland
Last synced: about 2 months ago
JSON representation
Townland event emitter
- Host: GitHub
- URL: https://github.com/townland-project/eventer
- Owner: townland-project
- License: mit
- Created: 2021-12-24T19:06:38.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-05T22:55:24.000Z (almost 3 years ago)
- Last Synced: 2024-10-28T15:36:20.176Z (2 months ago)
- Topics: library, npm, townland
- Language: TypeScript
- Homepage:
- Size: 34.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @townland/eventer
Townland custom event emitter named ```eventer``` and you can run this package in browsers.## Table of Contents
- [Stackable emit events](#stackable-emit-events)
- [Installation](#installation)
- [With package manager](#with-package-manager)
- [npm](#npm)
- [yarn](#yarn)
- [CDN](#cdn)
- [Functions](#functions)
- [has](#has)
- [isStacked](#isstacked)
- [on](#on)
- [once](#once)
- [remove](#remove)
- [Example](#example)
- [Change log](#change-log)## Stackable emit events
Emit an event with no event listener. After making the listener, the last emit will be called.## Installation
If you have worked with NPM/NodeJS so far, you know how to install this package. Of course, you can also run this package in browsers.### With package manager
I know ```npm``` and ```yarn``` to manage nodejs packages.#### npm
```
npm i @townland/eventer
```#### yarn
```
yarn add @townland/eventer
```### CDN
Do you know ```jsDeliver``` ?
```html```
## Functions
### has
Check event name exist or not.```typescript
eventer.has('')
```### isStacked
Check event name stacked and wait for listener.```typescript
eventer.isStacked('')
```### on
Listen to an event.```typescript
function callback() {
/// your event callback
}eventer.on('', callback)
```### once
Listen to an event one time.```typescript
function callback() {
/// your event callback
}eventer.once('', callback)
```### remove
Yes! You can remove created listenner.```typescript
let event = eventer.on('', callback);event.remove()
```## Example
```typescript
import { Eventer } from '@townland/eventer';let eventer = new Eventer();
eventer.once('pong', (params: any[]) => {
/*
* This callback will call one time
*/
console.log('ping')
})eventer.on('ping', (params: any[]) => {
/*
* This is event callback
*/
console.log('pong')
eventer.emit('pong')
});eventer.emit('ping') // <= call event callback
```## Change log
You can read changes right [here](./CHANGELOG.md).