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

kbs-sdk

v1.1.5

Published

提供给 [kb-smart-component](https://github.com/leeenx/kb-smart-component) 的配套工具包。使用包提供的「KbsPage」可以创建一个运行「kbs-dsl」的页面环境,具体参考:

Downloads

747

Readme

kbs-sdk

提供给 kb-smart-component 的配套工具包。使用包提供的「KbsPage」可以创建一个运行「kbs-dsl」的页面环境,具体参考:

import { KbsPage } from "kbs-sdk";
KbsPage({
  watch: true, // 是否监听,本地开发环境建议开启
  defaultKbsRoute: 'page-b', // 缺省路由(DSL 的路由)
  dslBase: 'http://127.0.0.1:9000/', // dsl 路由的 base
  defaultContainer: '/pages/kb/index', // 缺省页面容器 ---- 带头部的容器,必填
  headlessContainer: '/pages/kb-headless/index', // 不带头部的页面容器,如果需要提供无头部的页面窗口,此项必填
  onShow() {
    wx.hideHomeButton();
    console.log('------带头部的页面窗口');
  }
});

hooks

「kb-smart-component」底层的 kbone 只提供了 React-Hooks,这明显是不足以支撑一个页面功能的。「kbs-sdk」提供了小程序相关的 hooks 如下:

app-hooks

  • useLaunch, 等同于 App 入口的 onLaunch 生命周期钩子
  • useError, 等同于 App 入口的 onError 生命周期钩子
  • usePageNotFound, 等同于 App 入口的 onPageNotFound 生命周期钩子
  • useUnhandledRejection, 等同于 App 入口的 onUnhandledRejection 生命周期钩子
  • useAppShow, 等同于 App 入口的 onAppShow 生命周期钩子
  • useAppHide, 等同于 App 入口的 onAppHide 生命周期钩子
  • useThemeChange, 等同于 App 入口的 onThemeChange 生命周期钩子

page-hooks

  • useLoad, 等同于 Page 入口的 onLoad 勾子
  • useShow, 等同于 Page 入口的 onShow 勾子
  • useReady, 等同于 Page 入口的 onReady 勾子
  • useHide, 等同于 Page 入口的 onHide 勾子
  • useUnload, 等同于 Page 入口的 onUnload 勾子
  • useRouteDone, 等同于 Page 入口的 onRouteDone 勾子
  • usePullDownRefresh, 等同于 Page 入口的 onPullDownRefresh 勾子
  • useReachBottom, 等同于 Page 入口的 onReachBottom 勾子
  • usePageScroll, 等同于 Page 入口的 onPageScroll 勾子
  • useAddToFavorites, 等同于 Page 入口的 onAddToFavorites 勾子
  • useShareAppMessage, 等同于 Page 入口的 onShareAppMessage 勾子
  • useShareTimeline, 等同于 Page 入口的 onShareTimeline 勾子
  • useResize, 等同于 Page 入口的 onResize 勾子
  • useTabItemTap, 等同于 Page 入口的 onTabItemTap 勾子
  • useSaveExitState, 等同于 Page 入口的 onSaveExitState 勾子

理论上,DSL 是在页面「onLoad」之后再运行的。所以「useLoad」实际上是不会起任何作用,建议使用useEffect(() => {}, []) 代替;「useShow」监听不到第一次 onShow,原因与「useLoad」相同。

页面路由与页面跳转

这里有两种路由:

  • 小程序路由
  • 「kbs-dsl-maker」的路由(web 路由)

「小程序路由」是最终要作用于小程序的路由,而「kbs-dsl-maker」的路由是一种逻辑上的短路由,通过转换规则可以生成「小程序路由」。在这里「小程序路由」是不友好 的,所以在「kbs-dsl-maker」中直接使用 web路由做为逻辑路由。「kbs-sdk」提供了两个方法,如下:

  • navigate
  • createRoute
function createRoute(route: string, params: any, headless: boolean): string;
function navigate(route: string, params: any, config?: NavigateConfig): Promise<void>;

在「kbs-dsl-maker」中,使用「navigate」作页面跳转;使用「createRoute」可以返回「小程序路由」,在分享或是生成页面二维码等场景可使用。

内置对象与方法

  • currentPage 当前页面对象
  • getCurrentPage 获取当前页面对象
  • getCurrentParams 获取当前页面的 params
  • getCurrentParam 按 key 获取当面页面的 param
  • getParams 获取当前展示页面的 params
  • getParam 按 key 获取 当前展示页面的 param