@ 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饮用沙袋requestGql 请求 < 变量 >
实例
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对象? 吗? (可选,默认){}(中文(简体) )
实例
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.