Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zhangyu1818/stupid-events
Just a stupid imitation of the React v17 event system.
https://github.com/zhangyu1818/stupid-events
Last synced: about 1 month ago
JSON representation
Just a stupid imitation of the React v17 event system.
- Host: GitHub
- URL: https://github.com/zhangyu1818/stupid-events
- Owner: zhangyu1818
- Created: 2021-05-06T14:59:12.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-05-11T14:02:48.000Z (over 3 years ago)
- Last Synced: 2024-11-06T16:17:34.016Z (2 months ago)
- Language: TypeScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# stupid-events
Just a stupid imitation of the React v17 event system.
## Installation
```shell
yarn add stupid-events
```## Usage
```javascript
import { bindEvent, removeListeners, removeAllListeners } from 'stupid-events';const ele = document.querySelector('button');
const removeListener = bindEvent(
ele,
'click',
(event, { stopPropagation, stopImmediatePropagation }) => {
console.log('trigger');
}
);// remove event listener
removeListener();// remove element all click listeners
removeListeners(ele, 'click');// remove stupid-events all listeners
removeListeners();
```## How it works
Like React v17, it starts from the initial element that triggers the event and traverses to the upper level, collects all the elements that need to trigger the event into the queue, and then traverses the queue to call the event in turn.
However, it has no concept of priority, so I call it stupid-events, maybe can do some interesting things.