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

中文文档
3.2.6发布于 2021/10/19Apache-2.0ESM + CJS近 30 天下载 3361

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

原始使用文档
文档目录6 节
  1. Usage
  2. Installation
  3. In a web component
  4. In a class that does not extend HTMLElement interface
  5. Development
  6. Running the tests

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

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

In a web component

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);
<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.

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

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

Running the tests

npm test

版本与发布记录

@advanced-rest-client/events-target-mixin 共发布 12 个版本,首次发布于 2019/02/21;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.2.6latest2021/10/195 年前
3.2.52021/10/095 年前
3.2.42021/07/295 年前
3.2.32020/07/316 年前
3.2.22020/06/066 年前
3.2.02020/05/086 年前

关于 @advanced-rest-client/events-target-mixin 的常见问题

@advanced-rest-client/events-target-mixin 是什么?

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

如何安装 @advanced-rest-client/events-target-mixin?

在项目目录运行 npm install @advanced-rest-client/events-target-mixin,或使用 pnpm add / yarn add / bun add。

@advanced-rest-client/events-target-mixin 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/advanced-rest-client__events-target-mixin 是否存在。

@advanced-rest-client/events-target-mixin 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@advanced-rest-client/events-target-mixin 可以商用吗?

@advanced-rest-client/events-target-mixin 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@advanced-rest-client/events-target-mixin 的下载量有多少?

根据 npm 官方下载统计,@advanced-rest-client/events-target-mixin 在 2026/10/05 – 2026/11/03 这 30 天内被下载 3,361 次,日均约 112 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@advanced-rest-client/events-target-mixin 还在维护吗?

最新版本 3.2.6 发布于 2021/10/19(5 年前);至今共发布 12 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/02/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。