npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cross-window-emitter

v1.2.4

Published

Co-domain cross-window event triggers

Downloads

12

Readme

cross-window-emitter

由于 native 开发不提供 webview 激活时的钩子方法,特研究该方案。可应用于同域跨 webview 事件触发。

同域跨窗口事件触发器,通过轮询和 localStorage 实现。

点击查看示例

安装

npm install cross-window-emitter
yarn add cross-window-emitter
pnpm add cross-window-emitter

浏览器引入

在浏览器中使用 script 标签直接引入文件,并使用全局变量 crossWindowEmitter

npm 包的 cross-window-emitter/dist 目录下提供了 cross-window-emitter.js 以及 cross-window-emitter.min.js。你也可以通过 UNPKG 进行下载。

使用

window 1 page

import crossWindowEmitter from 'cross-window-emitter';

crossWindowEmitter.on('update', () => {
  console.log('update');
});

window 2 page

import crossWindowEmitter from 'cross-window-emitter';

crossWindowEmitter.emit('update');

API

on(eventName, listener)

  • eventName <string> | <symbol> 事件名称。
  • listener <Function> 回调函数。

添加 listener 函数到名为 eventName 的事件的监听器数组的末尾。 不会检查 listener 是否已被添加。 多次调用并传入相同的 eventNamelistener 会导致 listener 会被添加多次。

crossWindowEmitter.on('update', () => {
  console.log('update');
});

once(eventName, listener)

  • eventName <string> | <symbol> 事件名称。
  • listener <Function> 回调函数。

添加单次监听器 listener 到名为 eventName 的事件。 当 eventName 事件下次触发时,监听器会先调用,然后再被移除。

如果 eventName 事件为空,将自动停止轮询。

crossWindowEmitter.once('update', () => {
  console.log('update');
});

off(eventName[, listener])

  • eventName <string> | <symbol> 事件名称。
  • listener <Function> 回调函数。

从名为 eventName 的事件的监听器数组中移除指定的 listener

如果没有传入 listener,将移除全部 eventName 事件。

function callback(value) {
  // ...
}
crossWindowEmitter.on('update', callback);
// ...
crossWindowEmitter.off('update');

emit(eventName[, ...args])

  • eventName <string> | <symbol>
  • ...args <any>

按照监听器注册的顺序,同步地调用每个注册到名为 eventName 的事件的监听器,并传入提供的参数。

每次调用会检查是否有缓存超过 30 分钟的 eventName,超时将自动清除。

setPollingInterval(eventName, pollingInterval)

  • eventName <string> | <symbol>
  • pollingInterval <number>

设置当前窗口名为 eventName 的事件轮询调用时间,pollingInterval 不能超过 15 分钟,否则自动修正为 15 分钟。