Skip to content

Instantly share code, notes, and snippets.

@andersonleite
Last active January 4, 2017 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andersonleite/59adde044c57812a9886631e914d0b4e to your computer and use it in GitHub Desktop.
Save andersonleite/59adde044c57812a9886631e914d0b4e to your computer and use it in GitHub Desktop.
function renderSuggestion(suggestedBeer, selector) {
var suggestionEl = document.querySelector(selector);
if (suggestedBeer === null) {
suggestionEl.style.visibility = 'hidden';
} else {
suggestionEl.style.visibility = 'visible';
var usernameEl = suggestionEl.querySelector('.username');
usernameEl.textContent = suggestedBeer.name;
var imgEl = suggestionEl.querySelector('img');
imgEl.src = suggestedBeer.image_url;
var descriptionEl = suggestionEl.querySelector('.description');
descriptionEl.textContent = suggestedBeer.description;
}
}
suggestion1Stream.subscribe(function (suggestedBeer) {
renderSuggestion(suggestedBeer, '.suggestion1');
});
suggestion2Stream.subscribe(function (suggestedBeer) {
renderSuggestion(suggestedBeer, '.suggestion2');
});
suggestion3Stream.subscribe(function (suggestedBeer) {
renderSuggestion(suggestedBeer, '.suggestion3');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment