# @advanced-rest-client/events-target-mixin

> Mixin that support event targets retargeting so the element listens on a set node instead of default one

Latest version **3.2.6** (published 2021-10-18) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @advanced-rest-client/events-target-mixin
pnpm add @advanced-rest-client/events-target-mixin
yarn add @advanced-rest-client/events-target-mixin
bun add @advanced-rest-client/events-target-mixin
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.2.6 |
| Published | 2021-10-18 |
| First published | 2019-02-21 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 35.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | jarrodek, twoplustwoone, lbauret, carowright |
| Keywords | web-components, events, mixin |

## Links

- npm: https://www.npmjs.com/package/@advanced-rest-client/events-target-mixin
- Repository: https://github.com/advanced-rest-client/events-target-mixin
- Homepage: https://github.com/advanced-rest-client/events-target-mixin#readme
- Issues: https://github.com/advanced-rest-client/events-target-mixin/issues
- npm.io page: https://npm.io/package/@advanced-rest-client/events-target-mixin

## Dependencies (1)

- [@open-wc/dedupe-mixin](https://npm.io/package/@open-wc/dedupe-mixin.md) ^1.3.0

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 3.2.6 (latest) — 2021-10-18
- 3.2.5 — 2021-10-08
- 3.2.4 — 2021-07-28
- 3.2.3 — 2020-07-30
- 3.2.2 — 2020-06-05
- 3.2.0 — 2020-05-07
- 3.1.1 — 2020-04-14
- 3.1.0 — 2020-04-14
- 3.0.0 — 2019-06-20
- 3.0.0-preview.3 — 2019-04-03
- 3.0.0-preview.2 — 2019-03-05
- 3.0.0-preview.1 — 2019-02-21

## README

# DEPRECATED

Use the `@anypoint-web-components/awc` module instead.

-----

A Mixin that support event targets retargeting so the element listens on a set node instead of the default `window` object.

## Usage

### Installation

```sh
npm install @advanced-rest-client/events-target-mixin --save
```

### In a web component

```javascript
import { EventsTargetMixin } '@advanced-rest-client/events-target-mixin';

class SampleElement extends EventsTargetMixin(HTMLElement) {
  _attachListeners(node) {
    node.addEventListener('my-event', this._testEventHandler);
  }

  _detachListeners(node) {
    node.removeEventListener('my-event', this._testEventHandler);
  }

  _testEventHandler() {

  }
}
customElements.define('sample-element', SampleElement);
```

```html
<sample-element id="example"></sample-element>
<div id="target"></div>
<script>
example.eventsTarget = target;
</script>
```

The element listens for events that bubbles through #target element.

### In a class that does not extend HTMLElement interface

When constructing the object call the `_eventsTargetChanged()` method with
an object that is the default events target. If argument is not set then `window`
is used instead.

```javascript
import { EventsTargetMixin } '@advanced-rest-client/events-target-mixin';

class EventableObject extends EventsTargetMixin(Object) {
  constructor() {
    super();
    this._eventsTargetChanged();
  }
}
```

Because such class has no lifecycle methods, you should call `detachedCallback()`
manually when the instance should no longer listen on the target object. Skipping
this part may cause the GC to not clean the instance from memory.

### Development

```sh
git clone https://github.com/advanced-rest-client/events-target-mixin
cd events-target-mixin
npm install
```

### Running the tests
```sh
npm test
```

---
_Source: https://npm.io/package/@advanced-rest-client/events-target-mixin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
