assets: track
This commit is contained in:
		@ -255,7 +255,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _for
 | 
			
		||||
  \*********************/
 | 
			
		||||
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
 | 
			
		||||
 | 
			
		||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */   \"default\": function() { return /* binding */ Live; }\n/* harmony export */ });\n/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils */ \"./src/utils.js\");\n/* harmony import */ var _model__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./model */ \"./src/model.js\");\n\n\nclass Live {\n  constructor({\n    url,\n    timeout = 10,\n    src = \"\"\n  } = {}) {\n    this.url = url;\n    this.timeout = timeout;\n    this.src = src;\n    this.interval = null;\n    this.promise = null;\n    this.items = [];\n    this.current = null;\n  } //-- data refreshing\n\n\n  drop() {\n    this.promise = null;\n  }\n  /**\n   * Fetch data from server.\n   *\n   * @param {Object} options\n   * @param {Function} options.then: call this method on fetch, `this` passed as argument.\n   * @return {Promise} Promise resolving to fetched items.\n   */\n\n\n  fetch({\n    then = null\n  } = {}) {\n    const promise = fetch(this.url).then(response => response.ok ? response.json() : Promise.reject(response)).then(data => {\n      data.forEach(item => {\n        if (item.start) item.start = new Date(item.start);\n        if (item.end) item.end = new Date(item.end);\n      });\n      this.items = data;\n      const now = new Date();\n      let item = data.find(it => it.start && it.start <= now < it.end) || data.length ? data[data.length - 1] : null;\n\n      if (item) {\n        item.src = this.src;\n        this.current = new _model__WEBPACK_IMPORTED_MODULE_1__[\"default\"](item);\n      } else this.current = null;\n\n      if (then) then(this);\n      return this.items;\n    });\n    this.promise = promise;\n    return promise;\n  }\n\n  _refresh(options = {}) {\n    const promise = this.fetch(options);\n    promise.then(() => {\n      if (promise != this.promise) return [];\n    });\n    return promise;\n  }\n  /**\n   * Refresh live info every `this.timeout`.\n   * @param {Object} options: arguments passed to `this.fetch`.\n   */\n\n\n  refresh(options = {}) {\n    if (this.interval !== null) return;\n\n    this._refresh(options);\n\n    this.interval = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.setEcoInterval)(() => this._refresh(options), this.timeout * 1000);\n    return this.interval;\n  }\n\n  stopRefresh() {\n    this.interval !== null && clearInterval(this.interval);\n  }\n\n}\n\n//# sourceURL=webpack://aircox-assets/./src/live.js?");
 | 
			
		||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */   \"default\": function() { return /* binding */ Live; }\n/* harmony export */ });\n/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils */ \"./src/utils.js\");\n/* harmony import */ var _model__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./model */ \"./src/model.js\");\n\n\nclass Live {\n  constructor({\n    url,\n    timeout = 10,\n    src = \"\"\n  } = {}) {\n    this.url = url;\n    this.timeout = timeout;\n    this.src = src;\n    this.interval = null;\n    this.promise = null;\n    this.items = [];\n    this.current = null;\n  } //-- data refreshing\n\n\n  drop() {\n    this.promise = null;\n  }\n  /**\n   * Fetch data from server.\n   *\n   * @param {Object} options\n   * @param {Function} options.then: call this method on fetch, `this` passed as argument.\n   * @return {Promise} Promise resolving to fetched items.\n   */\n\n\n  fetch({\n    then = null\n  } = {}) {\n    const promise = fetch(this.url).then(response => response.ok ? response.json() : Promise.reject(response)).then(data => {\n      data.forEach(item => {\n        if (item.start) item.start = new Date(item.start);\n        if (item.end) item.end = new Date(item.end);\n      });\n      this.items = data;\n      const now = new Date();\n      let item = data.find(it => it.start && it.start <= now < it.end) || data.length ? data[0] : null;\n\n      if (item) {\n        item.src = this.src;\n        this.current = new _model__WEBPACK_IMPORTED_MODULE_1__[\"default\"](item);\n      } else this.current = null;\n\n      if (then) then(this);\n      return this.items;\n    });\n    this.promise = promise;\n    return promise;\n  }\n\n  _refresh(options = {}) {\n    const promise = this.fetch(options);\n    promise.then(() => {\n      if (promise != this.promise) return [];\n    });\n    return promise;\n  }\n  /**\n   * Refresh live info every `this.timeout`.\n   * @param {Object} options: arguments passed to `this.fetch`.\n   */\n\n\n  refresh(options = {}) {\n    if (this.interval !== null) return;\n\n    this._refresh(options);\n\n    this.interval = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.setEcoInterval)(() => this._refresh(options), this.timeout * 1000);\n    return this.interval;\n  }\n\n  stopRefresh() {\n    this.interval !== null && clearInterval(this.interval);\n  }\n\n}\n\n//# sourceURL=webpack://aircox-assets/./src/live.js?");
 | 
			
		||||
 | 
			
		||||
/***/ }),
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user