Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: parse method mutating its input #231

Merged
merged 1 commit into from
Jun 24, 2020

Conversation

matejvasek
Copy link
Contributor

fixes: #230

@matejvasek
Copy link
Contributor Author

/cc @lholmquist @lance

@@ -32,17 +32,20 @@ function parse(payload, headers, receiver) {
source: undefined
};


const unprocessed = new Set(Object.keys(incoming));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is Set necessary here. Can't we assume that the keys in the object are unique already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they should be unique. The thing is: If I understand it correctly Object.keys(incoming) returns an array and deletion from an array is more complicated than just delete() which is offered by a Set object.

@@ -32,17 +32,20 @@ function parse(payload, headers, receiver) {
source: undefined
};


const unprocessed = new Set(Object.keys(incoming));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the most efficient would be using the spread operator like this.

Suggested change
const unprocessed = new Set(Object.keys(incoming));
const unprocessed = { ...incoming };

Signed-off-by: Matej Vasek <mvasek@redhat.com>
@matejvasek
Copy link
Contributor Author

@lance I force pushed it. There is now only one line changed: const incoming = { ...parser.parse(payload) };.

Copy link
Member

@lance lance left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent - thank you!

@lance lance merged commit 060b21b into cloudevents:master Jun 24, 2020
@lance lance mentioned this pull request Jul 7, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Receiver accept() method modifies its input parameter.
3 participants