@zero-library/common 2.5.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -831,16 +831,9 @@ declare const _default$1: <A extends Array<any>, R = void>(func: (..._args: A) =
831
831
  cancel: () => void;
832
832
  };
833
833
 
834
- /**
835
- * useWebSocket Hook 参数类型定义
836
- */
837
- interface WebSocketProps {
834
+ interface WebSocketManagerOptions {
838
835
  /** WebSocket 服务器地址 */
839
836
  url: string;
840
- /** 接收到消息时的回调函数 */
841
- onMessage: (message: any) => void;
842
- /** 连接关闭时的回调函数(可选) */
843
- onClose?: () => void;
844
837
  /** 心跳间隔时间,单位毫秒,默认 30000ms */
845
838
  heartbeatInterval?: number;
846
839
  /** 心跳消息内容,默认 'ping' */
@@ -854,6 +847,16 @@ interface WebSocketProps {
854
847
  /** 是否开启重连机制,默认 true */
855
848
  isReconnect?: boolean;
856
849
  }
850
+
851
+ /**
852
+ * useWebSocket Hook 参数类型定义
853
+ */
854
+ interface WebSocketProps extends WebSocketManagerOptions {
855
+ /** 接收到消息时的回调函数 */
856
+ onMessage: (message: any) => void;
857
+ /** 连接关闭时的回调函数(可选) */
858
+ onClose?: () => void;
859
+ }
857
860
  /**
858
861
  * useWebSocket Hook 返回值类型定义
859
862
  */
@@ -872,6 +875,14 @@ interface WebSocketType {
872
875
  * - 页面可见性监听
873
876
  * - 连接状态管理
874
877
  * - 消息发送与接收
878
+ * - 多组件共享连接(相同 url 多次调用只会创建一个连接)
879
+ *
880
+ * 使用说明:
881
+ * - 相同 `url` 的多个组件会复用同一个 `WebSocketManager` 和底层连接
882
+ * - 断线重连时会重新创建底层 `WebSocket`,但已注册的组件监听器会继续保留
883
+ * - `onMessage` 和 `onClose` 通过 `ref` 持有最新引用,组件重渲染后无需重新建立连接
884
+ * - 当前 Hook 仅在 `url` 变化时重新订阅;同一 `url` 下修改心跳、重连等配置不会立即更新已存在的管理器实例
885
+ * - 组件卸载或 `url` 变化时会移除当前监听器;当某个 `url` 没有任何订阅者后,连接会在短暂缓冲后销毁
875
886
  *
876
887
  * @example
877
888
  * ```tsx
package/dist/index.d.ts CHANGED
@@ -831,16 +831,9 @@ declare const _default$1: <A extends Array<any>, R = void>(func: (..._args: A) =
831
831
  cancel: () => void;
832
832
  };
833
833
 
834
- /**
835
- * useWebSocket Hook 参数类型定义
836
- */
837
- interface WebSocketProps {
834
+ interface WebSocketManagerOptions {
838
835
  /** WebSocket 服务器地址 */
839
836
  url: string;
840
- /** 接收到消息时的回调函数 */
841
- onMessage: (message: any) => void;
842
- /** 连接关闭时的回调函数(可选) */
843
- onClose?: () => void;
844
837
  /** 心跳间隔时间,单位毫秒,默认 30000ms */
845
838
  heartbeatInterval?: number;
846
839
  /** 心跳消息内容,默认 'ping' */
@@ -854,6 +847,16 @@ interface WebSocketProps {
854
847
  /** 是否开启重连机制,默认 true */
855
848
  isReconnect?: boolean;
856
849
  }
850
+
851
+ /**
852
+ * useWebSocket Hook 参数类型定义
853
+ */
854
+ interface WebSocketProps extends WebSocketManagerOptions {
855
+ /** 接收到消息时的回调函数 */
856
+ onMessage: (message: any) => void;
857
+ /** 连接关闭时的回调函数(可选) */
858
+ onClose?: () => void;
859
+ }
857
860
  /**
858
861
  * useWebSocket Hook 返回值类型定义
859
862
  */
@@ -872,6 +875,14 @@ interface WebSocketType {
872
875
  * - 页面可见性监听
873
876
  * - 连接状态管理
874
877
  * - 消息发送与接收
878
+ * - 多组件共享连接(相同 url 多次调用只会创建一个连接)
879
+ *
880
+ * 使用说明:
881
+ * - 相同 `url` 的多个组件会复用同一个 `WebSocketManager` 和底层连接
882
+ * - 断线重连时会重新创建底层 `WebSocket`,但已注册的组件监听器会继续保留
883
+ * - `onMessage` 和 `onClose` 通过 `ref` 持有最新引用,组件重渲染后无需重新建立连接
884
+ * - 当前 Hook 仅在 `url` 变化时重新订阅;同一 `url` 下修改心跳、重连等配置不会立即更新已存在的管理器实例
885
+ * - 组件卸载或 `url` 变化时会移除当前监听器;当某个 `url` 没有任何订阅者后,连接会在短暂缓冲后销毁
875
886
  *
876
887
  * @example
877
888
  * ```tsx