asab_webui_components 27.2.4 → 27.3.1

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.
@@ -20,6 +20,10 @@ function PubSubProvider(_ref) {
20
20
  var eventsRef = (0, _react.useRef)({});
21
21
  // Subscribe to an event
22
22
  var subscribe = (0, _react.useCallback)((event, callback) => {
23
+ if (!event || typeof callback !== 'function') {
24
+ console.error('PubSub subscribe requires a valid event name and callback function');
25
+ return () => {}; // Return no-op unsubscribe
26
+ }
23
27
  if (!eventsRef.current[event]) {
24
28
  eventsRef.current[event] = [];
25
29
  }
@@ -27,21 +31,49 @@ function PubSubProvider(_ref) {
27
31
 
28
32
  // Return unsubscribe function
29
33
  return () => {
30
- eventsRef.current[event] = eventsRef.current[event].filter(cb => cb !== callback);
34
+ if (eventsRef.current[event]) {
35
+ eventsRef.current[event] = eventsRef.current[event].filter(cb => cb !== callback);
36
+ }
31
37
  };
32
38
  }, []);
33
39
 
34
40
  // Publish an event
35
41
  var publish = (0, _react.useCallback)((event, data) => {
36
42
  if (eventsRef.current[event]) {
37
- eventsRef.current[event].forEach(callback => callback(data));
43
+ eventsRef.current[event].forEach(callback => {
44
+ try {
45
+ callback(data);
46
+ } catch (error) {
47
+ console.error("Error in PubSub callback for event \"".concat(event, "\":"), error);
48
+ }
49
+ });
38
50
  }
39
51
  }, []);
40
- return /*#__PURE__*/_react.default.createElement(PubSubContext.Provider, {
41
- value: {
42
- app,
43
- subscribe,
44
- publish
52
+
53
+ // Assign a publish and subscribe methods to a app object (to obtain the publish/subscribe in non-react environments)
54
+ (0, _react.useLayoutEffect)(() => {
55
+ if (app) {
56
+ app.PubSub = {
57
+ publish,
58
+ subscribe
59
+ };
45
60
  }
61
+ return () => {
62
+ if (app) {
63
+ app.PubSub = undefined;
64
+ }
65
+ // Clear all subscriptions on unmount to prevent memory leaks
66
+ eventsRef.current = {};
67
+ };
68
+ }, [app, publish, subscribe]);
69
+
70
+ // Memoized pubsub values, to avoid unnecessary re-renders
71
+ var value = (0, _react.useMemo)(() => ({
72
+ app,
73
+ subscribe,
74
+ publish
75
+ }), [app, subscribe, publish]);
76
+ return /*#__PURE__*/_react.default.createElement(PubSubContext.Provider, {
77
+ value: value
46
78
  }, children);
47
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asab_webui_components",
3
- "version": "27.2.4",
3
+ "version": "27.3.1",
4
4
  "license": "BSD-3-Clause",
5
5
  "description": "TeskaLabs ASAB WebUI Components Library",
6
6
  "contributors": [
@@ -45,10 +45,10 @@
45
45
  "bootstrap": "^5.3.1",
46
46
  "bootstrap-icons": "^1.10.5",
47
47
  "date-fns": "^4.1.0",
48
- "i18next": "^25.4.2",
48
+ "i18next": "^25.5.2",
49
49
  "react": "^19.0.0",
50
50
  "react-dom": "^19.0.0",
51
- "react-i18next": "^15.7.3",
51
+ "react-i18next": "^16.0.0",
52
52
  "@microlink/react-json-view": "^1.26.2",
53
53
  "react-router": "^7.8.2",
54
54
  "reactstrap": "^9.2.0"