sebbo2002 / node-pyatv

A lightweight node.js wrapper around pyatv…
MIT License
27 stars 1 forks source link

fix(core): fix insufficient comparison in applyStateAndEmitEvents #299

Closed maxileith closed 8 months ago

maxileith commented 8 months ago

About this Pull Request

Pull Request Checklist

sebbo2002 commented 8 months ago

I also thought about it, but I assumed that atvscript only generates the event if there is a change. This is not necessarily the case with the default state with many fields, as it contains a large number of fields, thus the comparison. Therefore, when considering "additional dependency for deep-compare" / "hacky compare with toJSON" / "no compare", I opted for the latter, as the functionality is retained in the end. Do I see this wrong?

maxileith commented 8 months ago

I am not 100% sure wether or not the atvscript reports a change of output_devices only if there is a true change. Tbh, I would not rely on that ...

"hacky compare with toJSON"

I wouldn't consider this an option, since there is always the possibility of the object attributes beeing out of order and then there would be false positives as well.

maxileith commented 8 months ago

Would you consider it beeing it a vaiable option if I write a custom deepEqual? This way you would not have an additional dependency.

Edit: I just started doing that. Turns out not to be trivial ... haha

sebbo2002 commented 8 months ago

Would you consider it beeing it a vaiable option if I write a custom deepEqual? This way you would not have an additional dependency.

Edit: I just started doing that. Turns out not to be trivial ... haha

Haha. But is that even necessary? As I said, I assume that the events are only thrown by atvscript if there is a given change.

Edit: Just saw your first comment. To be honest, I would rely on that as long as the opposite is shown. That can then be implemented without requiring a Breaking Change...

maxileith commented 8 months ago

@sebbo2002 up to you. It is probably sufficient. However, I somehow find it very unpleasing to compare arrays flat. I have implemented the deepEqual method. Up-to-you wether you wanna merge it or not. It was a fun problem to solve anyhow.

sebbo2002 commented 8 months ago

@sebbo2002 up to you. It is probably sufficient. However, I somehow find it very unpleasing to compare arrays flat. I have implemented the deepEqual method. Up-to-you wether you wanna merge it or not. It was a fun problem to solve anyhow.

Yes, you're right. It's very dirty, even if it works. All right, let's agree on a compromise. Because to be honest, a full-fledged deepEqual implementation seems a bit too much of a good thing to me. What do you think of this solution? https://github.com/sebbo2002/node-pyatv/pull/300

maxileith commented 8 months ago

@sebbo2002 I think this is a good middle ground 👍

sebbo2002 commented 8 months ago

Nice. I close this PR then. I merged the other one then. Thank you.