Skip to content

Commit

Permalink
refactor(platform): set message body even if undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
danielwiehl authored and Marcarrian committed Nov 23, 2022
1 parent 2f8d75c commit f3890f0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export class ɵIntentClient implements IntentClient {
retain: options?.retain ?? false,
headers: new Map(options?.headers),
capability: undefined!, /* set by the broker when dispatching the intent */
body,
};
setBodyIfDefined(intentMessage, body);
return this._brokerGateway.postMessage(MessagingChannel.Intent, intentMessage);
}

Expand All @@ -44,8 +44,8 @@ export class ɵIntentClient implements IntentClient {
retain: options?.retain ?? false,
headers: new Map(headers) /* make a copy for each subscription to support multiple subscriptions */,
capability: undefined!, /* set by the broker when dispatching the intent */
body,
};
setBodyIfDefined(intentMessage, body);
return this._brokerGateway.requestReply$(MessagingChannel.Intent, intentMessage).pipe(throwOnErrorStatus());
});
}
Expand All @@ -63,9 +63,3 @@ export class ɵIntentClient implements IntentClient {
return new MessageHandler(Beans.get(IntentClient).observe$<IN>(selector), callback).subscription;
}
}

function setBodyIfDefined<T>(message: TopicMessage<T> | IntentMessage<T>, body?: T): void {
if (body !== undefined) {
message.body = body;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* SPDX-License-Identifier: EPL-2.0
*/
import {defer, noop, Observable, Subject, Subscription} from 'rxjs';
import {IntentMessage, mapToBody, throwOnErrorStatus, TopicMessage} from '../../messaging.model';
import {mapToBody, throwOnErrorStatus, TopicMessage} from '../../messaging.model';
import {BrokerGateway} from './broker-gateway';
import {MessagingChannel, PlatformTopics, TopicSubscribeCommand} from '../../ɵmessaging.model';
import {MessageClient} from './message-client';
Expand All @@ -26,8 +26,8 @@ export class ɵMessageClient implements MessageClient {
topic,
retain: options?.retain ?? false,
headers: new Map(options?.headers),
body: message,
};
setBodyIfDefined(topicMessage, message);
return this._brokerGateway.postMessage(MessagingChannel.Topic, topicMessage);
}

Expand All @@ -42,8 +42,8 @@ export class ɵMessageClient implements MessageClient {
topic,
retain: options?.retain ?? false,
headers: new Map(headers), /* make a copy for each subscription to support multiple subscriptions */
body: request,
};
setBodyIfDefined(topicMessage, request);
return this._brokerGateway.requestReply$(MessagingChannel.Topic, topicMessage).pipe(throwOnErrorStatus());
});
}
Expand Down Expand Up @@ -78,9 +78,3 @@ export class ɵMessageClient implements MessageClient {
});
}
}

function setBodyIfDefined<T>(message: TopicMessage<T> | IntentMessage<T>, body?: T): void {
if (body !== undefined) {
message.body = body;
}
}

0 comments on commit f3890f0

Please sign in to comment.