/
Batch.js
2 lines (2 loc) · 2.31 KB
/
Batch.js
1
2
(function(b,c){'object'==typeof exports&&'object'==typeof module?module.exports=c(require('prop-types'),require('react')):'function'==typeof define&&define.amd?define('Batch',['prop-types','react'],c):'object'==typeof exports?exports.Batch=c(require('prop-types'),require('react')):b.Batch=c(b['prop-types'],b.react)})(this,function(){return function(c){function d(f){if(e[f])return e[f].exports;var g=e[f]={i:f,l:!1,exports:{}};return c[f].call(g.exports,g,g.exports,d),g.l=!0,g.exports}var e={};return d.m=c,d.c=e,d.i=function(f){return f},d.d=function(f,g,h){d.o(f,g)||Object.defineProperty(f,g,{configurable:!1,enumerable:!0,get:h})},d.n=function(f){var g=f&&f.__esModule?function(){return f['default']}:function(){return f};return d.d(g,'a',g),g},d.o=function(f,g){return Object.prototype.hasOwnProperty.call(f,g)},d.p='./',d(d.s=2)}({'./src/components/Batch/index.js':function(c,d,e){'use strict';Object.defineProperty(d,'__esModule',{value:!0});var f=e(1),g=e.n(f),h=e(0),i=e.n(h);class j extends f.Component{constructor({flushCount:k,flushInterval:l,debug:m}){this.lastFlushCount=0,this.lastFlushTime=Date.now(),this.flushInterval=l,this.flushCount=k,this.debug=m}componentDidMount(){this._interval=setInterval(()=>this.checkAge(),this.flushInterval)}componentWillUnmount(){clearInterval(this._interval)}log(k,...l){this.debug&&console.log('[batch]: '+k,...l)}age(){return Date.now()-this.lastFlushTime}pending(){const{props:{count:k=0}={}}=this;return k-this.lastFlushCount}intervalExceeded(){return this.age()>=this.flushInterval}checkAge(){this.age()>=this.flushInterval&&0!=this.pending()&&(this.log('flush forced interval'),this.forceUpdate())}shouldComponentUpdate({count:k}){const l=k-this.lastFlushCount;return l>=this.flushCount?(this.log('flush count (age %dms)',this.age()),!0):!!(this.age()>=this.flushInterval)&&(this.log('flush interval (count %d)',l),!0)}render(){const{render:k,count:l}=this.props;return this.lastFlushCount=l,this.lastFlushTime=Date.now(),k()}}d['default']=j,j.propTypes={count:h.number.isRequired,flushCount:h.number.isRequired,flushInterval:h.number.isRequired,render:h.func.isRequired,debug:bool},j.defaultProps={debug:!1}},0:function(c){c.exports=require('prop-types')},1:function(c){c.exports=require('react')},2:function(c,d,e){c.exports=e('./src/components/Batch/index.js')}})});
//# sourceMappingURL=Batch.js.map