UNPKG

xcloudsdk

Version:

xcloud sdk

67 lines (66 loc) 2.48 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SyncEachObj = exports.SyncEach = void 0; let SyncEachWarpe = function (tempList, dataFun) { return __awaiter(this, void 0, void 0, function* () { var obj = tempList.shift(); var continueFun = true; if (obj) { continueFun = yield dataFun(obj); } if (continueFun && tempList.length > 0) { return SyncEachWarpe(tempList, dataFun); } }); }; /** * 异步遍历集合 * @param list 遍历的对象 * @param dataFun 数据处理函数,返回true 继续循环,返回false 停止循环 */ const SyncEach = function (list, dataFun) { return __awaiter(this, void 0, void 0, function* () { if (!list || list.length < 1) { return; } var tempList = list.slice(0); return SyncEachWarpe(tempList, dataFun); }); }; exports.SyncEach = SyncEach; /** * 异步遍历对象 * @param obj 遍历的对象 * @param dataFun 数据处理函数,返回true 继续循环,返回false 停止循环 * @param keyNames 要遍历的Keys [可选] */ const SyncEachObj = function (obj, dataFun, keyNames) { return __awaiter(this, void 0, void 0, function* () { var propNames = []; if (keyNames == undefined) { propNames = Object.getOwnPropertyNames(obj); } else { propNames = keyNames; } var continueFun = true; var key = propNames.shift(); if (key) { var list = obj[key]; continueFun = yield dataFun(list, key); } if (continueFun && propNames.length > 0) { return (0, exports.SyncEachObj)(obj, dataFun, propNames); } }); }; exports.SyncEachObj = SyncEachObj;