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

yc-webviewbridge

v0.6.0

Published

Native 和 WebView 通信桥梁

Downloads

5

Readme

YC-WebViewBridge

为 Native 和 H5 项目提供双向订阅发布功能

注意

此项目无法单独在浏览器下运行,需要运行在 native 下的 webview 中 编码风格使用 standard,请对应 IDE 安装插件

使用

npm i yc-webviewbridge
import YCWebViewBridge from 'yc-webviewbridge'

或者

git clone https://github.com/guanghetv/YC-WebViewBridge
npm install
npm run build

<script type="text/javascript" src="dist/YCWebviewBridge.js">

测试

$ npm run test

YCEvent
    #nameSpance
      ✓ create and get
    #on
      ✓ can register event
    #off
      ✓ can remove register
    #one
      ✓ can register only
    #emit
      ✓ dispatch register callback
    #once
      ✓ dispatch register and remove register callback

  validation
    #string type
      ✓ string type validation be ok
    #array type
      ✓ array type validation be ok


  8 passing (86ms)

使用

  1. 使用 new 初始化一个 bridge 对象,可以传递传递一个字符串参数做命名空间,不同命名空间的事件不共享。
var bridge = new YCWebViewBridge('namespance')

let cb = (data, responseCallback) => {
  console.log(data)
  responseCallback({ok: true, data: {message: 'hello'}})
}

bridge.on('hello', cb)
bridge.one('hello', cb)
bridge.once('hello', cb)
bridge.off('hello', cb)
bridge.off('hello')
bridge.callNative('native', { msg: 'hello' }, function (data) {
  console.log(data)
})

YCWebViewBridge API

constructor([namespance: string])

在一个命名空间下创建一个 bridge 对象,如果不传递 namespance 参数,则会使用默认的 _global_ 作为命名空间

var bridge = new YCWebViewBridge('namespance')

on(eventName, callback: function(data: jsonString, responseCallback: function) )

订阅一个 native 事件,并提供回调功能。

  • eventName: 事件名称
  • callback: 回调函数
    • data: native 发布事件时携带的参数
    • responseCallback: 签名为 responseCallback(data: string), 用来通知 native 执行结果

one(eventName, callback: function(data: jsonString, responseCallback: function) )

on 类似,但是会先删除掉所有同类事件,然后添加订阅

once(eventName, callback: function(data: jsonString, responseCallback: function) )

on 类似,但是会订阅一个一次性事件,执行一次后,就会被删除

off(eventName: string [, callback: function])

取消订阅一个事件

  • eventName: 事件名称
  • callback: 取消订阅的回调,如果不传递这个参数,则会取消掉所有的同类事件

callNative(eventName, data, callback: function(data))

向 native 发布一个事件

  • eventName: 事件名称
  • data: 发布事件所携带的参数, 没有参数时可以不传递
  • callback: 事件回调, data 为 native 回调的数据结果