@cantonjs/react-scroll-view
Version:
react scroll component using intersection observer API
70 lines (60 loc) • 2.07 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var FixedState = function () {
function FixedState() {
_classCallCheck(this, FixedState);
this.children = [];
}
_createClass(FixedState, [{
key: "bind",
value: function bind(reactInstance) {
if (!this.forceUpdate) {
this.forceUpdate = reactInstance.forceUpdate.bind(reactInstance);
}
}
}, {
key: "unbind",
value: function unbind() {
this.forceUpdate = null;
}
}, {
key: "_findIndexByKey",
value: function _findIndexByKey(key) {
var children = this.children;
var length = children.length;
var index = -1;
for (var i = 0; i < length; i++) {
var curr = children[i];
if (curr && curr.key === key) {
index = i;
break;
}
}
return index;
}
}, {
key: "unmount",
value: function unmount(key) {
var index = this._findIndexByKey(key);
if (index > -1) {
this.children.splice(index, 1);
this.forceUpdate && this.forceUpdate();
}
}
}, {
key: "render",
value: function render(child) {
var children = this.children;
var key = child.key;
var index = this._findIndexByKey(key);
if (index > -1) children.splice(index, 1, child);else children.push(child);
this.forceUpdate && this.forceUpdate();
}
}]);
return FixedState;
}();
exports.default = FixedState;
;