From f76ac73e9d21c80abe0118007e168e4f5d525036 Mon Sep 17 00:00:00 2001 From: enisdenjo Date: Thu, 22 Oct 2020 13:00:41 +0200 Subject: [PATCH] fix(server): No need to bind `this` scope --- src/server.ts | 5 ++--- src/tests/client.ts | 6 +++++- src/utils.ts | 4 ---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/server.ts b/src/server.ts index fc1bd742..fc22f5f7 100644 --- a/src/server.ts +++ b/src/server.ts @@ -34,7 +34,6 @@ import { isAsyncIterable, hasOwnObjectProperty, hasOwnStringProperty, - noop, } from './utils'; import { ID } from './types'; @@ -324,7 +323,7 @@ export function createServer( Object.entries(ctxRef.current.subscriptions).forEach( ([, subscription]) => { - (subscription.return || noop)(); + subscription.return?.(); }, ); } @@ -544,7 +543,7 @@ export function createServer( } case MessageType.Complete: { if (ctx.subscriptions[message.id]) { - await (ctx.subscriptions[message.id].return ?? noop)(); + await ctx.subscriptions[message.id].return?.(); } break; } diff --git a/src/tests/client.ts b/src/tests/client.ts index 3acd1d72..1e04716e 100644 --- a/src/tests/client.ts +++ b/src/tests/client.ts @@ -6,7 +6,11 @@ import WebSocket from 'ws'; import { url, startServer, pubsub } from './fixtures/simple'; import { Server } from '../server'; import { createClient, EventListener } from '../client'; -import { noop } from '../utils'; + +// Just does nothing +export function noop(): void { + /**/ +} /** Waits for the specified timeout and then resolves the promise. */ const wait = (timeout: number) => diff --git a/src/utils.ts b/src/utils.ts index cc8c0d47..f593b935 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -51,7 +51,3 @@ export function hasOwnStringProperty< typeof obj[prop] === 'string' ); } - -export function noop(): void { - /**/ -}