Skip to Content
Phoenix Web Development
book

Phoenix Web Development

by Brandon Richey
April 2018
Beginner to intermediate content levelBeginner to intermediate
406 pages
9h 33m
English
Packt Publishing
Content preview from Phoenix Web Development

Changing our dummy code to push to the server

The dummy code is there, but it's not doing anything other than validating that we've done something good to start. Let's expand on that more by pushing a socket message up to the server. We'll start off by writing a function that is responsible for actually pushing the vote back up to the server. Place this function preceding to your onJoin function for now:

// Push the vote up to the serverconst pushVote = (el, channel) => {  channel    .push('vote', { option_id: el.getAttribute('data-option-id') })    .receive('ok', res => console.log('You Voted!'))    .receive('error', res => console.log('Failed to vote:', res));};

We want to grab the current option ID for the button clicked and use that as part of ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Phoenix in Action

Phoenix in Action

Geoffrey Lessel
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781787284197Supplemental Content