Created
February 16, 2017 03:57
-
-
Save lubien/fba2066d82c6aa1234e4bf17815dbed4 to your computer and use it in GitHub Desktop.
Promise races v1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const $page = document.getElementById('page') | |
const setPage = title => { | |
$page.innerText = title | |
} | |
const loadPage = (title, time) => | |
new Promise(resolve => | |
setTimeout(() => resolve(title), time) | |
) | |
const onClickChangePage = button => | |
button.addEventListener('click', () => { | |
const nextPage = button.getAttribute('data-page') | |
const delay = +button.getAttribute('data-delay') | |
loadPage(nextPage, delay) | |
.then(setPage) | |
}) | |
Array.from(document.getElementsByTagName('button')) | |
.map(onClickChangePage) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment