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

salt-router

v1.0.0

Published

salt-router.js 主要功能是跟 Native 深度结合的一些 API 的封装,在项目中主要解决一些路由上的一些问题以及增加转场等的一些动画,另外还涉及到了 view 之间共享数据,以及多 view 的preload 等功能,API统一支持Promise,方便使用者调用;

Downloads

9

Readme

salt-router npm version

简介

salt-router.js 主要功能是跟 Native 深度结合的一些 API 的封装,在项目中主要解决一些路由上的一些问题以及增加转场等的一些动画,另外还涉及到了 view 之间共享数据,以及多 view 的preload 等功能,API统一支持Promise,方便使用者调用;

使用方式

引入模块

var Salt_router = require('salt-router');
Salt_router.preload({}).then().catch();

引入外部js

<script type="text/javascript" src="/xx/xx/salt-router.js"></script>

<script type="text/javascript">
    window.salt.router.preload({}).then().catch();
</script>

APIs

preload

  • Demo

  salt.router.preload({
          pages:[{
              id:'id1', // frame id
              url:'xxx' // frame url
          }] 
  }).then((data)=>{
      // TODO 
  }).catch((e)=>{
      // 捕获异常,或者根据返回code执行降级代码
  })
  • 功能 用于项目中预加载某些不需要特定数据交互的页面,一般是数据变化比较少的页面;

  • 参数

    • pages:Object 预加载的页面的数组对象,其中单个对象中包括
    • id: String 自定义的frame id,唯一
    • url: String 预加载的页面的url
  • 依赖API:dd.ui.nav.preload

recycle

  • Demo


salt.router.recycle({
        id:['a','b'] // frame id
}).then((data)=>{
        // TODO
}).catch((e)=>{
        // 捕获异常,或者根据返回code执行降级代码
})
  • 功能 用于释放(销毁)没有用的 webView
  • 参数
    • recycle:String API名称
    • id:Array 需要释放的frame id数组;
  • 依赖API:dd.ui.nav.recycle

push

  • Demo
salt.router.push({
        id:'xxx', // frame id 
        url:'xxx', // 跳转的frame 所需要加载的url
        anim:1, // 转场动画,1:从左到右,2:bottom 从下往上;默认1;
        needPost:true // 是否需要发送数据到加载的frame; 
        param:'xxx' // 当needPost 是true的时候发送的数据
}).then(()=>{}).catch((e)=>{
})
  • 功能 用于创建并且跳转一个新的webView

  • 参数

    • id:String frame id
    • url:String 跳转的frame 所需要加载的url
    • anim:number 转场动画,1:从左到右,2:bottom 从下往上;默认1;
    • needPost:bool 是否需要发送数据到加载的frame;
    • param:Object 当needPost是true的时候发送的数据,直接json对象,以及字符串;数据存储的key就是frame id;
  • 依赖API:dd.ui.nav.push

  • 备注: 发送的数据默认获取从getMessage中获取;

goBack

  • Demo

salt.router.goBack();
  • 功能 返回历史记录的上一层

pop

  • Demo

    salt.router.pop({
        to:'xxx' // frame id 
    }).then(()=>{
    }).catch((e)=>{
    })
  • 功能 功能中有2部分,包括了view 之间的跳转;
  • 参数
    • to:String 需要返回到指定的frame 的id;返回当前frame 之后堆栈上层的view 都会全部注销;
  • 备注:当to 不存在的时候默认会直接返回上一个frame;

postMessage

  • Demo
// @param opt 可以是Array,也可以是Object;
// @example
// [{key:'home',value:'123'},{key:'detail',value:'333'}] or {key:'app',value:'111'} 
salt.router.postMessage(opt).then().catch();
  • 功能 当前api 主要是对已经存在的frame 发送数据;
  • 参数
    • key:存储的key 值;
    • value:key 对应的value
  • 依赖API:dd.runtime.message.post

getMessage

  • Demo

    salt.router.getMessage('key');
  • 功能 获取别的frame 中存入的key,value 数据;
  • 参数
    • key:String 存储的数据的key 值;

依赖

  • Promise 针对不支持promise的浏览器需要单独引入,比如 polyfill
  • dingTalk 钉钉单独的 sdk.js