Skip to content

Commit caabb69

Browse files
committed
Address comments
1 parent 864277a commit caabb69

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

lib/node.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -861,11 +861,11 @@ class Node extends rclnodejs.ShadowNode {
861861
if (!(publisher instanceof Publisher)) {
862862
throw new TypeError('Invalid argument');
863863
}
864-
if (publisher._eventHandlers) {
865-
publisher._eventHandlers.forEach((handler) => {
864+
if (publisher.events) {
865+
publisher.events.forEach((handler) => {
866866
this._destroyEntity(handler, this._events);
867867
});
868-
publisher._eventHandlers = [];
868+
publisher.events = [];
869869
}
870870
this._destroyEntity(publisher, this._publishers, false);
871871
}
@@ -879,11 +879,11 @@ class Node extends rclnodejs.ShadowNode {
879879
if (!(subscription instanceof Subscription)) {
880880
throw new TypeError('Invalid argument');
881881
}
882-
if (subscription._eventHandlers) {
883-
subscription._eventHandlers.forEach((handler) => {
882+
if (subscription.events) {
883+
subscription.events.forEach((handler) => {
884884
this._destroyEntity(handler, this._events);
885885
});
886-
subscription._eventHandlers = [];
886+
subscription.events = [];
887887
}
888888

889889
this._destroyEntity(subscription, this._subscriptions);

lib/publisher.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class Publisher extends Entity {
2727
constructor(handle, typeClass, topic, options, node, eventCallbacks) {
2828
super(handle, typeClass, options);
2929
if (node && eventCallbacks) {
30-
this._eventHandlers = eventCallbacks.createEventHandlers(this.handle);
31-
node._events = node._events.concat(this._eventHandlers);
30+
this._events = eventCallbacks.createEventHandlers(this.handle);
31+
node._events.push(...this._events);
3232
}
3333
}
3434

@@ -111,18 +111,26 @@ class Publisher extends Entity {
111111
return rclnodejs.waitForAllAcked(this._handle, timeout);
112112
}
113113

114-
get eventHandlers() {
115-
if (!this._eventHandlers) {
114+
/**
115+
* Get the event handlers for this publisher.
116+
* @returns {Array} The array of event handlers for this publisher.
117+
*/
118+
get events() {
119+
if (!this._events) {
116120
throw new Error('Event handlers are not set for this publisher.');
117121
}
118-
return this._eventHandlers;
122+
return this._events;
119123
}
120124

121-
set eventHandlers(eventHandlers) {
122-
if (this._eventHandlers) {
125+
/**
126+
* Set the event handlers for this publisher.
127+
* @param {Array} events - The array of event handlers to be set for this publisher.
128+
*/
129+
set events(events) {
130+
if (this._events) {
123131
throw new Error('Event handlers are already set for this publisher.');
124132
}
125-
this._eventHandlers = eventHandlers;
133+
this._events = events;
126134
}
127135
}
128136

lib/subscription.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class Subscription extends Entity {
4444
this._isRaw = options.isRaw || false;
4545

4646
if (node && eventCallbacks) {
47-
this._eventHandlers = eventCallbacks.createEventHandlers(this.handle);
48-
node._events = node._events.concat(this._eventHandlers);
47+
this._events = eventCallbacks.createEventHandlers(this.handle);
48+
node._events.push(...this._events);
4949
}
5050
}
5151

@@ -152,6 +152,22 @@ class Subscription extends Entity {
152152
get publisherCount() {
153153
return rclnodejs.getPublisherCount(this._handle);
154154
}
155+
156+
/**
157+
* Get the event handlers for this subscription.
158+
* @returns {Array} The array of event handlers for this subscription.
159+
*/
160+
get events() {
161+
return this._events;
162+
}
163+
164+
/**
165+
* Set the event handlers for this subscription.
166+
* @param {Array} events - The array of event handlers for this subscription.
167+
*/
168+
set events(events) {
169+
this._events = events;
170+
}
155171
}
156172

157173
module.exports = Subscription;

0 commit comments

Comments
 (0)