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

@dingdaoos/msg-transfer

v0.0.5

Published

- [smartBond](#smartbond) - [smartAction](#smartaction)

Downloads

59

Readme

Atoms Bond

version: 1.0.x

为进一步简化调用方式,1.1.x 以上版本新增两个api

Install

npm install @dingdao/atoms-bond

How to use

import { createBond, receiveBond, createAction, receiveAction, preach, createCombo, receiveCombo, smartBond, smartAction } from '@dingdao/atoms-bond'

Action

Create action && Send action data
// 调起方
const action = await createAction(options)  // options.category is required
action.send('test')

// 被调起方
preach.response('test')
Receive action data
// 被调起方
receiveAction( data => {
  console.log(data) // test
})

// 调起方
receiveAction( data => {
  console.log(data) // test
}, { isResult: true })

Bond

Create bond && Send bond data
const bond = await createBond(options)  // options is optional
bond.send('test')
Receive bond data
// 被调起方接收数据
receiveBond( data => {
  console.log(data) // test
})

Combo

Create combo && Send combo data
// 同时创建 bond 和action; 注意,需要传入options.category 才能成功创建action
const combo = await createCombo(options) 
combo.send('test')
Receive combo data
// 被调起方接收数据
receiveCombo( data => {
  console.log(data, e, eventName)
})

参数说明:

  data: 'test'
  e: {
    custom: true,
    origin: 'com.dingdaoos.examples.atom1_AND_com.dingdaoos.examples.atom3',
    data: '123',
    type: 'RESPONSE'  // 'BOND' | 'action' | 'RESPONSE'
  }
  eventName: 'intentresult' | 'intentreceive' | 'bondIntent'

smartBond

根据配置的 input/output 自动创建所有 bond。同时使用者不再需要关心 schema 匹配问题,通过以 schema 为键值的 bonds 对象来对不同的 receive 进行分别处理

// @ts-ignore ignore mjs
import { bondOptions } from './.dsdl.mjs'
/* 读取 .dsdl.mjs 中的 bondOptions 
bondOptions = {
  input: ['CONTACT_LIST_TYPE', 'REQUEST_CATEGORY'],
  output: ['CONTACT_ID_INFO', 'RESPONSE_CATEGORY', 'CONTACT_INFO']
}
*/
// 在原子服务初始化时调用,自动根据 input/output 创建所有bond
const bonds = smartBond(bondOptions)

// 发送 bond 数据
bonds['CONTACT_LIST_TYPE'].then((e: any) => {
  e.send('test')
})

// 接收 bond 数据, 调用此 API 只有 schema 匹配时才会进行回调处理
bonds['CONTACT_LIST_TYPE'].receive((data: any, e: any, eventName: string) => {
  // data
  // e
  // eventName: bondintent
})

smartAction

调起方根据 actionId 定向创建通信,被调起方根据 refetUrl 定向收发数据,只有匹配的 action 才能互相收发数据

调起方
// 通过 actionId 定向创建一个action
const action1 = smartAction['com.dingdaoos.address-book.userinfo.actions.1']

// 定向发送数据,只会发送给 actionId 相匹配的 action 页面
action1.then((e: any) => {
  e.send('test')
})
// 接收 action response,只会接收此 actionId 回传的 response 数据
action1.receive((data: any, e: any, eventName: string) => {
  // data
  // e
  // eventName: intentresult
})
被调起方
// 通过来源 referUrl 创建一个监听
const action2 = smartAction[`${process.env.VUE_APP_APPROTO_DOMAIN}/organization`]
// 只会接收到 referUrl 匹配的 action 传来的数据
action2.receive((data: any, e: any, eventName: string) => {
  // data
  // e
  // eventName: intentreceive
})
// response 信息只会被 referUrl 相匹配的调起方接收到
action2.response('test')

simulator 模拟器

import { simulator } from '@dingdao/atoms-bond'
customElements.define('ding-simulator', simulator)

<ding-simulator class="approto-main"  id="simulator" :config="JSON.stringify(minifestJson)"></ding-simulator>

Related documents

preach-dsapi