systemlynx 1.12.8 → 1.12.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.js +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/systemlynx/App/components/loadModules.js +1 -0
- package/systemlynx/Client/components/ServiceRequestHandler.js +5 -3
- package/systemlynx/Client/components/SocketDispatcher.js +1 -1
- package/systemlynx/Dispatcher/Dispatcher.js +7 -5
- package/systemlynx/ServerManager/ServerManager.js +1 -0
- package/systemlynx/ServerManager/components/Router.js +2 -0
- package/utils/throttle.js +19 -0
package/client.js
CHANGED
|
@@ -5,7 +5,7 @@ const createDispatcher = require("./systemlynx/Dispatcher/Dispatcher");
|
|
|
5
5
|
|
|
6
6
|
const HttpClient = createHttpClient();
|
|
7
7
|
const Client = createClient();
|
|
8
|
-
const Dispatcher = createDispatcher();
|
|
8
|
+
const Dispatcher = new createDispatcher();
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
11
|
//Export these pre-created objects for convenient object destructuring
|
package/index.js
CHANGED
|
@@ -15,7 +15,7 @@ const LoadBalancer = isNode ? createLoadBalancer() : null;
|
|
|
15
15
|
const App = createApp();
|
|
16
16
|
const HttpClient = createHttpClient();
|
|
17
17
|
const Client = createClient();
|
|
18
|
-
const Dispatcher = createDispatcher();
|
|
18
|
+
const Dispatcher = new createDispatcher();
|
|
19
19
|
|
|
20
20
|
module.exports = {
|
|
21
21
|
//Export these pre-created objects for convenient object destructuring
|
package/package.json
CHANGED
|
@@ -63,9 +63,11 @@ module.exports = function ServiceRequestHandler(
|
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
const ErrorHandler = (err, errCount, cb) => {
|
|
66
|
-
if (!err.isAxiosError)
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
if (!err.isAxiosError) throw err;
|
|
67
|
+
if (!err.response) throw err;
|
|
68
|
+
if (!err.response.data) throw err;
|
|
69
|
+
|
|
70
|
+
if (err.response.data.SystemLynxService) {
|
|
69
71
|
cb(err.response.data);
|
|
70
72
|
} else if (errCount <= 3) {
|
|
71
73
|
errCount++;
|
|
@@ -7,7 +7,7 @@ module.exports = function SocketDispatcher(namespace, events = {}, systemContext
|
|
|
7
7
|
(this || {}).on && (this || {}).emit
|
|
8
8
|
? this
|
|
9
9
|
: createDispatcher.apply(this, [events, systemContext]);
|
|
10
|
-
const socket = io.connect(namespace);
|
|
10
|
+
const socket = io.connect(namespace, { reconnection: false });
|
|
11
11
|
socket.on("dispatch", (event) => dispatcher.emit(event.name, event.data, event));
|
|
12
12
|
socket.on("disconnect", () => {
|
|
13
13
|
socket.disconnect();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
const throttle = require("../../utils/throttle");
|
|
2
|
+
|
|
2
3
|
module.exports = function createDispatcher(events = {}, systemContext) {
|
|
3
|
-
const Dispatcher = this || {};
|
|
4
|
+
const Dispatcher = this !== window ? this || {} : {};
|
|
4
5
|
|
|
5
6
|
Dispatcher.emit = (eventName, data, event) => {
|
|
6
7
|
if (events[eventName])
|
|
@@ -10,12 +11,13 @@ module.exports = function createDispatcher(events = {}, systemContext) {
|
|
|
10
11
|
return Dispatcher;
|
|
11
12
|
};
|
|
12
13
|
|
|
13
|
-
Dispatcher.on = (eventName, callback) => {
|
|
14
|
+
Dispatcher.on = (eventName, callback, { limit, interval } = {}) => {
|
|
14
15
|
if (typeof callback !== "function") return Dispatcher;
|
|
15
|
-
|
|
16
|
+
const name = callback.name;
|
|
17
|
+
if (typeof interval === "number") callback = throttle(callback, limit, interval);
|
|
16
18
|
if (!events[eventName]) events[eventName] = [];
|
|
17
19
|
|
|
18
|
-
if (
|
|
20
|
+
if (name) {
|
|
19
21
|
//if the function has a name and it already present don't add it
|
|
20
22
|
const i = events[eventName].findIndex((fn) => fn.name === callback.name);
|
|
21
23
|
if (i === -1) events[eventName].push(callback);
|
|
@@ -146,6 +146,7 @@ module.exports = function createServerManager(customServer, customWebSocketServe
|
|
|
146
146
|
});
|
|
147
147
|
|
|
148
148
|
function addMiddleware(middleware) {
|
|
149
|
+
if (Array.isArray(middleware)) return middleware.map(addMiddleware);
|
|
149
150
|
if (!serverConfigurations.validators[name])
|
|
150
151
|
serverConfigurations.validators[name] = [];
|
|
151
152
|
serverConfigurations.validators[name].push(async function (req, res, next) {
|
|
@@ -11,6 +11,7 @@ module.exports = function createRouter(server, config) {
|
|
|
11
11
|
req.module_name = module_name;
|
|
12
12
|
req.fn = fn;
|
|
13
13
|
req.Module = Module;
|
|
14
|
+
req.module = Module;
|
|
14
15
|
next();
|
|
15
16
|
},
|
|
16
17
|
setHelpers,
|
|
@@ -26,6 +27,7 @@ module.exports = function createRouter(server, config) {
|
|
|
26
27
|
req.module_name = module_name;
|
|
27
28
|
req.fn = method;
|
|
28
29
|
req.Module = Module;
|
|
30
|
+
req.module = Module;
|
|
29
31
|
next();
|
|
30
32
|
},
|
|
31
33
|
setHelpers,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module.exports = function throttleByCount(func, limit = 1, interval) {
|
|
2
|
+
let callCount = 0;
|
|
3
|
+
let resetTimer;
|
|
4
|
+
|
|
5
|
+
return function (...args) {
|
|
6
|
+
callCount++;
|
|
7
|
+
|
|
8
|
+
if (callCount <= limit) {
|
|
9
|
+
func.apply(this, args);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (!resetTimer) {
|
|
13
|
+
resetTimer = setTimeout(() => {
|
|
14
|
+
callCount = 0;
|
|
15
|
+
resetTimer = null;
|
|
16
|
+
}, interval);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
};
|