Skip to content

Commit

Permalink
fix: rm unnedded calls, wss tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
Elin Angelow committed Apr 5, 2024
1 parent 8d9faa5 commit ccafb6a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
7 changes: 3 additions & 4 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,20 @@ module.exports = () => {
.reduce((prev, curr) => {
const ln = layerProps(curr, createConfig, Config);
console.log(`Add Layer: ${ln.layerName} for namespace ${ln.namespace}`);
const comp = curr({
return curr({
prev,
config: ln.config,
wires,
list: methodsList,
allMethods
});
return () => comp;
},
() => Methods({
Methods({
wires,
list: methodsList,
config: layerProps(Methods, createConfig, Config).config
}));
const comp = new (Component());
const comp = new Component();
components.push(comp);
return api;
},
Expand Down
6 changes: 2 additions & 4 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ log4js.configure({
const loggers = new Map();
const Logger = ({
prev,
config,
wires,
list
config
}) => {
class logger extends prev({wires, list, config}) {
class logger extends prev {
log(level, ...rest) {
let l = loggers.get(this.namespace);
if (!l) {
Expand Down
6 changes: 2 additions & 4 deletions lib/sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ const exposeMethods = require('expose-sql-methods/lib/postgres');

const Sql = ({
prev,
config,
wires,
list
config
}) => {
class sql extends prev({wires, list}) {
class sql extends prev {
async init() {
this.log('info', 'Sql', 'Init');
await migration({
Expand Down
18 changes: 8 additions & 10 deletions lib/wss.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ const dumpingComm = (fn) => {
};
const Wss = ({
prev,
config,
wires,
list
config
}) => {
class wss extends prev({wires, list}) {
class wss extends prev {
constructor() {
super();
this.server = undefined;
Expand Down Expand Up @@ -65,7 +63,7 @@ const Wss = ({
}
async init() {
this.log('info', 'Wss', 'Init');
await this.connect();
await this.initWssServer();
this.add({name: this.namespace + '.write', fn: async(message) => {
try {
if (!message.id) {
Expand Down Expand Up @@ -266,11 +264,15 @@ const Wss = ({
this.refreshConnection(id);
return this.connections.get(id)?.connection;
}
async connect() {
async initWssServer() {
return await (new Promise((resolve, reject) => {
this.server = new WebSocketServer({
port: config.port
});
this.server.on('error', (error) => {
this.log('error', 'Wss', error);
reject(error);
});
this.server.on('connection', async(wsClient, req) => {
const connectionId = uuidv4();
try {
Expand All @@ -296,10 +298,6 @@ const Wss = ({
wsClient.close();
}
});
this.server.on('error', (error) => {
this.log('error', 'Wss', error);
reject(error);
});
this.server.on('listening', () => {
this.log('info', 'Wss', 'Listening', this.server.address());
resolve();
Expand Down

0 comments on commit ccafb6a

Please sign in to comment.