{"size": 576, "ext": "js", "max_stars_repo_path": "_grow/source/js/deployment/observer.js", "max_stars_repo_name": "Kukurijek/fastlane.tools", "max_stars_repo_stars_event_min_datetime": "2015-05-27T14:48:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-25T08:54:49.000Z", "max_issues_repo_path": "_grow/source/js/deployment/observer.js", "max_issues_repo_name": "Kukurijek/fastlane.tools", "max_issues_repo_issues_event_min_datetime": "2015-05-14T19:17:54.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-12T11:46:53.000Z", "max_forks_repo_path": "_grow/source/js/deployment/observer.js", "max_forks_repo_name": "Kukurijek/fastlane.tools", "max_forks_repo_forks_event_min_datetime": "2015-05-11T14:02:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T06:40:09.000Z"}
{"max_stars_count": 18, "max_issues_count": 46, "max_forks_count": 26, "avg_line_length": 22.1538461538, "max_line_length": 65, "alphanum_fraction": 0.6527777778}
/**
 * @param {string} selector DOM selector to watch
 * @param {Function} callback Callback when intersection happens.
 */
export function Observer(selector, callback) {
  this.target = document.querySelector(selector);
  this.io = new IntersectionObserver(e => {
    if (e.find(i => i.isIntersecting)) {
      callback();
      this.stop();
    }
  });

  this.io.observe(this.target);
}

/**
 * Stops observing.
 */
Observer.prototype.stop = function() {
  if (!this.target) {
    return console.warn("I'm not watching anything.");
  }
  this.io.unobserve(this.target);
};
