@dark-engine/core
Version:
The lightweight and powerful UI rendering engine without dependencies and written in TypeScript (Browser, Node.js, Android, iOS, Windows, Linux, macOS)
27 lines (26 loc) • 695 B
JavaScript
import { $$scope } from '../scope';
function batch(callback) {
const $scope = $$scope();
$scope.setIsBatch(true);
callback();
$scope.setIsBatch(false);
}
function addBatch(hook, callback, change) {
const $scope = $$scope();
if ($scope.getIsTransition()) {
callback();
} else {
const batch = hook.getBatch() || { timer: null, changes: [] };
hook.setBatch(batch);
batch.changes.push(change);
batch.timer && clearTimeout(batch.timer);
batch.timer = setTimeout(() => {
batch.changes.splice(-1);
batch.changes.forEach(x => x());
hook.setBatch(null);
callback();
});
}
}
export { batch, addBatch };
//# sourceMappingURL=batch.js.map