index.min.js 9.4 KB

12345678910111213141516
  1. !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@lumino/coreutils"),require("@lumino/signaling")):"function"==typeof define&&define.amd?define(["exports","@lumino/coreutils","@lumino/signaling"],t):t((e=e||self).lumino_polling={},e.lumino_coreutils,e.lumino_signaling)}(this,(function(e,t,n){"use strict";
  2. /*! *****************************************************************************
  3. Copyright (c) Microsoft Corporation. All rights reserved.
  4. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  5. this file except in compliance with the License. You may obtain a copy of the
  6. License at http://www.apache.org/licenses/LICENSE-2.0
  7. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  8. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  9. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  10. MERCHANTABLITY OR NON-INFRINGEMENT.
  11. See the Apache Version 2.0 License for specific language governing permissions
  12. and limitations under the License.
  13. ***************************************************************************** */var i=function(e,t){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function o(e,t){function n(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var r=function(){return(r=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function s(e,t,n,i){return new(n||(n=Promise))((function(o,r){function s(e){try{l(i.next(e))}catch(e){r(e)}}function a(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){e.done?o(e.value):new n((function(t){t(e.value)})).then(s,a)}l((i=i.apply(e,t||[])).next())}))}function a(e,t){var n,i,o,r,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function a(r){return function(a){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(o=2&r[0]?i.return:r[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,r[1])).done)return o;switch(i=0,o&&(r=[2&r[0],o.value]),r[0]){case 0:case 1:o=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,i=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(o=(o=s.trys).length>0&&o[o.length-1])&&(6===r[0]||2===r[0])){s=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]<o[3])){s.label=r[1];break}if(6===r[0]&&s.label<o[1]){s.label=o[1],o=r;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(r);break}o[2]&&s.ops.pop(),s.trys.pop();continue}r=t.call(e,s)}catch(e){r=[6,e],i=0}finally{n=o=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,a])}}}var l,u,c="function"==typeof requestAnimationFrame?requestAnimationFrame:setImmediate,p="function"==typeof cancelAnimationFrame?cancelAnimationFrame:clearImmediate;e.Poll=function(){function e(e){var i=this;this._disposed=new n.Signal(this),this._tick=new t.PromiseDelegate,this._ticked=new n.Signal(this),this._timeout=-1,this._factory=e.factory,this._standby=e.standby||u.DEFAULT_STANDBY,this._state=r(r({},u.DEFAULT_STATE),{timestamp:(new Date).getTime()});var o=e.frequency||{},s=Math.max(o.interval||0,o.max||0,u.DEFAULT_FREQUENCY.max);this.frequency=r(r(r({},u.DEFAULT_FREQUENCY),o),{max:s}),this.name=e.name||u.DEFAULT_NAME,"auto"in e&&!e.auto||c((function(){i.start()}))}return Object.defineProperty(e.prototype,"disposed",{get:function(){return this._disposed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"frequency",{get:function(){return this._frequency},set:function(n){if(!this.isDisposed&&!t.JSONExt.deepEqual(n,this.frequency||{})){var i=n.backoff,o=n.interval,r=n.max;if(o=Math.round(o),r=Math.round(r),"number"==typeof i&&i<1)throw new Error("Poll backoff growth factor must be at least 1");if((o<0||o>r)&&o!==e.NEVER)throw new Error("Poll interval must be between 0 and max");if(r>e.MAX_INTERVAL&&r!==e.NEVER)throw new Error("Max interval must be less than "+e.MAX_INTERVAL);this._frequency={backoff:i,interval:o,max:r}}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isDisposed",{get:function(){return"disposed"===this.state.phase},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"standby",{get:function(){return this._standby},set:function(e){this.isDisposed||this.standby===e||(this._standby=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"state",{get:function(){return this._state},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"tick",{get:function(){return this._tick.promise},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"ticked",{get:function(){return this._ticked},enumerable:!0,configurable:!0}),e.prototype.dispose=function(){this.isDisposed||(this._state=r(r({},u.DISPOSED_STATE),{timestamp:(new Date).getTime()}),this._tick.promise.catch((function(e){})),this._tick.reject(new Error("Poll ("+this.name+") is disposed.")),this._disposed.emit(void 0),n.Signal.clearData(this))},e.prototype.refresh=function(){return this.schedule({cancel:function(e){return"refreshed"===e.phase},interval:e.IMMEDIATE,phase:"refreshed"})},e.prototype.schedule=function(n){return void 0===n&&(n={}),s(this,void 0,void 0,(function(){var i,o,s,l,u,h=this;return a(this,(function(a){switch(a.label){case 0:return this.isDisposed?[2]:n.cancel&&n.cancel(this.state)?[2]:(i=this.state,o=this._tick,s=new t.PromiseDelegate,l=r({interval:this.frequency.interval,payload:null,phase:"standby",timestamp:(new Date).getTime()},n),this._state=l,this._tick=s,i.interval===e.IMMEDIATE?p(this._timeout):clearTimeout(this._timeout),this._ticked.emit(this.state),o.resolve(this),[4,o.promise]);case 1:return a.sent(),u=function(){h.isDisposed||h.tick!==s.promise||h._execute()},this._timeout=l.interval===e.IMMEDIATE?c(u):l.interval===e.NEVER?-1:setTimeout(u,l.interval),[2]}}))}))},e.prototype.start=function(){return this.schedule({cancel:function(e){var t=e.phase;return"constructed"!==t&&"standby"!==t&&"stopped"!==t},interval:e.IMMEDIATE,phase:"started"})},e.prototype.stop=function(){return this.schedule({cancel:function(e){return"stopped"===e.phase},interval:e.NEVER,phase:"stopped"})},e.prototype._execute=function(){var e=this,t="function"==typeof this.standby?this.standby():this.standby;if(t="never"!==t&&("when-hidden"===t?!("undefined"==typeof document||!document||!document.hidden):t))this.schedule();else{var n=this.tick;this._factory(this.state).then((function(t){e.isDisposed||e.tick!==n||e.schedule({payload:t,phase:"rejected"===e.state.phase?"reconnected":"resolved"})})).catch((function(t){e.isDisposed||e.tick!==n||e.schedule({interval:u.sleep(e.frequency,e.state),payload:t,phase:"rejected"})}))}},e}(),(l=e.Poll||(e.Poll={})).IMMEDIATE=0,l.MAX_INTERVAL=2147483647,l.NEVER=1/0,function(t){t.DEFAULT_BACKOFF=3,t.DEFAULT_FREQUENCY={backoff:!0,interval:1e3,max:3e4},t.DEFAULT_NAME="unknown",t.DEFAULT_STANDBY="when-hidden",t.DEFAULT_STATE={interval:e.Poll.NEVER,payload:null,phase:"constructed",timestamp:new Date(0).getTime()},t.DISPOSED_STATE={interval:e.Poll.NEVER,payload:null,phase:"disposed",timestamp:new Date(0).getTime()},t.sleep=function(n,i){var o=n.backoff,r=n.interval,s=n.max;if(r===e.Poll.NEVER)return r;var a=!0===o?t.DEFAULT_BACKOFF:!1===o?1:o,l=function(e,t){return e=Math.ceil(e),t=Math.floor(t),Math.floor(Math.random()*(t-e+1))+e}(r,i.interval*a);return Math.min(s,l)}}(u||(u={}));var h=function(){function n(n,i){var o=this;void 0===i&&(i=500),this.payload=null,this.limit=i,this.poll=new e.Poll({auto:!1,factory:function(){return s(o,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,n()];case 1:return[2,e.sent()]}}))}))},frequency:{backoff:!1,interval:e.Poll.NEVER,max:e.Poll.NEVER},standby:"never"}),this.payload=new t.PromiseDelegate,this.poll.ticked.connect((function(e,n){var i=o.payload;return"resolved"===n.phase?(o.payload=new t.PromiseDelegate,void i.resolve(n.payload)):"rejected"===n.phase||"stopped"===n.phase?(o.payload=new t.PromiseDelegate,i.promise.catch((function(e){})),void i.reject(n.payload)):void 0}),this)}return Object.defineProperty(n.prototype,"isDisposed",{get:function(){return null===this.payload},enumerable:!0,configurable:!0}),n.prototype.dispose=function(){this.isDisposed||(this.payload=null,this.poll.dispose())},n.prototype.stop=function(){return s(this,void 0,void 0,(function(){return a(this,(function(e){return[2,this.poll.stop()]}))}))},n}(),f=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t.prototype.invoke=function(){return this.poll.schedule({interval:this.limit,phase:"invoked"}),this.payload.promise},t}(h);e.Throttler=function(t){function n(n,i){var o=t.call(this,n,"number"==typeof i?i:i&&i.limit)||this,r="leading";return"number"!=typeof i&&(r="edge"in(i=i||{})?i.edge:r),o._interval="trailing"===r?o.limit:e.Poll.IMMEDIATE,o}return o(n,t),n.prototype.invoke=function(){return"invoked"!==this.poll.state.phase&&this.poll.schedule({interval:this._interval,phase:"invoked"}),this.payload.promise},n}(h),e.Throttler||(e.Throttler={}),e.Debouncer=f,e.RateLimiter=h,Object.defineProperty(e,"__esModule",{value:!0})}));
  14. //# sourceMappingURL=index.min.js.map