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

@tb-app/registry-trigger

v0.3.1

Published

实现webview与淘宝小程序之间的通信

Downloads

22

Readme

@tb-app/registry-trigger

简介

这是一个用于淘宝小程序与 web-view 通信的库。且只能在小程序端使用。

web-view 端 使用 @tb-app/web-view-api 暴露的各个 api,即可使用小程序提供的原生 api 功能。

安装

yarn add @tb-app/registry-trigger
// 或
npm i @tb-app/registry-trigger

提供了以下 API

registry(type:string,callback:Function)

registry 用于在小程序端注册事件,该事件是由 web-view 端触发的。

参数介绍

  • type: 事件的名称
  • callback: 当事件触发时的回调函数, 参数是 web-view 端传递的数据
// 小程序端
import { registry, trigger } from '@tb-app/registry-trigger;
const localWebViewId = 'local';

registry('greet', (options) => {
  return `${option.name}你好`
});

Page({
  localWebView: null,
  data: {
    localWebViewId,
  },
  onLoad() {
    this.localWebView = my.createWebViewContext(localWebViewId);
  },
  onWebViewMessage({ detail: { value } }) {
    trigger(value, this.localWebView)
  },
});
// webview 端
import { invoke } from '@tb-app/web-view-api';
invoke({
  type: 'greet',
  data: {
    name: '德米朵夫',
  },
});

trigger(param:Object,webViewContext:WebViewContext)

trigger 在 web-view 组件的 onMessage 事件处理器内使用。用于触发 web-view 端发送的消息事件。

这个 api 必须使用,否则无法处理到 web-view 端发过来的消息。

参数介绍

  • param: web-view 端传递给来的数据,该值来自小程序组件 webview 的 onMessage 事件处理函数
  • webViewContext: web-view 组件上下文,由 my.createWebViewContext 得到
// 小程序端代码
Page({
  localWebView: null,
  data: {
    localWebViewId,
  },
  onLoad() {
    this.localWebView = my.createWebViewContext(localWebViewId);
  },
  onWebViewMessage({ detail: { value } }) {
    trigger(value, this.localWebView);
  },
});