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

react-channel

v0.3.0

Published

Message flow channel

Downloads

20

Readme

ReactChannel

Message flow channel.

            MChannel Module -- Message-Flow Model


    Com - Publisher +--------> Channel (filter) ---------> Subscriber - Com
                    |           
                    |                    
                    +--------> Channel (filter) ---------> Subscriber - Com                      
                                                         ^
                                                         |
    Com - Publisher +--------> Channel (filter) ---------+
  • Publisher 和 Subscriber 之间是独立管理的。如果没有 Publisher 与 Subscriber 连接, Subscriber 仍然存在,只是不会有消息流动。如果没有 Subscriber 与 Publisher 连接, Publisher 仍然可以发送消息,只是不会有 Subscriber 接收

  • 消息总是从 Publisher 发出,通过 Channel (filter),到达 Subscriber

  • 一个 Channel 只与一个 Publisher、Subscriber 连接

  • 一个 Publisher 可以连接多个 Channel (filter)

  • 一个 Subscriber 可以连接多个 Channel (filter)

  • 一个 Component 最多只有一个 Publisher、Subscriber

  • Publisher 和 Subscriber 没有“解除”的同步绑定,即 Publisher 销毁的时候,Subscriber 不会 自动销毁。如果你想在某个 Publisher 销毁的时候,同时销毁监听的 Subscriber,应该让 Publisher 发送一个消息,比如 “destroy”,Subscriber 收到这条消息的时候,可以自己决定是否销毁

  • Channel (filter) 只负责流动消息,同时可以提供过滤器,只允许特殊条件的消息流动

API

import { Component } from 'react'

declare namespace ReactChannel {
  export interface IAction {
    action: string
  }

  export class Publisher<A extends IAction = IAction> {
    public add(c: Channel): void
    public del(c: Channel): void
    public replace(c1: Channel, c2: Channel): void
    public has(c: Channel): boolean
    public items(): Iterable<Channel>
    public pub(a: A): void
    public attach(c: Channel): void
    public detach(c?: Channel): void
  }

  export class Channel<A extends IAction = IAction> {
    constructor(...actionFilter: Array<string>)
    public attachPublisher(p: Publisher) : void
    public detachPublisher(): void
    public attachSubscriber(s: Subscriber): void
    public detachSubscriber(): boolean
    public pub(a: A): void
  }

  export class Subscriber<A extends IAction = IAction> {
    public add(c: Channel): void
    public del(c: Channel): void
    public replace(c1: Channel, c2: Channel): void
    public has(c: Channel): boolean
    public items(): Iterable<Channel>
    public notify(a: A): void
    public sub(cb: (a: A) => void): void
    public attach(c: Channel): void
    public detach(c?: Channel): void
  }

  export interface IActionComponentProps {
    pub?: (p: Publisher) => void
    sub?: (s: Subscriber) => void
  }

  export abstract class ActionComponent<
    P extends IActionComponentProps, 
    PA extends IAction = IAction,
    SA extends IAction = IAction
  > extends Component<P> {
    constructor(props: P) 
    public componentWillUnmount(): void
  }
} 

export = ReactChannel