refactor: socket
This commit is contained in:
parent
18eec3a986
commit
770813148d
|
@ -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) => {
|
||||
|
|
|
@ -15,6 +15,8 @@ const decorate = compose(
|
|||
EventEmitter,
|
||||
);
|
||||
|
||||
export const socket = (latus) => latus.config['%socket'];
|
||||
|
||||
export default class SocketClient extends decorate(Class) {
|
||||
|
||||
constructor(latus) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user