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

app-communication

v1.0.8

Published

init app communication

Downloads

7

Readme

注意事项

开始

静态属性方法

更新日记

注意事项

sessionStorage 请勿设置key为: app_sessionId app_userId app_token

安装

npm i app-communication --save

创建实例并初始化方法

import AppCommunication from 'app-communication'; const initApp = new AppCommunication();

    // 注册通讯方法
            initApp.init({
                isAndroid: null, //是否安卓,非必传,有默认判断方法,若自己本身有一套判断就传
                shareData:{
                    type: 'share',
                    param: {
                        shareMap: {// 0==>微信朋友圈,1===》微信好友,2===》新浪微博,3===》短信,4==》微信收藏,5===》qq,6===》复制到粘贴板
                            '0': {
                            title: '标题',
                            content: '内容',
                            imageUrl: '分享图片(小图片)',
                            shareUrl: '分享地址',
                            },
                            '1': {...},
                            '2': {...},
                            '3': {...},
                            '4': {...},
                        },
                    },
                }, // 分享的数据 
                loginCallBack: function(userInfo,data), // app登录后的回调函数,userInfo带有userId, sessionId, token等,第二个参数data是app端返回没经过处理的数据,基本不用管
                initCallBack:function(bridge), // 初始化后的回调函数,可不传,!!!基本不用传
                bridgeInitCallBack:function(message), // bridge注册事件初始化的回调函数,可不传,!!!基本不用传
                refreshCallBack:function(data), // app端认为需要刷新页面的回调函数,1代表需要,具体根据业务来
                registerHandler:{ // 此处编写需要注册的方法,key值代表需要注册的方法名,callback代表app触发后的回调函数
                    "test":{
                        callback:function(data){

                        }
                    }
                }
            });
    // 注册通讯方法2,通过回调使用  推荐上面注册方法,此方法为了兼容
    const bridge = await initApp.init();
    bridge.registerHandler('hello', function (
            data,
            responseCallback
        ) {
            // Do something
            responseCallback('javascript');// 此处是传给app的参数
    });

    例子:(仅单用到分享)
     initApp.init({
        shareData:{
            type: 'share',
            param: {
                shareMap: {
                    '0': {
                    title: '标题',
                    content: '内容',
                    imageUrl: '分享图片(小图片)',
                    shareUrl: '分享地址',
                    },
                    '1': {...},
                    '2': {...},
                    '3': {...},
                    '4': {...},
                },
            }
        }
     })

派送事件给app 静态属性

    /*
    * sendData 给app的参数,一般是obj
    * resData 事件结束后给app的参数,一般不用传,不写就好
    */
    AppCommunication.handleSend(sendData,resData);

    例子:告诉app要请求某个接口
    const sendData = {
        reactJS: {
            handler: "hello",
            interface: 'http://www.baidu.com',
            param: {
                test:'hello world',
            }
        }
    };
    initApp.handleSend(sendData);
    // 当app接收到这个请求后,就会去请求interface 这个接口并把参数带上,请求结束后,app会主动调用注册方法里面的hello,并把数据给到回到函数里。

静态属性方法

判断是否在安卓 静态属性

    AppCommunication.getIsAndroid(); //true=安卓 false=非安卓(ios)

判断是否函数 静态属性

    AppCommunication.isFn(); //true=function false=function

获取登录信息 静态属性

    AppCommunication.getLoginInfo(); 
    return {
            token,
            userId,
            sessionId,
    };

设置登录信息 静态属性

    AppCommunication.setLoginInfo(userId, sessionId, token);

判断是否需要登录 静态属性

    AppCommunication.isNeedLogin(); // true 需要登录,false已登录
    判断条件: !(token || (userId && sessionId));  可使用getLoginInfo根据自身项目判断

获取url参数 静态属性

    AppCommunication.getUrlParam(key);

初始化化后重新注册事件,一定要在init后执行 静态属性

    // callback可不传
    AppCommunication.handleRegister(key,callback(data,responseCallback){
        // TODO
    });
    // 例子  分享事件重新注册事件
    静态属性.handleRegister('shareActionHandler',callback(data,responseCallback){
        responseCallback(shareConfig);
    });
    

更新日记

  • 2020/2/14 添加静态方法