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

web-message-center

v0.0.3

Published

web-message-center

Downloads

10

Readme

web-message-center

web的消息中心插件

基于发布-订阅模式思想,利用 window.postMessage 封装的浏览器父子标签之间、父子页面、iframe之间通信插件,消息名称及消息内容均可自定义

基础使用

在一个页面中引入
import WebMessageCenter from "web-message-center"
const wmc = new WebMessageCenter();

wmc.emit("message", {
  from: "parent",
  contents: "我是父页面",
});


在另外一个 iframe、页面中
import WebMessageCenter from "web-message-center"
const wmc = new WebMessageCenter();

wmc.on("message", function (data) {
  console.log('form:'data.from + "contents" + data.contents);
});

api

constructor

const wmc = new WebMessageCenter(options)

options参数是可选的,支持如下:

| 名称 | 类型 | 含义 | | ------------ | -------- | ------------------------------------------------------------ | | origin | String | 页面源,设置后只能在同一源(同一url)下才能通信 * | | channel | String | 频道,处于同一频道下的WebMessageCenter才能相互通信 | | verifyDomain | Function | 校验发消息的来源,function (url) { return url.indexOf("https://my-domain") === 0; }, 只有返回true的时候才能接收到消息 | | targetFrames | Array | 给那些iframe发消息(Window (t window.open的返回值) 或 HTMLFrameElement (iframe元素)),也可以通过wmc.addTargetFrame(myIframe);动态添加 |

target

target(options),options同上

// 只接收来自https://example.com的消息
wmc.target({origin: "https://example.com"}).on('message', () => {})

emit

emit('event', data?, reply?): boolean

| 参数 | 类型 | 描述 | | -------- | -------- | ---------------------- | | event | String | 事件名称 | | data | Any | 传递的内容 | | callback | Function | 为订阅者提供的回调函数 |

on

on('event', fn): boolean

| 参数 | 类型 | 描述 | | ----------------- | -------- | ---------------------------------- | | event | String | 事件名称 | | fn(data?, reply?) | Function | 事件处理函数,均来自于emit函数 |

off

off('event', fn): boolean

取消订阅

teardown

销毁实例