asva-executors
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -152,3 +152,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
"use strict"; | ||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _Executors_Executor__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../Executors/Executor */ \"./src/modules/Executors/Executor.ts\");\nvar __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n};\r\nvar __generator = (undefined && undefined.__generator) || function (thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [0, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n};\r\n\r\nvar InfiniteLoader = /** @class */ (function () {\r\n function InfiniteLoader(run, perStep) {\r\n if (perStep === void 0) { perStep = 20; }\r\n this.items = [];\r\n this.perStep = 20; // number of items to load\r\n this.pointer = 0;\r\n this.isFinished = false;\r\n this.isFresh = true;\r\n this.executor = new _Executors_Executor__WEBPACK_IMPORTED_MODULE_0__[\"default\"](run);\r\n this.perStep = perStep;\r\n }\r\n Object.defineProperty(InfiniteLoader.prototype, \"isRunning\", {\r\n /**\r\n * Command from this executor is currently running.\r\n */\r\n get: function () {\r\n return this.executor.isRunning;\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n Object.defineProperty(InfiniteLoader.prototype, \"isEmpty\", {\r\n /**\r\n * We tried to load, but list is empty\r\n */\r\n get: function () {\r\n if (this.executor.isRunning) {\r\n return false;\r\n }\r\n return this.isFinished && (this.items.length === 0);\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n Object.defineProperty(InfiniteLoader.prototype, \"isFull\", {\r\n /**\r\n * We tried to load, and list is not empty\r\n */\r\n get: function () {\r\n return !!this.items.length;\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n Object.defineProperty(InfiniteLoader.prototype, \"isRefreshing\", {\r\n /**\r\n * Is loading anew. This could happen in two cases.\r\n * 1) Executor is running for the first time. Meaning the list is empty.\r\n * 2) Executor is refreshing. Meaning the list is not empty.\r\n */\r\n get: function () {\r\n return this.pointer === 0 && this.isRunning;\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n /**\r\n * Loads a bunch of items\r\n */\r\n InfiniteLoader.prototype.next = function () {\r\n if (this.isRunning) {\r\n return;\r\n }\r\n this.isFresh = false;\r\n this.runExecutor();\r\n };\r\n InfiniteLoader.prototype.runExecutor = function () {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var result, exception_1;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n _a.trys.push([0, 2, , 3]);\r\n return [4 /*yield*/, this.executor.run(this.pointer, this.perStep)];\r\n case 1:\r\n result = _a.sent();\r\n if (!Array.isArray(result)) {\r\n console.warn('InfiniteLoader function must return array');\r\n return [2 /*return*/];\r\n }\r\n if (result.length < this.perStep) {\r\n this.isFinished = true;\r\n }\r\n this.pointer = this.pointer + this.perStep;\r\n this.applyNew(result);\r\n return [3 /*break*/, 3];\r\n case 2:\r\n exception_1 = _a.sent();\r\n this.isFinished = true;\r\n throw exception_1;\r\n case 3: return [2 /*return*/];\r\n }\r\n });\r\n });\r\n };\r\n /**\r\n * Refresh the list.\r\n * This will replace current items with new ones after loading. Not clear the list immediately.\r\n */\r\n InfiniteLoader.prototype.refresh = function () {\r\n this.pointer = 0;\r\n this.isFresh = true;\r\n this.isFinished = false;\r\n this.runExecutor();\r\n };\r\n InfiniteLoader.prototype.applyNew = function (items) {\r\n if (this.isFresh) {\r\n this.items = items;\r\n return;\r\n }\r\n this.items = this.items.concat(items);\r\n };\r\n return InfiniteLoader;\r\n}());\r\n/* harmony default export */ __webpack_exports__[\"default\"] = (InfiniteLoader);\r\n\n\n//# sourceURL=webpack:///./src/modules/Loaders/InfiniteLoader.ts?"); | ||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _Executors_LadderExecutor__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../Executors/LadderExecutor */ \"./src/modules/Executors/LadderExecutor.ts\");\nvar __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n};\r\nvar __generator = (undefined && undefined.__generator) || function (thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [0, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n};\r\n\r\nvar InfiniteLoader = /** @class */ (function () {\r\n function InfiniteLoader(run, perStep) {\r\n if (perStep === void 0) { perStep = 20; }\r\n this.items = [];\r\n this.perStep = 20; // number of items to load\r\n this.pointer = 0;\r\n this.isFinished = false;\r\n this.isFresh = true;\r\n this.executor = new _Executors_LadderExecutor__WEBPACK_IMPORTED_MODULE_0__[\"default\"](run);\r\n this.perStep = perStep;\r\n }\r\n Object.defineProperty(InfiniteLoader.prototype, \"isRunning\", {\r\n /**\r\n * Command from this executor is currently running.\r\n */\r\n get: function () {\r\n return this.executor.isRunning;\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n Object.defineProperty(InfiniteLoader.prototype, \"isEmpty\", {\r\n /**\r\n * We tried to load, but list is empty\r\n */\r\n get: function () {\r\n if (this.executor.isRunning) {\r\n return false;\r\n }\r\n return this.isFinished && (this.items.length === 0);\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n Object.defineProperty(InfiniteLoader.prototype, \"isFull\", {\r\n /**\r\n * We tried to load, and list is not empty\r\n */\r\n get: function () {\r\n return !!this.items.length;\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n Object.defineProperty(InfiniteLoader.prototype, \"isRefreshing\", {\r\n /**\r\n * Is loading anew. This could happen in two cases.\r\n * 1) Executor is running for the first time. Meaning the list is empty.\r\n * 2) Executor is refreshing. Meaning the list is not empty.\r\n */\r\n get: function () {\r\n return this.pointer === 0 && this.isRunning;\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n /**\r\n * Loads a bunch of items\r\n */\r\n InfiniteLoader.prototype.next = function () {\r\n if (this.isRunning) {\r\n return;\r\n }\r\n this.isFresh = false;\r\n this.runExecutor();\r\n };\r\n InfiniteLoader.prototype.runExecutor = function () {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var result, exception_1;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n _a.trys.push([0, 2, , 3]);\r\n return [4 /*yield*/, this.executor.run(this.pointer, this.perStep)];\r\n case 1:\r\n result = _a.sent();\r\n if (!Array.isArray(result)) {\r\n console.warn('InfiniteLoader function must return array');\r\n return [2 /*return*/];\r\n }\r\n if (result.length < this.perStep) {\r\n this.isFinished = true;\r\n }\r\n this.pointer = this.pointer + this.perStep;\r\n this.applyNew(result);\r\n return [3 /*break*/, 3];\r\n case 2:\r\n exception_1 = _a.sent();\r\n this.isFinished = true;\r\n throw exception_1;\r\n case 3: return [2 /*return*/];\r\n }\r\n });\r\n });\r\n };\r\n /**\r\n * Refresh the list.\r\n * This will replace current items with new ones after loading. Not clear the list immediately.\r\n */\r\n InfiniteLoader.prototype.refresh = function () {\r\n this.pointer = 0;\r\n this.isFresh = true;\r\n this.isFinished = false;\r\n this.runExecutor();\r\n };\r\n InfiniteLoader.prototype.applyNew = function (items) {\r\n if (this.isFresh) {\r\n this.items = items;\r\n return;\r\n }\r\n this.items = this.items.concat(items);\r\n };\r\n return InfiniteLoader;\r\n}());\r\n/* harmony default export */ __webpack_exports__[\"default\"] = (InfiniteLoader);\r\n\n\n//# sourceURL=webpack:///./src/modules/Loaders/InfiniteLoader.ts?"); | ||
@@ -155,0 +155,0 @@ /***/ }), |
@@ -1,6 +0,6 @@ | ||
import Executor from '../Executors/Executor'; | ||
import LadderExecutor from '../Executors/LadderExecutor'; | ||
export declare type PointerRequest = (pointer: number, perStep: number) => Promise<any[]>; | ||
export default class InfiniteLoader { | ||
items: any[]; | ||
protected readonly executor: Executor; | ||
protected readonly executor: LadderExecutor; | ||
protected readonly perStep: number; | ||
@@ -7,0 +7,0 @@ protected pointer: number; |
@@ -0,0 +0,0 @@ |
{ | ||
"name": "asva-executors", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Helper classes for your async flow control", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
@@ -1,2 +0,2 @@ | ||
import Executor from '../Executors/Executor' | ||
import LadderExecutor from '../Executors/LadderExecutor' | ||
@@ -8,3 +8,3 @@ export type PointerRequest = (pointer: number, perStep: number) => Promise<any[]> | ||
protected readonly executor: Executor | ||
protected readonly executor: LadderExecutor | ||
protected readonly perStep: number = 20 // number of items to load | ||
@@ -16,3 +16,3 @@ protected pointer: number = 0 | ||
constructor (run: PointerRequest, perStep: number = 20) { | ||
this.executor = new Executor(run) | ||
this.executor = new LadderExecutor(run) | ||
this.perStep = perStep | ||
@@ -19,0 +19,0 @@ } |
61628