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

@byted-apaas/component-v3

v1.13.0

Published

给组件开发者提供标准化的运行时 SDK API,目前的能力范围主要包含:

Downloads

53

Readme

概述

给组件开发者提供标准化的运行时 SDK API,目前的能力范围主要包含:

  • 基于视图模型的方式,支撑组件之间相互消费

详细参考:https://ae.feishu.cn/hc/zh-CN/articles/353952071417?from=from_parent_docs#lineguid-2KyZM

用法

model.ts

import { ViewModel } from '@byted-apaas/component-v3';
import { IDemoProps } from './type';

export default class DemoModel extends ViewModel<IDemoProps> {
  public data = {
    displayText: this.props.initialDisplayText,
    clickCount: 0,
  };

  public updateDisplayText = (): void => {
    this.updateData('clickCount', this.data.clickCount + 1);
    this.updateData(
      'displayText',
      `display text is updated ${this.data.clickCount} ${
        this.data.clickCount > 1 ? 'times' : 'time'
      }`,
    );
  };
}

type.ts

export interface IDemoProps {
  title: string;
  initialDisplayText: string;
}

index.ts

import { FC } from 'React';
import { Button } from '@universe-design/react';
import { useModel, observer } from '@byted-apaas/runtime-react';
import DemoModel from './model';
import { IDemoProps } from './type';

const Demo: FC<IDemoProps> = ({ title }) => {
  const { data, updateDisplayText } = useModel<DemoModel>();

  return (
    <div className="demo">
      <div className="demo-title">{title}</div>
      <div className="demo-description">{data.displayText}</div>
      <Button className="mr12" onClick={() => updateDisplayText()}>
        click to change display text
      </Button>
    </div>
  );
};

export default observer(Demo);

接口描述

ViewModel

描述

用于定义【视图模型】的基类

类型

type EmptyRecord = {
  [key: string]: any;
};
class ViewModel<Props = EmptyRecord> {
  //组件属性
  props: Props;
  //组件状态
  data: EmptyRecord;
  //更新组件状态方法
  updateData<K, T = K extends keyof Data ? Data[K] : unknown>(
    key: K,
    value: T,
  ): void;
}

useModel

描述

使用组件定义的【视图模型】的 React Hook

类型

interface useModel<Model extends ViewModel> {
  (): Model;
}

###observer

描述

如果使用了 useModel 来消费视图模型中的响应式属性,对 React 组件需要使用 observer 包装一次,这样才能做到基于数据变化自动渲染

类型

interface observer<Component extends React.FC> {
  (component: Component): Component;
}