Skip to content

Commit

Permalink
Fix bug of "move ding" audio playing every time the clock ticked
Browse files Browse the repository at this point in the history
  • Loading branch information
mreishus committed Jan 8, 2020
1 parent d733936 commit 844ccb6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 8 additions & 2 deletions apps/demon_spirit_web/assets/js/hooks/update_ding.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
let move_audio = new Audio();
move_audio.src = '/sounds/move.mp3';
move_audio.src = "/sounds/move.mp3";

let moves = 0;

let UpdateDing = {
updated() {
move_audio.play();
let new_moves = this.el.getAttribute("data-moves");
if (new_moves != moves) {
moves = new_moves;
move_audio.play();
}
}
};
export default UpdateDing;
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ td .content {
<%= render "show/ready.html", state: @state, socket: @socket, guest: @guest %>
<% end %>

<div phx-hook="UpdateDing" class="hidden">
<div phx-hook="UpdateDing" class="hidden" data-moves=<%= @state.game.moves %>>
<%= @state.game.moves %>
</div>

Expand All @@ -103,9 +103,9 @@ td .content {

<%# Left - Chat %>
<div class="h-64 md:h-96 xl:h-112 mr-2 md:mr-4">
<%= live_render(@socket, DemonSpiritWeb.LiveChatIndex,
session: %{chat_name: @game_name, guest: @guest},
id: @game_name,
<%= live_render(@socket, DemonSpiritWeb.LiveChatIndex,
session: %{chat_name: @game_name, guest: @guest},
id: @game_name,
container: {:div, class: "h-full"}
) %>
</div>
Expand Down

1 comment on commit 844ccb6

@mreishus
Copy link
Owner Author

Choose a reason for hiding this comment

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

This must have changed after one of the live view releases.

<div phx-hook="UpdateDing" class="hidden">
  <%= @state.game.moves %>
</div>

This block gets redrawn every time the clock changes, however its contents do not change since no moves have been made.

It used to be that the update hook would only fire if the dom contents changed; now the update hook fires even when the contents do not change.

Please sign in to comment.