Adding toOption function.

This commit is contained in:
Dessalines 2022-06-15 19:17:28 -04:00
parent a3a42657fd
commit 05e8d7714c
2 changed files with 4 additions and 17 deletions

View file

@ -7,6 +7,9 @@ export function toUndefined<T>(opt: Option<T>) {
return opt.isSome() ? opt.unwrap() : undefined;
}
/**
* Converts a null value to an option.
*/
export function toOption<T>(val: T): Option<T> {
return Some(val || undefined);
}

View file

@ -647,26 +647,9 @@ export class LemmyWebsocket {
function wrapper<MessageType>(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<ResponseType>(
msg: any,
responseClass: ClassConstructor<ResponseType>
): ResponseType {
// Have to deserialize the response again into the correct class
return deserialize(responseClass, serialize(msg.data));
}