'use strict';

/**
 * 当给定的一组图片全部加载完成
 * @param {Array<string>} imgUrls
 */
function onImagesLoad(imgUrls) {
  var imgs = [];
  return new Promise(function (resolve) {
    var _loop = function _loop(i) {
      var img = new Image();
      img.src = imgUrls[i];

      img.onload = function () {
        imgs.push(img);

        if (imgs.length === imgUrls.length) {
          resolve(imgs);
        }
      };
    };

    for (var i = 0; i < imgUrls.length; i++) {
      _loop(i);
    }
  });
}

module.exports = onImagesLoad;
