bendc / animateplus

A+ animation module for the modern web
MIT License
5.96k stars 280 forks source link

Returning a Promise #19

Closed JSteunou closed 6 years ago

JSteunou commented 8 years ago

Hi,

first thank you first this jewel, really a saviour!

Could you consider returning a Promise from animate call?

Would solve https://github.com/bendc/animateplus/issues/6 and allow use of future async / await out of the box.

ghost commented 7 years ago

Agreed. The amount of spaghetti code I wrote trying to do a simple headline rotation sequence has lead me to giving animo a shot instead (it returns a promise, but uses a different approach).

msheakoski commented 7 years ago

What about using a simple wrapper?

function pranimate(params) {
  return new Promise(function (resolve, reject) {
    params.complete = resolve;
    animate(params);
  });
}
<h1>Hello</h1>
<script> 
  document.addEventListener("DOMContentLoaded", function(event) {    
    pranimate({
      el: "h1",
      translateX: [0, 200],
      duration: 1000
    }).then(function () {
      return pranimate({
        el: "h1",
    translateX: [200, 200],
        translateY: [0, 200],
        duration: 1000
      });
    }).then(function () {
      return pranimate({
        el: "h1",
    translateX: [200, 0],
        translateY: [200, 200],
        duration: 1000
      });
    }).then(function () {
      return pranimate({
        el: "h1",
        translateY: [200, 0],
        duration: 1000
      });
    });
  });
</script>
bendc commented 6 years ago

Fixed in v2.0.0