"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.IntersectionObserverState = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _mobx = require("mobx");
class IntersectionObserverState {
  constructor() {
    (0, _defineProperty2.default)(this, "intersectionRatio", 1);
    (0, _defineProperty2.default)(this, "observer", void 0);
    (0, _defineProperty2.default)(this, "dispose", () => {
      var _this$observer;
      (_this$observer = this.observer) == null || _this$observer.disconnect();
    });
    (0, _mobx.makeObservable)(this, {
      intersectionRatio: _mobx.observable.ref
    });
  }
  init({
    root,
    target,
    rootMargin
  }) {
    if (target == null || typeof IntersectionObserver === 'undefined') {
      return;
    }
    const observer = new IntersectionObserver((0, _mobx.action)(([{
      intersectionRatio
    }]) => {
      this.intersectionRatio = intersectionRatio;
    }), {
      root,
      rootMargin
    });
    observer.observe(target);
    this.observer = observer;
    return this.dispose;
  }
}
exports.IntersectionObserverState = IntersectionObserverState;
//# sourceMappingURL=IntersectionObserverState.js.map