Add immutable state for tasks
This commit is contained in:
parent
233b33cbd4
commit
3905097151
@ -4,6 +4,7 @@ import { v4 as uuid } from 'uuid';
|
||||
import Scheduler from './Scheduler';
|
||||
import UpgradeBuildingTask from './Task/UpgradeBuildingTask';
|
||||
import { Command } from './Common';
|
||||
import TaskQueueRenderer from './TaskQueueRenderer';
|
||||
|
||||
export default class Dashboard {
|
||||
private scheduler: Scheduler;
|
||||
@ -19,6 +20,7 @@ export default class Dashboard {
|
||||
await sleepShort();
|
||||
|
||||
markPage('Dashboard');
|
||||
new TaskQueueRenderer().render(this.scheduler.taskState());
|
||||
|
||||
if (p.pathname === '/build.php') {
|
||||
console.log('BUILD PAGE DETECTED');
|
||||
|
@ -3,14 +3,14 @@ import UpgradeBuildingTask from './Task/UpgradeBuildingTask';
|
||||
import GoToBuildingAction from './Action/GoToBuildingAction';
|
||||
import UpgradeBuildingAction from './Action/UpgradeBuildingAction';
|
||||
import { TryLaterError } from './Errors';
|
||||
import { TaskQueue, State } from './Storage/TaskQueue';
|
||||
import { TaskQueue, State, ImmutableState } from './Storage/TaskQueue';
|
||||
import ActionQueue from './Storage/ActionQueue';
|
||||
import { Args, Command } from './Common';
|
||||
import TaskQueueRenderer from './TaskQueueRenderer';
|
||||
|
||||
export default class Scheduler {
|
||||
taskQueue: TaskQueue;
|
||||
actionQueue: ActionQueue;
|
||||
private taskQueue: TaskQueue;
|
||||
private actionQueue: ActionQueue;
|
||||
|
||||
constructor() {
|
||||
this.taskQueue = new TaskQueue();
|
||||
@ -45,6 +45,10 @@ export default class Scheduler {
|
||||
}
|
||||
}
|
||||
|
||||
taskState(): ImmutableState {
|
||||
return this.taskQueue.state();
|
||||
}
|
||||
|
||||
pushTask(task: Command): void {
|
||||
this.log('PUSH TASK', task);
|
||||
this.taskQueue.push(task);
|
||||
|
@ -49,6 +49,15 @@ export class State {
|
||||
}
|
||||
}
|
||||
|
||||
export class ImmutableState {
|
||||
readonly current: CommandWithTime | null;
|
||||
readonly items: Array<CommandWithTime>;
|
||||
constructor(state: State) {
|
||||
this.current = state.current;
|
||||
this.items = state.items;
|
||||
}
|
||||
}
|
||||
|
||||
export class TaskQueue {
|
||||
push(cmd: Command, ts: number | null = null) {
|
||||
this.log('PUSH TASK', cmd, ts);
|
||||
@ -73,8 +82,8 @@ export class TaskQueue {
|
||||
this.flushState(state);
|
||||
}
|
||||
|
||||
state(): State {
|
||||
return this.getState();
|
||||
state(): ImmutableState {
|
||||
return new ImmutableState(this.getState());
|
||||
}
|
||||
|
||||
private defaultTs(): number {
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { State } from './Storage/TaskQueue';
|
||||
import { ImmutableState } from './Storage/TaskQueue';
|
||||
|
||||
const ID = 'id-832654376836436939356';
|
||||
|
||||
export default class TaskQueueRenderer {
|
||||
render(state: State) {
|
||||
render(state: ImmutableState) {
|
||||
const ul = jQuery('<ul></ul>')
|
||||
.attr({ id: ID })
|
||||
.css({
|
||||
|
Loading…
x
Reference in New Issue
Block a user