From 770813148d56abe824fe3a79b69987de5cfc59b0 Mon Sep 17 00:00:00 2001 From: cha0s Date: Tue, 12 Jan 2021 17:31:30 -0600 Subject: [PATCH] refactor: socket --- packages/socket/src/client/index.js | 2 ++ packages/socket/src/client/socket.js | 2 ++ packages/socket/src/hooks/use-socket.js | 7 +++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/socket/src/client/index.js b/packages/socket/src/client/index.js index 62ddf5a..4e5cec1 100644 --- a/packages/socket/src/client/index.js +++ b/packages/socket/src/client/index.js @@ -1,6 +1,8 @@ import acceptor from '../packet/acceptor'; import SocketClient from './socket'; +export {socket} from './socket'; + export default { hooks: { '@latus/http/client/up': (latus) => { diff --git a/packages/socket/src/client/socket.js b/packages/socket/src/client/socket.js index 83947d3..e8337ef 100644 --- a/packages/socket/src/client/socket.js +++ b/packages/socket/src/client/socket.js @@ -15,6 +15,8 @@ const decorate = compose( EventEmitter, ); +export const socket = (latus) => latus.config['%socket']; + export default class SocketClient extends decorate(Class) { constructor(latus) { diff --git a/packages/socket/src/hooks/use-socket.js b/packages/socket/src/hooks/use-socket.js index c5e7a22..8b159cb 100644 --- a/packages/socket/src/hooks/use-socket.js +++ b/packages/socket/src/hooks/use-socket.js @@ -1,5 +1,7 @@ import {LatusContext, React} from '@latus/react'; +import {socket} from '../client/socket'; + const {useContext} = React; export default function useSocket() { @@ -7,8 +9,9 @@ export default function useSocket() { if (!latus) { throw new Error('useSocket: no latus context'); } - if (!latus.config['%socket']) { + const sock = socket(latus); + if (!sock) { throw new Error('useSocket: no configured socket'); } - return latus.config['%socket']; + return sock; }