@osimatic/helpers-js 1.0.46 → 1.0.47

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/event_bus.js ADDED
@@ -0,0 +1,37 @@
1
+ class EventBus {
2
+ constructor() {
3
+ this.events = {};
4
+ }
5
+
6
+ publish(name, data) {
7
+ var handlers = this.events[name];
8
+
9
+ if (!!handlers === false) {
10
+ return;
11
+ }
12
+
13
+ handlers.forEach((handler) => handler.call(this, data));
14
+ }
15
+
16
+ subscribe(name, handler) {
17
+ var handlers = this.events[name];
18
+
19
+ if (!!handlers === false) {
20
+ handlers = this.events[name] = [];
21
+ }
22
+
23
+ handlers.push(handler);
24
+ }
25
+
26
+ unsubscribe(name, handler) {
27
+ var handlers = this.events[name];
28
+
29
+ if (!!handlers === false) {
30
+ return;
31
+ }
32
+
33
+ handlers.splice(handlers.indexOf(handler));
34
+ }
35
+ }
36
+
37
+ module.exports = { EventBus };
package/index.js CHANGED
@@ -35,18 +35,19 @@ const { ImportFromCsv } = require('./import_from_csv');
35
35
  const { JwtToken, JwtSession } = require('./jwt');
36
36
  const { ListBox } = require('./list_box');
37
37
  const { WebRTC } = require('./web_rtc');
38
+ const { EventBus } = require('./event_bus');
38
39
 
39
40
  // exports surcouche lib externe
40
41
  const { GoogleCharts } = require('./google_charts');
41
42
  const { GoogleRecaptcha } = require('./google_recaptcha');
42
43
  const { GoogleMap } = require('./google_maps');
43
44
  const { OpenStreetMap } = require('./open_street_map');
44
- const { WebSocket, EventBus } = require('./web_socket');
45
+ const { WebSocket } = require('./web_socket');
45
46
 
46
47
  module.exports = {
47
48
  Array, Object, Number, String,
48
49
  HTTPRequest, Cookie, UrlAndQueryString, IBAN, BankCard, AudioMedia, UserMedia, PersonName, Email, TelephoneNumber, DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, Duration, File, CSV, Img, FormHelper, Country, PostalAddress, GeographicCoordinates, SocialNetwork,
49
- Browser, DataTable, Pagination, Navigation, DetailsSubArray, SelectAll, MultipleActionInTable, FormDate, InputPeriod, ShoppingCart, FlashMessage, CountDown, ImportFromCsv, JwtToken, JwtSession, ListBox, WebRTC,
50
+ Browser, DataTable, Pagination, Navigation, DetailsSubArray, SelectAll, MultipleActionInTable, FormDate, InputPeriod, ShoppingCart, FlashMessage, CountDown, ImportFromCsv, JwtToken, JwtSession, ListBox, WebRTC, WebSocket, EventBus,
50
51
  sleep, refresh, chr, ord, trim, empty,
51
52
  GoogleCharts, GoogleRecaptcha, GoogleMap, OpenStreetMap
52
53
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.0.46",
3
+ "version": "1.0.47",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/web_socket.js CHANGED
@@ -16,7 +16,8 @@ class WebSocket {
16
16
 
17
17
  static connect(url, options, connectInitPayload, onConnectionAckCallback, onUnavailableCallback) {
18
18
  const io = require('socket.io-client');
19
-
19
+ const EventBus = require('./event_bus');
20
+
20
21
  this.eventBus = new EventBus();
21
22
  this.logged = false;
22
23
  this.instance = io(url, options);
@@ -63,40 +64,4 @@ class WebSocket {
63
64
  }
64
65
  }
65
66
 
66
- class EventBus {
67
- constructor() {
68
- this.events = {};
69
- }
70
-
71
- publish(name, data) {
72
- var handlers = this.events[name];
73
-
74
- if (!!handlers === false) {
75
- return;
76
- }
77
-
78
- handlers.forEach((handler) => handler.call(this, data));
79
- }
80
-
81
- subscribe(name, handler) {
82
- var handlers = this.events[name];
83
-
84
- if (!!handlers === false) {
85
- handlers = this.events[name] = [];
86
- }
87
-
88
- handlers.push(handler);
89
- }
90
-
91
- unsubscribe(name, handler) {
92
- var handlers = this.events[name];
93
-
94
- if (!!handlers === false) {
95
- return;
96
- }
97
-
98
- handlers.splice(handlers.indexOf(handler));
99
- }
100
- }
101
-
102
- module.exports = { WebSocket, EventBus };
67
+ module.exports = { WebSocket };