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

bridge-page

v1.0.0

Published

A bridge for page

Downloads

2

Readme

PageBridge

使浏览器页面之间的通信像计算机网络一样简单,采用 localStorage 来实现通讯。

快速开始

将其添加到现有的 VueReact 项目中:

# npm
npm install bridge-page
# pnpm
pnpm install bridge-page
# yarn
yarn add bridge-page

系统协议

  • @bridge/create 注册页面数据
  • @bridge/update 更新页面数据
  • @bridge/delete 删除指定页面

使用示例

下面展示一些常用的方法

桥接页面

  • 页面A a.html
<h1>A</h1>
import { PageBridge } from 'bridge-page';

// 创建桥接对象
const bridge = new PageBridge({ name: 'A' });
  • 页面B b.html
<h1>B</h1>
import { PageBridge } from 'bridge-page';

// 创建桥接对象
const bridge = new PageBridge({ name: 'B' });

页面信息

// 获取当前页面信息
bridge.getId(); // 当前页面ID
bridge.getName(); // 当前页面名称
bridge.getData(); // 当前页面数据
bridge.getPage(); // 当前页面对象
// 获取指定页面信息
bridge.getPage(); // 当前页面
bridge.getPage('LVXJ7I56-CAV9930MH3A'); // 指定ID页面
bridge.getPage('Name'); // 指定名称页面
bridge.getPage((vo) => vo.data.label === 'Good' && vo.name === 'A'); // 指定条件页面
// 获取指定页面列表
bridge.getPages(); // 所有页面列表
bridge.getPages('LVXJ7I56-CAV9930MH3A'); // 指定ID页面列表
bridge.getPages('Name'); // 指定名称页面列表
bridge.getPages((vo) => vo.data.label === 'Good' && vo.name === 'A'); // 指定条件页面列表
// 设置当前页面信息
bridge.setName('A'); // 设置当前页面名称
bridge.setData({ label: 'Good' }); // 设置当前页面数据

订阅/发布

  • 窗口初始化
// 当前窗口初始化
bridge.ready(async () => {
    console.log('Ready');
});
  • 订阅消息
// 订阅事件(广播)
bridge.on('visit', async (vo: PageMessage) => {
    // vo.getData(); # 获取请求数据
});

// 订阅事件(请求)
bridge.on('say', async (vo: PageMessage) => {
    // vo.getData(); # 获取请求数据
    return '我是 Main';
});

// 取消订阅事件
bridge.off('say');
  • 发布广播
bridge.send({
    method: 'visit', // 方法名称
    data: { from: 'Main' }, // 请求数据
    page?: 'LVXJ7I56-CAV9930MH3A', // 指定窗口ID
    page?: null, // 所有窗口
    page?: 'Name', // 指定窗口名称
    page?: (vo) => vo.data.label === 'Good' && vo.name === 'A', // 指定条件窗口
});
  • 请求&响应
// 请求指定窗口
bridge.request({
    method: 'say', // 方法名称
    data: { from: 'Main' }, // 请求数据
    target?: 'LVXJ7I56-CAV9930MH3A', // 指定窗口ID
    target?: undefined, // 当前窗口
}).then((vo: any) => {
    console.log('say.then', vo);
}).catch((error: Error) => {
    console.log('say.catch', vo);
});