@absinthe/socket

中文文档
0.2.1发布于 2019/02/20MITESM + CJS近 30 天下载 17.4万

饮用套接字

中文使用文档
文档目录14 节
  1. 特征
  2. 安装
  3. 使用 无
  4. 使用 线条
  5. 类型
  6. API 密码
  7. 取消( e)
  8. 创建
  9. 观察
  10. 发送
  11. 可读
  12. 取消观察
  13. 取消观察
  14. 许可证

@ absinthe/ socket (韩语)

饮用套接字

特征

  • 可移动功能 API

    除Absinthe Socket外,所有收到并返回的物体 情况(有计划使这种不可改变)在以下情况下得到处理: 无法改变的方式。 物体没有方法,相反,我们提供依赖性 无国籍的功能与他们互动.

  • 懒惰的连接/ 加入

    如果提供凤凰套接字实例时未连接,则不用 在创建时连接, 连接将在下一个时建立 援引 发送。 。 。 .

  • 处理连接丢失的待处理操作

    等待突变中止, 询问会很不满, 订阅 复设所.

  • 可撤销的请求

    通话 取消( e) 从 assinthe Socket 实例中删除给定的通知符 并发送一个取消事件给其所有观察者和未订阅者,以防它发生 持有订阅申请.

  • 业务重复

    如果已经向 发送,而不是发送 它将再次返回与之相关的通知者.

  • 观察员对可收回错误的支持

    由于失去的连接被处理,那么需要存在两个事件来代表 3⁄4 ̄ ̧漯B.

  • 每个请求的多名观察员

    通话 发送 返回允许附加任何编号的通知符 观察员,在结果到来时将予以通知.

  • 根据操作类型进行观察互动

    就订阅而言, 开始 当 订阅成立,其他类型则订阅 (口水和变异),当请求发出.

安装

使用 无

$ npm install --save phoenix @absinthe/socket

使用 线条

$ yarn add phoenix @absinthe/socket

类型

type RequestStatus = "canceled" | "canceling" | "pending" | "sent" | "sending";

// from @jumpn/utils-graphql
type GqlRequest<Variables: void | Object = void> = {
  operation: string,
  variables?: Variables
};

// from @jumpn/utils-graphql
type GqlResponse<Data> = {
  data?: Data,
  errors?: Array<GqlError>
};

// from @jumpn/utils-graphql
type GqlOperationType = "mutation" | "query" | "subscription";

type Observer<Result, Variables: void | Object = void> = {|
  onAbort?: (error: Error) => any,
  onCancel?: () => any,
  onError?: (error: Error) => any,
  onStart?: (notifier: Notifier<Result, Variables>) => any,
  onResult?: (result: Result) => any
|};

type Notifier<Result, Variables: void | Object = void> = {|
  activeObservers: $ReadOnlyArray<Observer<Result, Variables>>,
  canceledObservers: $ReadOnlyArray<Observer<Result, Variables>>,
  isActive: boolean,
  operationType: GqlOperationType,
  request: GqlRequest<Variables>,
  requestStatus: RequestStatus,
  subscriptionId?: string
|};

type AbsintheSocket = {|
  channel: Channel,
  channelJoinCreated: boolean,
  notifiers: Array<Notifier<any>>,
  phoenixSocket: PhoenixSocket
|};

API 密码

取消( e)

取消向所有观察员发送取消事件的通知人,并 如果持有订阅请求, 则不订阅

参数

  • absintheSocket 饮用沙袋
  • notifier 通知“ 任何,任何”

实例

import * as withAbsintheSocket from "@absinthe/socket";

withAbsintheSocket.cancel(absintheSocket, notifier);

回返 饮用沙袋

创建

使用给定的 Phoenix Socket 实例创建 Absinthe Socket

参数

  • phoenixSocket 凤凰套

实例

import * as withAbsintheSocket from "@absinthe/socket";
import {Socket as PhoenixSocket} from "phoenix";

const absintheSocket = withAbsintheSocket.create(
  new PhoenixSocket("ws://localhost:4000/socket")
);

回返 饮用沙袋

观察

使用所提供的观察员给予的观察

