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

ractor-react

v1.1.8

Published

react binding for Ractor

Downloads

26

Readme

ractor-react

安装

npm i ractor-react

state store vs domain store

ractor-react 支持两种用法,分别是 动态加载依赖注入。分别对应 mobxstate storereduxdomain store

state store

所谓 state store, 就是你可以把 store 当一个外部状态使用,和内部状态类似,view 是监听这个 state 的,也是动态加载和卸载的。

@Connect(CounterStore)
export class Counter extends React.Component<{ value: number }> {}

这里注入的 store 在组件 didMount 的时候初始化并订阅,在组件 Unmount 的时候取消监听。你可以把这个 store 和你组件放在一起,仅仅作为状态和行为的集合,和视图做逻辑分离。

具体代码可以看 examples 里的 counter

domain store

domain store。类似领域驱动设计里的 model,对应后端的 model 层,也可以简单的理解为对应数据库里的表。和 redux 的 reducer 有点类似。

render(
  <Provider stores={[TodoStore]}>
    {React.createElement(Todo)}
  </Provider>,
  document.getElementById("app")
)

使用 Provider 组件注入 我们所有的 store,Provider 内部会依次全部实例化,并放在 context 里面。

@Providers([AStore, BStore], (aStore, bStore) => ({}))
export default class TodoComponent extends React.Component {}

使用 Providers 从全局中选择性定义传入的 store

Api

Privider

高阶组件,需要传入 stores 数组。

<Provider system={system} stores={[TodoStore, CounterStore]}>
  // 你的组件
</Provider>,

connect

实现动态注入 store 的函数,方便喜欢 pub/sub 模式的同学,连接 store 和 react 的高阶组件。会在组件初始化传入的 store, 并监听之。组件卸载的时候同时从 system 中卸载 store.

@Connect(TodoStore)(TodoComponent)

Providers

依赖注入的一直实现方式。Providers 会从 context 中找到 provide 的实例的 state 通过 selector 筛选之后通过 props 传给你的组件。灵感上参考了很多 angular 的依赖注入

@Providers([AStore, BStore], (aStore, bStore) => ({}))