UNPKG

react-application-core

Version:

A react-based application core for the business applications.

79 lines 3.18 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PersistentScrollPlugin = void 0; var di_1 = require("../../di"); var definition_1 = require("../../definition"); var util_1 = require("../../util"); var PersistentScrollPlugin = /** @class */ (function () { /** * @stable [06.02.2020] * @param {IGenericComponent<IScrolledProps>} component */ function PersistentScrollPlugin(component) { this.component = component; this.onScroll = this.onScroll.bind(this); this.scrollTask = new util_1.DelayedTask(this.doScroll.bind(this), 200); } /** * @stable [23.10.2019] */ PersistentScrollPlugin.prototype.componentDidMount = function () { var element = this.selfRef; // Props contain x/y this.domAccessor.scrollTo(this.component.props, element); this.scrollUnsubscriber = this.domAccessor.captureEvent({ callback: this.onScroll, eventName: definition_1.EventsEnum.SCROLL, element: element, }); }; /** * @stable [24.10.2019] */ PersistentScrollPlugin.prototype.componentWillUnmount = function () { this.scrollTask.stop(); if (util_1.isFn(this.scrollUnsubscriber)) { this.scrollUnsubscriber(); this.scrollUnsubscriber = null; } }; /** * @stable [24.10.2019] */ PersistentScrollPlugin.prototype.onScroll = function () { this.scrollTask.start(); }; /** * @stable [24.10.2019] */ PersistentScrollPlugin.prototype.doScroll = function () { this.component.props.onScroll(this.domAccessor.getScrollInfo(this.selfRef)); }; Object.defineProperty(PersistentScrollPlugin.prototype, "selfRef", { /** * @stable [17.01.2020] * @returns {HTMLElement} */ get: function () { return this.component.selfRef.current; }, enumerable: false, configurable: true }); __decorate([ di_1.lazyInject(di_1.DI_TYPES.DomAccessor), __metadata("design:type", Object) ], PersistentScrollPlugin.prototype, "domAccessor", void 0); return PersistentScrollPlugin; }()); exports.PersistentScrollPlugin = PersistentScrollPlugin; //# sourceMappingURL=persistent-scroll.plugin.js.map