代码拉取完成,页面将自动刷新
"use strict";
exports.__esModule = true;
exports.filterCacheChildren = void 0;
var childrenBuilder_1 = require("./childrenBuilder");
var util_1 = require("./util");
var CacheViewModel = /** @class */ (function () {
function CacheViewModel(row, life, result) {
this.row = row;
this.life = life;
this.result = result;
this.once = new util_1.OnceInitDestry();
}
CacheViewModel.prototype.init = function () {
this.once.init();
this.resultDestroy = (0, util_1.orRun)(this.result);
};
CacheViewModel.prototype.destroy = function () {
this.once.destroy();
this.life.destroy();
(0, util_1.orRun)(this.resultDestroy);
};
return CacheViewModel;
}());
/**
* 有缓存mvc
* @param array
* @param fun
* @returns
*/
function filterCacheChildren(array, fun) {
return function (parent, me) {
var views = [];
var life = (0, util_1.onceLife)(function () {
var size = views.length;
for (var i = 0; i < size; i++) {
views[i].init();
}
return function () {
var size = views.length;
for (var i = size - 1; i > -1; i--) {
views[i].destroy();
}
views.length = 0;
w.disable();
};
});
var w = util_1.Watcher.ofAfter(array, function (vs) {
if (vs.length < views.length) {
//更新旧数据视图
for (var i = 0; i < vs.length; i++) {
views[i].row(vs[i]);
}
var minLength = vs.length - 1;
for (var i = views.length - 1; i > minLength; i--) {
//销毁
if (life.isInit) {
views[i].destroy();
}
//删除视图
parent.remove(i);
}
views.length = vs.length;
}
else {
//更新旧数据
for (var i = 0; i < views.length; i++) {
views[i].row(vs[i]);
}
//追加新数据
for (var i = views.length; i < vs.length; i++) {
var row = util_1.mve.valueOf(vs[i]);
var lifeModel = (0, util_1.newLifeModel)();
//创建视图
var vm = parent.newChildAt(i);
var cs = fun(lifeModel.me, row, i);
var vx = (0, childrenBuilder_1.baseChildrenBuilder)(lifeModel.me, cs, vm);
var cv = new CacheViewModel(row, lifeModel, vx);
//模型增加
views.push(cv);
//初始化
if (life.isInit) {
cv.init();
}
}
}
});
return life.init;
};
}
exports.filterCacheChildren = filterCacheChildren;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。