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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@wair/cloud-micro-app-types

v1.0.5

Published

用于太初云微应用ts类型包。

Downloads

11

Readme

@wair/cloud-micro-app-types

TypeScript 类型定义包,用于太初云微应用集成。

安装

npm install @wair/cloud-micro-app-types

或者使用 pnpm:

pnpm add @wair/cloud-micro-app-types

使用方法

import { useEffect, useState, useRef } from 'react'
import { InjectProps } from '@wair/cloud-micro-app-types'

export type QianKunProps = {
  name: string
} & InjectProps
export class MainAppState {
  static state: InjectProps['state']
  static actions: InjectProps['actions']
  static appName: string
  static init({
    state,
    actions,
    subscribe,
    snapshot,
    name,
    router,
  }: QianKunProps) {
    this.state = state
    this.actions = actions
    this.subscribe = subscribe
    this.snapshot = snapshot
    this.appName = name
    this.appRouter = router
  }
  static subscribe: InjectProps['subscribe']
  static snapshot: InjectProps['snapshot']
  static appRouter: InjectProps['router']
}

export function useMainAppState<T>(fn: (s: typeof MainAppState.state) => T) {
  const [state, setState] = useState<ReturnType<typeof fn>>(
    fn(
      MainAppState.snapshot
        ? MainAppState.snapshot(MainAppState.state)
        : MainAppState.state,
    ),
  )
  const fnRef = useRef(fn)

  useEffect(() => {
    fnRef.current = fn
  }, [fn])

  useEffect(() => {
    if (MainAppState.subscribe) {
      const unSubscribe = MainAppState.subscribe(
        MainAppState.state,
        (s: any) => {
          fnRef.current &&
            setState(fnRef.current(MainAppState.snapshot(MainAppState.state)))
        },
      )
      return unSubscribe
    }
  }, [fnRef, setState])

  return state
}

export function appLoadFinished() {
  MainAppState.actions &&
    MainAppState.actions.updateMicroAppState(MainAppState.appName, {
      loading: false,
    })
}

类型说明

InjectMicroAppState

微应用状态接口,定义了微应用的状态结构。

interface InjectMicroAppState {
  microApp: Record<'taichu-web', {
    loading: boolean;
  }>;
}

Router

React Router 类型定义,基于 createBrowserRouter 的返回类型。

export type Router = ReturnType<typeof createBrowserRouter>;

InjectMicroAppActions

微应用操作方法集合的类型定义:

export declare const injectMicroAppActions: {
  updateInjectMicroAppState(name: string, value: {
    loading: boolean;
  }): void;
};

export type InjectMicroAppActions = typeof injectMicroAppActions;
  • updateInjectMicroAppState(name: string, value: { loading: boolean }): 更新微应用状态

InjectProps

注入到微应用的完整属性对象类型定义:

export declare const injectProps: {
  actions: InjectMicroAppActions;
  state: InjectMicroAppState;
  router: Router;
  subscribe: typeof subscribe;
  snapshot: typeof snapshot;
};

export type InjectProps = typeof injectProps;

包含以下属性:

  • actions: 操作方法集合
  • state: 状态对象
  • router: React Router 实例
  • subscribe: valtio 订阅方法
  • snapshot: valtio 快照方法

文件结构

taichu-cloud-micro-app-types/
├── micro-app-store.d.ts    # 主要类型定义文件
├── package.json            # 包配置文件
└── readme.md              # 说明文档

依赖要求

  • valtio: ^2.0.0
  • react-router-dom: ^7.0.0

开发团队

Taichu Cloud Team

许可证

MIT