Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kt3k/event-hub

A dom which works as an event hub
https://github.com/kt3k/event-hub

Last synced: 20 days ago
JSON representation

A dom which works as an event hub

Awesome Lists containing this project

README

        

# event-hub v6.2.2

> event hub on a dom tree

[![CircleCI](https://circleci.com/gh/kt3k/event-hub.svg?style=svg)](https://circleci.com/gh/kt3k/event-hub)

***note*** `event-hub` depends on [classcaps](https://github.com/kt3k/classcaps).

# Usage

```html

DIV 1

DIV 2

DIV 3


```

The `channel` attribute specify which events are the channel of the `.event-hub`. (If you want to set multiple channels, set them like `click mouseover` (in space-separated form)).

The `sub-click` class on the 2nd element in the `.event-hub` means that it subscribes to `click` event of the `.event-hub`.

With the above settings, all the `click` events which occur under the `.event-hub` is published to the 2nd div.

See the [DEMO](https://kt3k.github.io/event-hub/test.html).

# API

```html

```

- @class `event-hub` is the component name. You need to specify the class name in dom.
- @param {string[]} ch0, ch1,..., ch_N The channel which the event hub brokes.

If the event `ch_i` bubbles up to the above `event-hub` dom, then it dispatches the event to its children which has `sub-ch_i` class in it.

## Node API

You need to call `def` of classcaps to use event-hub.

```js
const { def } = require('classcaps')
const EventHub = require('event-hub')

def('event-hub', EventHub)
```

# License

MIT