Skip to content

Commit ad11302

Browse files
committed
Minor refactoring, created a 'isNotAnEmptyObject' function
1 parent 61dff68 commit ad11302

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/connection/Connection.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ export class Connection implements IConnection {
111111
else valueToSend = value;
112112
});
113113

114-
// If the message is an object, and it's empty, it makes no sense to send it
115-
// All other messages (e.g. non-empty objects or primitives) must be sent
116-
if (!(typeof valueToSend === 'object' && Object.keys(valueToSend).length == 0)) {
114+
// Checking if valueToSend is NOT {}
115+
if (Utils.isNotAnEmptyObject(valueToSend)) {
117116
messages.push({ topic, propertyName: current, value: valueToSend });
118117
}
119118

src/utils/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ function isArray<T>(value: CloudMessageValue): value is T[] {
3131
return Array.isArray(value);
3232
}
3333

34+
function isNotAnEmptyObject(value): boolean {
35+
return !(typeof value === 'object' && Object.keys(value).length == 0);
36+
}
37+
3438
function toArrayBuffer(buf: { length: number }): ArrayBuffer {
3539
const ab = new ArrayBuffer(buf.length);
3640
const view = new Uint8Array(ab);
@@ -69,4 +73,5 @@ export default {
6973
toArrayBuffer,
7074
toBuffer,
7175
arrayBufferToBase64,
76+
isNotAnEmptyObject,
7277
};

0 commit comments

Comments
 (0)