twolfson / google-music.js

Browser-side JS library for controlling Google Music
The Unlicense
47 stars 6 forks source link

Repeat/Shuffle observer firing multiple times #29

Closed chrismou closed 8 years ago

chrismou commented 8 years ago

Following on from a a discussion here, I've noticed the repeat/shuffle observer is being fired multiple times on change.

As @twolfson suggests, this could be due to multiple attributes changing - I guess this could relate to multiple instances of each button around the app, where changing one changes several others?

https://github.com/gmusic-utils/gmusic.js/blob/4.0.3/lib/main.js#L366-L386

This isn't a bug per say as the data isn't wrong, but figured it could be worth logging as a note to look into a bit further at some point for the sake of optimization.

twolfson commented 8 years ago

Yep, the deeper problem is that we are firing a "change" event when no "change" has occurred. We track last state for change:song but none of the other observers:

https://github.com/gmusic-utils/gmusic.js/blob/4.0.3/lib/main.js#L348

If we add in preserving last values to a variable and verifying that variable has changed before firing, then we should be good.