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

bifrostor

v0.0.2

Published

iframe平台桥通信

Downloads

4

Readme

@datafe/bifrost

彩虹桥 iframe 微前端解决方案

重大更新

从原来的构造函数式调用改为了函数式调用 (这样做的原因是将代码彻底向函数式改造,更方便阅读、扩展、维护),省去了使用 this 的心智负担

new Bifrost({}) => Bifrost({})

new Bifrost.Model({}) => Birfost.Model({})

用法

引入包

mnpm install --save @datafe/bifrost

创建父页面实例

import Bifrost from '@datafe/bifrost'
const bifrost = Bifrost(
	{
			el,
			name: 'client',
			classList: ['child'],
			url: ${window.location.href}client.html
	}
).sendHandshake().then((child) => {
	child.on('some-event', (ev) => {
	})
	child.get('height').then(data => {
	})
setTimout(() => {
  child.call('upBackground', '#fff')
}, 5000)
})

创建子页面实例

Bifrost.Model(
    {
        upRouting: (hash: string) => {
            location.hash = hash;
        },
        height: () => document.body.offsetHeight,
        upBackground: (color: string) => {
            document.body.style.background = color;
        }
    },
    true
)
    .sendHandshake()
    .then((parent: ParentApi) => {
        document.body.addEventListener("click", ev => {
            parent.emit("client1-click", { x: ev.pageX, y: ev.pageY });
        });
        window.addEventListener("hashchange", () => {
            document.body.innerText = `触发hash更新, ${location.hash}`;
        });
    })
    .catch((err: Error) => {
        console.log(err.message);
    });

其他 api

父页面 setUrl, 修改 iframe 页面的地址, 自动握手 bifrost.setUrl('newUrl').then((childApi) => {}) 父页面设置回调内容(需要在握手之前设置) bifrost.setFuncAfterHandshake((childApi) => {}) 这俩方法主要是在需要切换 iframe 时候用到。 握手成功后, 父页面可监控子页面发送的事件(on), 也可以调用子页面对外暴露的方法(get 和 call) 子页面在初始化时对外暴露方法,如 upRouting,height 等, 也可以向父页面发送事件(emit)

sendHandshake(opt)方法(建设中)

opt: string[] | (origin: string): boolean => {} 对子页面许可域进行校验, 校验失败, 握手失败, 抛出 601 校验失败。

错误码说明

402: "参数无效",
403: "创建失败",
404: "握手失败",
405: "上下文未打通",
500: "未定义错误",
501: "缺少模型",
502: "握手通讯超时",
601: "校验失败"