refactor: socket
This commit is contained in:
parent
18eec3a986
commit
770813148d
|
@ -1,6 +1,8 @@
|
||||||
import acceptor from '../packet/acceptor';
|
import acceptor from '../packet/acceptor';
|
||||||
import SocketClient from './socket';
|
import SocketClient from './socket';
|
||||||
|
|
||||||
|
export {socket} from './socket';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
hooks: {
|
hooks: {
|
||||||
'@latus/http/client/up': (latus) => {
|
'@latus/http/client/up': (latus) => {
|
||||||
|
|
|
@ -15,6 +15,8 @@ const decorate = compose(
|
||||||
EventEmitter,
|
EventEmitter,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const socket = (latus) => latus.config['%socket'];
|
||||||
|
|
||||||
export default class SocketClient extends decorate(Class) {
|
export default class SocketClient extends decorate(Class) {
|
||||||
|
|
||||||
constructor(latus) {
|
constructor(latus) {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import {LatusContext, React} from '@latus/react';
|
import {LatusContext, React} from '@latus/react';
|
||||||
|
|
||||||
|
import {socket} from '../client/socket';
|
||||||
|
|
||||||
const {useContext} = React;
|
const {useContext} = React;
|
||||||
|
|
||||||
export default function useSocket() {
|
export default function useSocket() {
|
||||||
|
@ -7,8 +9,9 @@ export default function useSocket() {
|
||||||
if (!latus) {
|
if (!latus) {
|
||||||
throw new Error('useSocket: no latus context');
|
throw new Error('useSocket: no latus context');
|
||||||
}
|
}
|
||||||
if (!latus.config['%socket']) {
|
const sock = socket(latus);
|
||||||
|
if (!sock) {
|
||||||
throw new Error('useSocket: no configured socket');
|
throw new Error('useSocket: no configured socket');
|
||||||
}
|
}
|
||||||
return latus.config['%socket'];
|
return sock;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user