@cantonjs/react-scroll-view
Version:
react scroll component using intersection observer API
52 lines (45 loc) • 1.6 kB
JavaScript
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"); } }
import { createId } from './util';
var MapPolyfill = function () {
function MapPolyfill() {
_classCallCheck(this, MapPolyfill);
this._store = [];
this._key = '__map' + createId();
}
_createClass(MapPolyfill, [{
key: 'has',
value: function has(obj) {
return !!~this._store.indexOf(obj);
}
}, {
key: 'set',
value: function set(obj, val) {
if (!this.has(obj)) {
obj[this._key] = val;
this._store.push(obj);
}
}
}, {
key: 'get',
value: function get(obj) {
if (this.has(obj)) return obj[this._key];
}
}, {
key: 'delete',
value: function _delete(obj) {
var index = this._store.indexOf(obj);
if (index > -1) {
delete obj[this._key];
this._store.splice(index, 1);
}
}
}, {
key: 'size',
get: function get() {
return this._store.length;
}
}]);
return MapPolyfill;
}();
export default Map || MapPolyfill;