wonder.js
Version:
58 lines (49 loc) • 2.2 kB
JavaScript
;
var Curry = require("bs-platform/lib/js/curry.js");
var Log$WonderLog = require("wonder-log/lib/js/src/Log.js");
var Contract$WonderLog = require("wonder-log/lib/js/src/Contract.js");
var ArrayService$Wonderjs = require("../../atom/ArrayService.js");
var ArrayService$WonderCommonlib = require("wonder-commonlib/lib/js/src/ArrayService.js");
var MutableSparseMapService$WonderCommonlib = require("wonder-commonlib/lib/js/src/MutableSparseMapService.js");
function isAlive(component, disposedIndexArray) {
return !disposedIndexArray.includes(component);
}
function checkComponentShouldAlive(component, isAliveFunc, record) {
return Contract$WonderLog.test(Log$WonderLog.buildAssertMessage("dispose the alive component", "not"), (function (param) {
return Contract$WonderLog.assertTrue(Curry._2(isAliveFunc, component, record));
}));
}
function checkComponentShouldAliveWithBatchDispose(componentArr, isAliveFunc, record) {
return ArrayService$WonderCommonlib.forEach((function (component) {
return checkComponentShouldAlive(component, isAliveFunc, record);
}), componentArr);
}
var disposeSparseMapData = MutableSparseMapService$WonderCommonlib.deleteVal;
function removeFromArray(target, arr) {
var index = arr.indexOf(target);
var match = index === -1;
if (match) {
return arr;
} else {
var lastIndex = arr.length - 1 | 0;
ArrayService$Wonderjs.deleteBySwap(index, lastIndex, arr);
return arr;
}
}
function batchRemoveFromArray(map, arr) {
var match = MutableSparseMapService$WonderCommonlib.length(map) === 0;
if (match) {
return arr;
} else {
return arr.filter((function (value) {
return MutableSparseMapService$WonderCommonlib.has(value, map) === false;
}));
}
}
exports.isAlive = isAlive;
exports.checkComponentShouldAlive = checkComponentShouldAlive;
exports.checkComponentShouldAliveWithBatchDispose = checkComponentShouldAliveWithBatchDispose;
exports.disposeSparseMapData = disposeSparseMapData;
exports.removeFromArray = removeFromArray;
exports.batchRemoveFromArray = batchRemoveFromArray;
/* Log-WonderLog Not a pure module */