Get started with when CDN

MIT licensed

Import and call library functions after page load in JS projects.

Tags:
  • Promises/A+
  • promises-aplus
  • promise
  • promises
  • deferred
  • deferreds
  • when
  • async
  • asynchronous
  • cujo
  • ender

Stable version

Copied!

How to start using when CDN


<!DOCTYPE html>
<html>
<head>
  <title>Get started with when CDN - cdnhub.io</title>
  <script src="https://cdn.cdnhub.io/when/3.7.8/when.min.js"></script>
</head>
<body>
  <button id="myButton">Click me</button>
  <script>
    const myButton = document.getElementById('myButton');

    when(
      () => myButton.disabled, // condition
      () => console.log('Button is disabled'),
      () => console.log('Button is enabled')
    ).then(function() {
      myButton.addEventListener('click', function() {
        myButton.disabled = true;
        when(
          () => !myButton.disabled, // new condition
          () => console.log('Button is enabled and was clicked'),
          () => console.log('Button is still disabled')
        ).then(function() {
          myButton.disabled = false;
        });
      });
    });
  </script>
</body>
</html>
Copied!
Copied!
Copied!

All versions