Update prettier and reformat code

This commit is contained in:
Anton Vakhrushev 2020-10-10 10:21:30 +03:00
parent ecaa98b69c
commit 60078e94b2
39 changed files with 149 additions and 146 deletions

15
package-lock.json generated
View File

@ -410,6 +410,15 @@
"prettier": "^1.18.2",
"source-map": "~0.6.1",
"vue-template-es2015-compiler": "^1.9.0"
},
"dependencies": {
"prettier": {
"version": "1.19.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz",
"integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==",
"dev": true,
"optional": true
}
}
},
"@webassemblyjs/ast": {
@ -4107,9 +4116,9 @@
"dev": true
},
"prettier": {
"version": "1.19.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz",
"integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==",
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.1.2.tgz",
"integrity": "sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==",
"dev": true
},
"process": {

View File

@ -35,7 +35,7 @@
"mocha": "^7.2.0",
"mocha-junit-reporter": "^1.23.3",
"nyc": "^15.1.0",
"prettier": "^1.19.1",
"prettier": "^2.1.2",
"raw-loader": "^4.0.2",
"sass": "^1.27.0",
"sass-loader": "^8.0.2",

View File

@ -113,12 +113,12 @@ export class ControlPanel {
this.villageFactory
.createTaskCollection(villageId)
.getTasks()
.filter(t => t.name === UpgradeBuildingTask.name)
.map(t => t.args.buildId || 0);
.filter((t) => t.name === UpgradeBuildingTask.name)
.map((t) => t.args.buildId || 0);
if (p.pathname === '/dorf1.php') {
showResourceSlotIds(getBuildingsInQueue());
onResourceSlotCtrlClick(buildId => {
onResourceSlotCtrlClick((buildId) => {
this.onSlotCtrlClick(villageId, buildId);
showResourceSlotIds(getBuildingsInQueue());
});
@ -126,7 +126,7 @@ export class ControlPanel {
if (p.pathname === '/dorf2.php') {
showBuildingSlotIds(getBuildingsInQueue());
onBuildingSlotCtrlClick(buildId => {
onBuildingSlotCtrlClick((buildId) => {
this.onSlotCtrlClick(villageId, buildId);
showBuildingSlotIds(getBuildingsInQueue());
});
@ -151,7 +151,7 @@ export class ControlPanel {
el: `#${appId}`,
data: gameState,
store: createStore(villageFactory),
render: h => h(DashboardApp),
render: (h) => h(DashboardApp),
});
}

View File

@ -36,8 +36,8 @@ export default {
},
computed: {
...mapState({
isLogsVisible: state => state.views.logs,
isVillageEditorVisible: state => state.views.villageEditor,
isLogsVisible: (state) => state.views.logs,
isVillageEditorVisible: (state) => state.views.villageEditor,
}),
isSecondaryDashboardVisible() {
return this.isLogsVisible || this.isVillageEditorVisible;

View File

@ -43,7 +43,7 @@ export function createStore(villageFactory: VillageFactory) {
},
},
getters: {
reverseLogs: state => {
reverseLogs: (state) => {
return state.logs.slice().reverse();
},
},

View File

@ -27,7 +27,7 @@ import { mapState } from 'vuex';
export default {
computed: {
...mapState({
villageName: state => state.villageSettings.villageName,
villageName: (state) => state.villageSettings.villageName,
}),
sendResourcesThreshold: {
get() {

View File

@ -44,9 +44,7 @@ export class SendOnAdventureAction extends BaseAction {
private checkConfig(adventure: Adventure, health: number) {
for (let conf of CONFIG) {
if (adventure.level === conf.level && health >= conf.health) {
return jQuery(adventure.el)
.find('td.goTo .gotoAdventure')
.trigger('click');
return jQuery(adventure.el).find('td.goTo .gotoAdventure').trigger('click');
}
}
}
@ -55,11 +53,7 @@ export class SendOnAdventureAction extends BaseAction {
const adventures: Array<Adventure> = [];
jQuery('tr[id^=adventure]').each((index, el) => {
const imgClass =
jQuery(el)
.find('.difficulty img')
.attr('class')
?.toString() || '';
const imgClass = jQuery(el).find('.difficulty img').attr('class')?.toString() || '';
const level = Number(trimPrefix(imgClass, 'adventureDifficulty'));
if (!isNaN(level)) {
adventures.push({ el, level: level });

View File

@ -22,7 +22,7 @@ export class UpgradeResourceToLevelAction extends BaseAction {
const requiredLevel = getNumber(args.level);
const notUpgraded = deposits.filter(
dep => !dep.isUnderConstruction && requiredLevel > dep.level
(dep) => !dep.isUnderConstruction && requiredLevel > dep.level
);
if (notUpgraded.length === 0) {
@ -59,7 +59,7 @@ export class UpgradeResourceToLevelAction extends BaseAction {
return (
undefined ===
tasks.find(
task =>
(task) =>
task.name === UpgradeBuildingTask.name &&
task.args.villageId === villageId &&
task.args.buildId === dep.buildId

View File

@ -12,7 +12,7 @@ export class UpdateResourceContractsTask extends BaseTask {
const villages = this.factory.getAllVillages();
const tasks = villages
.map(v => this.factory.createTaskCollection(v.id).getTasks())
.map((v) => this.factory.createTaskCollection(v.id).getTasks())
.reduce((acc, tasks) => acc.concat(tasks), []);
const paths = uniqPaths([
@ -20,7 +20,7 @@ export class UpdateResourceContractsTask extends BaseTask {
...this.walkImprovementTask(tasks),
]);
return paths.map(p => ({
return paths.map((p) => ({
name: GoToPageAction.name,
args: { path: path(p.name, p.query) },
}));
@ -28,8 +28,10 @@ export class UpdateResourceContractsTask extends BaseTask {
private walkUpgradeTasks(tasks: ImmutableTaskList): PathList {
return tasks
.filter(t => t.name === UpgradeBuildingTask.name && t.args.villageId && t.args.buildId)
.map(t => ({
.filter(
(t) => t.name === UpgradeBuildingTask.name && t.args.villageId && t.args.buildId
)
.map((t) => ({
name: '/build.php',
query: { newdid: t.args.villageId, id: t.args.buildId },
}));
@ -37,8 +39,10 @@ export class UpdateResourceContractsTask extends BaseTask {
private walkImprovementTask(tasks: ImmutableTaskList): PathList {
return tasks
.filter(t => t.name === ForgeImprovementTask.name && t.args.villageId && t.args.buildId)
.map(t => ({
.filter(
(t) => t.name === ForgeImprovementTask.name && t.args.villageId && t.args.buildId
)
.map((t) => ({
name: '/build.php',
query: { newdid: t.args.villageId, id: t.args.buildId },
}));

View File

@ -55,7 +55,7 @@ export function createTaskHandler(
/**
* List on non intersected task queue predicates.
*/
const TASK_TYPE_PREDICATES: Array<TaskNamePredicate> = OrderedProductionQueues.map(queue => {
const TASK_TYPE_PREDICATES: Array<TaskNamePredicate> = OrderedProductionQueues.map((queue) => {
return (taskName: string) => getProductionQueue(taskName) === queue;
});

View File

@ -1,7 +1,7 @@
import * as URLParse from 'url-parse';
export async function waitForLoad() {
return new Promise(resolve => jQuery(resolve));
return new Promise((resolve) => jQuery(resolve));
}
export function parseLocation(location?: string | undefined) {

View File

@ -7,7 +7,7 @@ export function elClassId(classes: string | undefined, prefix: string): number |
return undefined;
}
let result: number | undefined = undefined;
classes.split(/\s/).forEach(part => {
classes.split(/\s/).forEach((part) => {
const match = part.match(new RegExp(prefix + '(\\d+)'));
if (match) {
result = toNumber(match[1]);

View File

@ -1,7 +1,7 @@
import { around, randomInRange } from './Random';
export function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
return new Promise((resolve) => setTimeout(resolve, ms));
}
export async function sleepMicro() {

View File

@ -26,7 +26,7 @@ export function createBuildButton(
const resElement = $el.find('.resourceWrapper .resource');
const resources = grabResourcesFromList(resElement);
$el.append(`<div style="padding: 8px"><a id="${btnId}" href="#">Построить</a></div>`);
jQuery(`#${btnId}`).on('click', evt => {
jQuery(`#${btnId}`).on('click', (evt) => {
evt.preventDefault();
onClickHandler(buildTypeId, resources);
});
@ -50,17 +50,14 @@ export function createUpgradeButton(onClickHandler: (resources: Resources) => vo
const btn = `<div style="padding: 8px"><a id="${id}" href="#">В очередь</a></div>`;
upgradeContainer.append(btn);
const resources = grabContractResources();
jQuery(`#${id}`).on('click', evt => {
jQuery(`#${id}`).on('click', (evt) => {
evt.preventDefault();
onClickHandler(resources);
});
}
export function grabResourcesFromList($els: JQuery) {
const getText = (n: number) =>
jQuery($els.get(n))
.find('.value')
.text();
const getText = (n: number) => jQuery($els.get(n)).find('.value').text();
const grab = (n: number) => getNumber(getText(n));
return new Resources(grab(0), grab(1), grab(2), grab(3));
}

View File

@ -22,7 +22,7 @@ function createResearchButton($researchBlockEl: JQuery, onClickHandler: Research
<a id="${id}" href="#">Исследовать</a>
</div>`);
jQuery(`#${id}`).on('click', evt => {
jQuery(`#${id}`).on('click', (evt) => {
evt.preventDefault();
onClickHandler(resources, unitId);
});

View File

@ -45,7 +45,7 @@ function createCelebrationButton(
<a id="${id}" href="#">Праздновать</a>
</div>`);
jQuery(`#${id}`).on('click', evt => {
jQuery(`#${id}`).on('click', (evt) => {
evt.preventDefault();
onClickHandler(resources, idx);
});

View File

@ -23,7 +23,7 @@ export function createTrainTroopButtons(
);
const resElement = $el.find('.resourceWrapper .resource');
const resources = grabResourcesFromList(resElement);
jQuery(`#${id}`).on('click', evt => {
jQuery(`#${id}`).on('click', (evt) => {
evt.preventDefault();
const input = $el.find(`input[name="t${troopId}"]`);
const count = getNumber(input.val());

View File

@ -46,7 +46,7 @@ export class BuildingPageController {
this.logger.info('BUILD PAGE DETECTED', 'ID', this.attributes.buildId, this.attributes);
if (buildTypeId) {
createUpgradeButton(res => this.onScheduleUpgradeBuilding(res));
createUpgradeButton((res) => this.onScheduleUpgradeBuilding(res));
} else {
createBuildButton((buildTypeId, res) => this.onScheduleBuildBuilding(buildTypeId, res));
}
@ -126,7 +126,7 @@ export class BuildingPageController {
private onSendResources(coordinates: Coordinates) {
const villageId = grabActiveVillageId();
const targetVillage = grabVillageList().find(v => v.crd.eq(coordinates));
const targetVillage = grabVillageList().find((v) => v.crd.eq(coordinates));
this.scheduler.scheduleTask(SendResourcesTask.name, {
villageId: villageId,
targetVillageId: targetVillage?.id,

View File

@ -18,8 +18,8 @@ function slotElements(prefix: string): Array<SlotElement> {
function showSlotIds(prefix: string, buildingIds: Array<number>): void {
const slots = slotElements(prefix);
slots.forEach(slot => {
const upCount = buildingIds.filter(id => id === slot.buildId).length;
slots.forEach((slot) => {
const upCount = buildingIds.filter((id) => id === slot.buildId).length;
const $slotEl = jQuery(slot.el);
const $labelEl = $slotEl.find('.labelLayer');
const oldLabel = $labelEl.data('oldLabel') || $labelEl.text();
@ -53,10 +53,10 @@ export function showBuildingSlotIds(buildingIds: number[]): void {
function onSlotCtrlClick(prefix: string, onClickHandler: (buildId: number) => void): void {
const slots = slotElements(prefix);
slots.forEach(slot => {
slots.forEach((slot) => {
jQuery(slot.el)
.find('.labelLayer')
.on('click', evt => {
.on('click', (evt) => {
if (evt.ctrlKey) {
evt.preventDefault();
evt.stopPropagation();

View File

@ -47,7 +47,7 @@ export class ActionQueue {
const items = serialized as Array<{ [key: string]: any }>;
return items.map(i => {
return items.map((i) => {
const command = { name: '', args: {} };
return Object.assign(command, i);
});

View File

@ -24,7 +24,7 @@ export class DataStorageTaskProvider implements TaskProvider {
const storedItems = serialized as Array<{ [key: string]: any }>;
return storedItems.map(i => {
return storedItems.map((i) => {
const task = new Task(uniqTaskId(), 0, '', {});
return Object.assign(task, i);
});

View File

@ -19,7 +19,7 @@ export class TaskQueue {
}
get(ts: number): Task | undefined {
const readyItems = this.getItems().filter(t => t.ts <= ts);
const readyItems = this.getItems().filter((t) => t.ts <= ts);
if (readyItems.length === 0) {
return undefined;
}
@ -27,7 +27,7 @@ export class TaskQueue {
}
findById(taskId: TaskId): Task | undefined {
const [matched, _] = this.split(t => t.id === taskId);
const [matched, _] = this.split((t) => t.id === taskId);
return matched.shift();
}
@ -58,7 +58,7 @@ export class TaskQueue {
private split(predicate: (t: Task) => boolean): [TaskList, TaskList] {
const matched: TaskList = [];
const other: TaskList = [];
this.getItems().forEach(t => {
this.getItems().forEach((t) => {
if (predicate(t)) {
matched.push(t);
} else {

View File

@ -141,10 +141,10 @@ export class Scheduler {
let alreadyHasTask;
if (args.villageId) {
alreadyHasTask = this.taskQueue.has(
t => t.name === name && t.args.villageId === args.villageId
(t) => t.name === name && t.args.villageId === args.villageId
);
} else {
alreadyHasTask = this.taskQueue.has(t => t.name === name);
alreadyHasTask = this.taskQueue.has((t) => t.name === name);
}
if (!alreadyHasTask) {
@ -153,7 +153,7 @@ export class Scheduler {
}
removeTask(taskId: TaskId) {
this.taskQueue.remove(t => t.id === taskId);
this.taskQueue.remove((t) => t.id === taskId);
this.actionQueue.clear();
}
@ -168,7 +168,7 @@ export class Scheduler {
}
postponeTask(taskId: TaskId, seconds: number) {
const task = this.taskQueue.seeItems().find(t => t.id === taskId);
const task = this.taskQueue.seeItems().find((t) => t.id === taskId);
if (!task) {
return;
}
@ -179,7 +179,7 @@ export class Scheduler {
this.removeTask(taskId);
} else {
const modifyTime = withTime(timestamp() + seconds);
this.taskQueue.modify(t => t.id === taskId, modifyTime);
this.taskQueue.modify((t) => t.id === taskId, modifyTime);
}
}

View File

@ -42,10 +42,7 @@ export class Statistics {
private getTopStatKeys(stat: ActionStatistics) {
const keys = Object.keys(stat);
return keys
.sort()
.reverse()
.slice(0, KEEP_RECORD_COUNT);
return keys.sort().reverse().slice(0, KEEP_RECORD_COUNT);
}
getActionStatistics(): ActionStatistics {

View File

@ -6,7 +6,7 @@ const NAMESPACE = 'travian:v1';
const storage = localStorage;
function join(...parts: Array<string>) {
return parts.map(p => p.replace(/[:]+$/g, '').replace(/^[:]+/g, '')).join(':');
return parts.map((p) => p.replace(/[:]+$/g, '').replace(/^[:]+/g, '')).join(':');
}
export class DataStorage {

View File

@ -19,7 +19,7 @@ export function createMapper<T>(options: ObjectMapperOptions<T>): ObjectMapper<T
}
if (factory) {
return plain => {
return (plain) => {
let item = factory();
if (typeof plain === 'object' && typeof item === 'object') {
return Object.assign(item, plain) as T;

View File

@ -74,7 +74,7 @@ export class VillageStorage {
storeIncomingMerchants(merchants: ReadonlyArray<IncomingMerchant>): void {
this.storage.set(
INCOMING_MERCHANTS_KEY,
merchants.map(m => ({ ...m.resources, ts: m.ts }))
merchants.map((m) => ({ ...m.resources, ts: m.ts }))
);
}

View File

@ -6,9 +6,7 @@ const ID = uniqId();
export class TaskQueueRenderer {
render(tasks: ImmutableTaskList) {
const ul = jQuery('<ul></ul>')
.attr({ id: ID })
.css({
const ul = jQuery('<ul></ul>').attr({ id: ID }).css({
'position': 'absolute',
'background-color': 'white',
'left': 0,
@ -17,7 +15,7 @@ export class TaskQueueRenderer {
'z-index': '9999',
'padding': '8px 6px',
});
tasks.forEach(task => {
tasks.forEach((task) => {
ul.append(
jQuery('<li></li>').text(formatDate(task.ts) + ' ' + task.name + ' ' + task.id)
);

View File

@ -171,19 +171,21 @@ export class VillageController {
const resourceSlots = this.storage.getResourceSlots();
const tasks = this.taskCollection.getTasks();
const cropSlots = resourceSlots.filter(s => s.type === ResourceType.Crop && !s.isMaxLevel);
const cropSlots = resourceSlots.filter(
(s) => s.type === ResourceType.Crop && !s.isMaxLevel
);
if (cropSlots.length === 0) {
return;
}
// Check, if crop field is building now
const underContraction = cropSlots.find(s => s.isUnderConstruction);
const underContraction = cropSlots.find((s) => s.isUnderConstruction);
if (underContraction !== undefined) {
return;
}
// Check, if we already have crop task in queue
const cropBuildIds = cropSlots.map(s => s.buildId);
const cropBuildIds = cropSlots.map((s) => s.buildId);
for (let buildId of cropBuildIds) {
const upgradeTask = tasks.find(
isBuildingPlanned(UpgradeBuildingTask.name, buildId, undefined)
@ -207,11 +209,11 @@ export class VillageController {
}
private planWarehouseBuilding(): void {
this.planStorageBuilding(WAREHOUSE_ID, t => !t.isEnoughWarehouseCapacity);
this.planStorageBuilding(WAREHOUSE_ID, (t) => !t.isEnoughWarehouseCapacity);
}
private planGranaryBuilding(): void {
this.planStorageBuilding(GARNER_ID, t => !t.isEnoughGranaryCapacity);
this.planStorageBuilding(GARNER_ID, (t) => !t.isEnoughGranaryCapacity);
}
private planStorageBuilding(
@ -221,14 +223,14 @@ export class VillageController {
const buildingSlots = this.storage.getBuildingSlots();
const storageSlots = buildingSlots.filter(
s => s.buildTypeId === buildTypeId && !s.isMaxLevel
(s) => s.buildTypeId === buildTypeId && !s.isMaxLevel
);
if (storageSlots.length === 0) {
return;
}
// Check, if storage is building now
const underConstruction = storageSlots.find(s => s.isUnderConstruction);
const underConstruction = storageSlots.find((s) => s.isUnderConstruction);
if (underConstruction !== undefined) {
return;
}
@ -236,7 +238,7 @@ export class VillageController {
const tasks = this.state.tasks;
// Check, if we have storage is in building queue
const storageBuildIds = storageSlots.map(s => s.buildId);
const storageBuildIds = storageSlots.map((s) => s.buildId);
for (let buildId of storageBuildIds) {
const upgradeTask = tasks.find(
isBuildingPlanned(UpgradeBuildingTask.name, buildId, buildTypeId)

View File

@ -13,7 +13,7 @@ export class VillageRepository implements VillageRepositoryInterface {
}
get(villageId: number): Village {
const village = this.all().find(vlg => vlg.id === villageId);
const village = this.all().find((vlg) => vlg.id === villageId);
if (!village) {
throw new VillageNotFound('Active village not found');
}
@ -21,7 +21,7 @@ export class VillageRepository implements VillageRepositoryInterface {
}
getByCrd(crd: Coordinates): Village {
const village = this.all().find(vlg => vlg.crd.eq(crd));
const village = this.all().find((vlg) => vlg.crd.eq(crd));
if (!village) {
throw new VillageNotFound('Village not found');
}
@ -29,7 +29,7 @@ export class VillageRepository implements VillageRepositoryInterface {
}
getActive(): Village {
const village = this.all().find(vlg => vlg.active);
const village = this.all().find((vlg) => vlg.active);
if (!village) {
throw new VillageNotFound('Active village not found');
}

View File

@ -220,7 +220,7 @@ function createTaskQueueStates(
storage: VillageStorage
) {
let result: Array<VillageProductionQueueState> = [];
const possibleTasks = tasks.filter(task => task.canBeBuilt);
const possibleTasks = tasks.filter((task) => task.canBeBuilt);
for (let taskQueueInfo of getGroupedByQueueTasks(possibleTasks, storage)) {
result.push(createProductionQueueState(taskQueueInfo, warehouse));
}
@ -230,12 +230,14 @@ function createTaskQueueStates(
function getReadyForProductionTask(
queues: ReadonlyArray<VillageProductionQueueState>
): TaskState | undefined {
const firstReadyQueue = queues.find(queue => queue.isWaiting);
const firstReadyQueue = queues.find((queue) => queue.isWaiting);
if (!firstReadyQueue) {
return undefined;
}
return firstReadyQueue.tasks.find(task => task.name === TrainTroopTask.name || task.canBeBuilt);
return firstReadyQueue.tasks.find(
(task) => task.name === TrainTroopTask.name || task.canBeBuilt
);
}
function getTaskResources(task: TaskCore | undefined): Resources {
@ -284,7 +286,7 @@ function createVillageOwnState(
const storageState = makeStorageState(resources, storageResources, performance);
const tasks = taskCollection
.getTasks()
.map(t => makeTaskState(t, storageState.optimumFullness));
.map((t) => makeTaskState(t, storageState.optimumFullness));
const queues = createTaskQueueStates(storageState, tasks, storage);
const firstReadyTask = getReadyForProductionTask(queues);
const requiredResources = getTaskResources(firstReadyTask);
@ -323,7 +325,7 @@ function createVillageState(
state: VillageOwnState,
ownStates: VillageOwnStateDictionary
): VillageState {
const villageIds = Object.keys(ownStates).map(k => +k);
const villageIds = Object.keys(ownStates).map((k) => +k);
const commitments = villageIds.reduce((memo, shipmentVillageId) => {
const shipmentVillageState = ownStates[shipmentVillageId];
const shipmentVillageRequired = shipmentVillageState.required;
@ -342,7 +344,7 @@ function getVillageStates(
taskCollectionFactory: VillageTaskCollectionFactory
): Array<VillageState> {
const ownStates = createVillageOwnStates(villages, storageFactory, taskCollectionFactory);
return villages.map(village => createVillageState(ownStates[village.id], ownStates));
return villages.map((village) => createVillageState(ownStates[village.id], ownStates));
}
interface VillageStorageFactory {
@ -382,7 +384,7 @@ export class VillageStateFactory {
this.storageFactory,
this.taskCollectionFactory
);
const needle = states.find(s => s.id === villageId);
const needle = states.find((s) => s.id === villageId);
if (!needle) {
throw new VillageNotFound(`Village ${villageId} not found`);
}

View File

@ -24,13 +24,13 @@ export class VillageTaskCollection {
private modifyTasks(predicate: (t: Task) => boolean, modifier: (t: Task) => Task): void {
const tasks = this.getTasks();
const modified = tasks.map(t => (predicate(t) ? modifier(t) : t));
const modified = tasks.map((t) => (predicate(t) ? modifier(t) : t));
this.storage.storeTaskList(modified);
}
private removeTasks(predicate: (t: Task) => boolean): void {
const tasks = this.getTasks();
const remaining = tasks.filter(t => !predicate(t));
const remaining = tasks.filter((t) => !predicate(t));
this.storage.storeTaskList(remaining);
}
@ -55,12 +55,12 @@ export class VillageTaskCollection {
}
removeTask(taskId: TaskId) {
this.removeTasks(t => t.id === taskId);
this.removeTasks((t) => t.id === taskId);
}
upTask(taskId: TaskId): void {
const tasks = this.storage.getTasks();
const index = tasks.findIndex(t => t.id === taskId);
const index = tasks.findIndex((t) => t.id === taskId);
if (index < 0 || index === 0) {
return;
}
@ -71,7 +71,7 @@ export class VillageTaskCollection {
downTask(taskId: TaskId) {
const tasks = this.storage.getTasks();
const index = tasks.findIndex(t => t.id === taskId);
const index = tasks.findIndex((t) => t.id === taskId);
if (index < 0 || index === tasks.length - 1) {
return;
}
@ -82,7 +82,7 @@ export class VillageTaskCollection {
postponeTask(taskId: TaskId, seconds: number) {
const modifyTime = withTime(timestamp() + seconds);
this.modifyTasks(task => task.id === taskId, modifyTime);
this.modifyTasks((task) => task.id === taskId, modifyTime);
}
updateResourcesInTasks(resources: Resources, attr: ContractAttributes): void {

View File

@ -27,7 +27,7 @@ describe('Task Queue', function() {
new Task('id2', 2, 'task2', {}),
]);
const queue = new TaskQueue(provider, new NullLogger());
queue.remove(t => t.id === 'id1');
queue.remove((t) => t.id === 'id1');
const tasks = provider.getTasks();
expect(tasks).to.have.lengthOf(1);
expect(tasks[0].ts).to.be.equals(2);
@ -41,8 +41,8 @@ describe('Task Queue', function() {
]);
const queue = new TaskQueue(provider, new NullLogger());
queue.modify(
t => t.ts < 4,
t => new Task(t.id, 10, t.name, t.args)
(t) => t.ts < 4,
(t) => new Task(t.id, 10, t.name, t.args)
);
const tasks = provider.getTasks();
expect(4).is.equals(tasks[0].ts);