Closed maxileith closed 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?
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.
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
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...
@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 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
@sebbo2002 I think this is a good middle ground 👍
Nice. I close this PR then. I merged the other one then. Thank you.
About this Pull Request
outputDevices
to this library, it is required to compare state changes of the attributes with a deep comparison instead of a flat one, since[{"test": 1}] == [{"test": 1}]
isfalse
in JavaScript. Therefore a deep comparison is required in order to fix #295Pull Request Checklist
npm run lint
to double checknpm run test
to run the unit tests andnpm run coverage
to generate a coverage report