From 05e8d7714c418792016cfdb58ba4480c49208ef9 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 15 Jun 2022 19:17:28 -0400 Subject: [PATCH] Adding toOption function. --- src/utils.ts | 3 +++ src/websocket.ts | 18 +----------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index b034a11..2fb61f1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -7,6 +7,9 @@ export function toUndefined(opt: Option) { return opt.isSome() ? opt.unwrap() : undefined; } +/** + * Converts a null value to an option. + */ export function toOption(val: T): Option { return Some(val || undefined); } diff --git a/src/websocket.ts b/src/websocket.ts index 3bf7479..4c7822b 100644 --- a/src/websocket.ts +++ b/src/websocket.ts @@ -647,26 +647,9 @@ export class LemmyWebsocket { function wrapper(op: UserOperation, data: MessageType) { let send = serialize({ op: UserOperation[op], data }); - console.log(send); return send; } -/** - * A websocket JSON response that includes the errors. - */ -// interface WebSocketJsonResponse { -// op?: string; - -// /** -// * This contains the data for a websocket response. -// * -// * The correct response type if given is in [[LemmyHttp]]. -// */ -// data?: ResponseType; -// error?: string; -// reconnect?: boolean; -// } - export function wsUserOp(msg: any): UserOperation { let opStr: string = msg.op; return UserOperation[opStr as keyof typeof UserOperation]; @@ -679,5 +662,6 @@ export function wsJsonToRes( msg: any, responseClass: ClassConstructor ): ResponseType { + // Have to deserialize the response again into the correct class return deserialize(responseClass, serialize(msg.data)); }