Skip to content

Commit

Permalink
chore: fix lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
hans00 committed Jun 16, 2023
1 parent 6b00614 commit dc80454
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
30 changes: 18 additions & 12 deletions example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ export default function App() {
const [started, setStarted] = React.useState(false);

React.useEffect(() => {
broker.current.on('error', (err: Error) => {
const currBroker = broker.current;

currBroker.on('error', (err: Error) => {
setError(err);
console.error(err);
});
broker.current.on('close', () => {
currBroker.on('close', () => {
setStarted(false);
});
broker.current.on('listening', () => {
currBroker.on('listening', () => {
setStarted(true);
});
broker.current.on('message', (topic: string, message: Buffer | string) => {
currBroker.on('message', (topic: string, message: Buffer | string) => {
console.log('message', topic, message);
});
broker.current.start();
currBroker.start();

return () => broker.current.stop();
return () => currBroker.stop();
}, []);

const stop = React.useCallback(() => {
Expand All @@ -40,12 +42,16 @@ export default function App() {
<View style={styles.container}>
{started && <Text>Run MQ broker on port 1883</Text>}
{error && <Text>{error.message}</Text>}
{started && <Pressable onPress={stop} style={styles.box}>
<Text>Stop</Text>
</Pressable>}
{!started && <Pressable onPress={start} style={styles.box}>
<Text>Start</Text>
</Pressable>}
{started && (
<Pressable onPress={stop} style={styles.box}>
<Text>Stop</Text>
</Pressable>
)}
{!started && (
<Pressable onPress={start} style={styles.box}>
<Text>Start</Text>
</Pressable>
)}
</View>
);
}
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ export class Server extends EventEmitter {
constructor(opts?: Object) {
super();
this._opts = opts;
this.server = net.createServer();
this.server.on('connection', (socket: net.Socket) => {
this.server = net.createServer((socket: net.Socket) => {
this.emit('connection', new Client(socket, this._opts));
});
this.server.on('error', this.emit.bind(this, 'error'));
Expand Down

0 comments on commit dc80454

Please sign in to comment.