监听者模式

new Subscribe<{
"foo": [arg1: number, arg2: string],
"bar": [arg: boolean],
}>()

Hierarchy (view full)

Constructors

Methods

  • 触发事件

    Type Parameters

    • K extends "network"

      预设的监听事件名称

    Parameters

    • name: K

      事件类型

    • Rest...data: Parameters<{
          network(source: string, type: NetworkType, state: NetworkState, detail: string): void;
      }[K]>

      触发事件的数据

    Returns boolean

    canceled 是否被触发取消

  • 判断是否注册了事件

    Parameters

    • name: "network"

      事件类型

    Returns boolean

  • 解除事件

    如果 name 不传的话解除对应所有事件 如果 name, callback 不传的话解除所有name的所有事件

    Type Parameters

    • K extends "network"

      预设的监听事件名称

    Parameters

    • Optionalname: K

      事件类型

    • Optionalcallback: ((...args: Parameters<{
          network(source: string, type: NetworkType, state: NetworkState, detail: string): void;
      }[K]>) => ReturnType<{
          network(source: string, type: NetworkType, state: NetworkState, detail: string): void;
      }[K]>)

      事件回调函数

        • (...args): ReturnType<{
              network(source: string, type: NetworkType, state: NetworkState, detail: string): void;
          }[K]>
        • Parameters

          • Rest...args: Parameters<{
                network(source: string, type: NetworkType, state: NetworkState, detail: string): void;
            }[K]>

          Returns ReturnType<{
              network(source: string, type: NetworkType, state: NetworkState, detail: string): void;
          }[K]>

    Returns void

  • 注册事件

    Type Parameters

    • K extends "network"

      预设的监听事件名称

    Parameters

    • name: K

      事件类型

    • callback: ((...args: Parameters<{
          network(source: string, type: NetworkType, state: NetworkState, detail: string): void;
      }[K]>) => ReturnType<{
          network(source: string, type: NetworkType, state: NetworkState, detail: string): void;
      }[K]>)

      事件回调函数

        • (...args): ReturnType<{
              network(source: string, type: NetworkType, state: NetworkState, detail: string): void;
          }[K]>
        • Parameters

          • Rest...args: Parameters<{
                network(source: string, type: NetworkType, state: NetworkState, detail: string): void;
            }[K]>

          Returns ReturnType<{
              network(source: string, type: NetworkType, state: NetworkState, detail: string): void;
          }[K]>

    • Optionalonce: boolean

      是否只执行一次

    Returns (() => void)

    解除事件

      • (): void
      • Returns void

  • 注册事件(是否只执行一次)

    Type Parameters

    • K extends "network"

      预设的监听事件名称

    Parameters

    • name: K

      事件类型

    • callback: ((...args: Parameters<{
          network(source: string, type: NetworkType, state: NetworkState, detail: string): void;
      }[K]>) => ReturnType<{
          network(source: string, type: NetworkType, state: NetworkState, detail: string): void;
      }[K]>)

      事件回调函数

        • (...args): ReturnType<{
              network(source: string, type: NetworkType, state: NetworkState, detail: string): void;
          }[K]>
        • Parameters

          • Rest...args: Parameters<{
                network(source: string, type: NetworkType, state: NetworkState, detail: string): void;
            }[K]>

          Returns ReturnType<{
              network(source: string, type: NetworkType, state: NetworkState, detail: string): void;
          }[K]>

    Returns (() => void)

    解除事件

      • (): void
      • Returns void

  • 等待事件

    Type Parameters

    • K extends "network"

      预设的监听事件名称

    Parameters

    • name: K

      事件类型

    • Optionalfilter: ((...args: Parameters<{
          network(source: string, type: NetworkType, state: NetworkState, detail: string): void;
      }[K]>) => boolean | void)

      事件类型

        • (...args): boolean | void
        • Parameters

          • Rest...args: Parameters<{
                network(source: string, type: NetworkType, state: NetworkState, detail: string): void;
            }[K]>

          Returns boolean | void

    Returns Promise<Parameters<{
        network(source: string, type: NetworkType, state: NetworkState, detail: string): void;
    }[K]>>

    触发事件的数据