Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement Message#equals #1906

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/message.js
Expand Up @@ -116,6 +116,18 @@ Message.fromObject = function fromObject(object) {
return this.$type.fromObject(object);
};

/**
* Returns whether one Message's fields have values equal to those of another Message
* @param {T} b Message instance
* @returns {Boolean}
* @template T extends Message<T>
* @this Constructor<T>
*/
Message.prototype.equals = function equals(b) {
return this.$type == b.$type &&
this.$type.fieldsArray.every(f => this[f.name] == b[f.name]);
};

/**
* Creates a plain object from a message of this type. Also converts values to other types if specified.
* @param {T} message Message instance
Expand All @@ -136,4 +148,4 @@ Message.prototype.toJSON = function toJSON() {
return this.$type.toObject(this, util.toJSONOptions);
};

/*eslint-enable valid-jsdoc*/
/*eslint-enable valid-jsdoc*/