参数

  • absintheSocket 饮用沙袋
  • notifier 通知器<结果,变量>
  • observer 观察器 < 结果, 变量 >

实例

import * as withAbsintheSocket from "@absinthe/socket"

const logEvent = eventName => (...args) => console.log(eventName, ...args);

const updatedNotifier = withAbsintheSocket.observe(absintheSocket, notifier, {
  onAbort: logEvent("abort"),
  onError: logEvent("error"),
  onStart: logEvent("open"),
  onResult: logEvent("result")
});

发送

发送给定的请求并返回一个对象( 通知符) 以跟踪其进度 (见观察功能)

参数

  • absintheSocket 饮用沙袋
  • request Gql 请求 < 变量 >

实例

import * as withAbsintheSocket from "@absinthe/socket";

const operation = `
  subscription userSubscription($userId: ID!) {
    user(userId: $userId) {
      id
      name
    }
  }
`;

// This example uses a subscription, but the functionallity is the same for
// all operation types (queries, mutations and subscriptions)

const notifier = withAbsintheSocket.send(absintheSocket, {
  operation,
  variables: {userId: 10}
});

回返 通知器<结果,变量>

可读

创建一个可观察的,将遵循给定的通知符

参数

  • absintheSocket 饮用沙袋
  • notifier 通知器<结果,变量>
  • options 对象? 吗? (可选,默认) {}(中文(简体) )
    • options.unsubscribe 函数 (): 未定义? 吗?
    • options.onError 函数( 错误 : 错误: 未定义? 吗?
    • options.onStart 函数( 通知符: 通知符 < Result, 变量 > ): 未定义? 吗?
    • options.handlers ...任何东西

实例

import * as withAbsintheSocket from "@absinthe/socket";

const unobserveOrCancelIfNeeded = (absintheSocket, notifier, observer) => {
  if (notifier && observer) {
    withAbsintheSocket.unobserveOrCancel(absintheSocket, notifier, observer);
  }
};

const logEvent = eventName => (...args) => console.log(eventName, ...args);

const observable = withAbsintheSocket.toObservable(absintheSocket, notifier, {
  onError: logEvent("error"),
  onStart: logEvent("open"),
  unsubscribe: unobserveOrCancelIfNeeded
});

回返 可观察

取消观察

从通知中除去观察员

参数

  • absintheSocket 饮用沙袋
  • notifier 通知“ 任何,任何”
  • observer 观察器“ 任何,任何”

实例

import * as withAbsintheSocket from "@absinthe/socket";

withAbsintheSocket.unobserve(absintheSocket, notifier, observer);

回返 饮用沙袋

取消观察

如果除给定的观察者之外没有其他观察者,则取消通知者,或 将观察员与通知人分开,否则

参数

  • absintheSocket 饮用沙袋
  • notifier 通知器<结果,变量>
  • observer 观察器 < 结果, 变量 >

实例

import * as withAbsintheSocket from "@absinthe/socket";

withAbsintheSocket.unobserve(absintheSocket, notifier, observer);

许可证

麻省理工学院 :版权:Jumpn Limited.

版本与发布记录

@absinthe/socket 共发布 13 个版本,首次发布于 2017/11/08;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.2.1latest2019/02/207 年前
0.2.02018/12/147 年前
0.1.102018/01/038 年前
0.1.92017/11/288 年前
0.1.82017/11/108 年前
0.1.72017/11/108 年前

关于 @absinthe/socket 的常见问题

@absinthe/socket 是什么?

饮用套接字

如何安装 @absinthe/socket?

在项目目录运行 npm install @absinthe/socket,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:phoenix(^1.4.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@absinthe/socket 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/absinthe__socket 是否存在。

@absinthe/socket 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@absinthe/socket 可以商用吗?

@absinthe/socket 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@absinthe/socket 的下载量有多少?

根据 npm 官方下载统计,@absinthe/socket 在 2026/10/05 – 2026/11/03 这 30 天内被下载 174,492 次,日均约 5,816 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@absinthe/socket 还在维护吗?

最新版本 0.2.1 发布于 2019/02/20(7 年前);至今共发布 13 个版本,其中过去 12 个月发布了 0 个;首次发布于 2017/11/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。