-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
104 lines (90 loc) · 2.2 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import Renderer from './dist/Renderer.js';
import { ModelType } from './dist/Types.js';
import { TESTS } from './dist/TestData.js';
const app = Vue.createApp({
data() {
return {
renderer: null,
viewWidth: 0,
viewHeight: 0,
viewModel: [],
isValid: false,
isAutoStep: false,
stepSize: 1,
maxStepSize: 10_000,
timerId: null,
modelType: ModelType.MANUAL,
testData: TESTS,
selectedData: 5
};
},
methods: {
startTimer() {
if (this.timerId) {
clearInterval(this.timerId);
}
this.timerId = setTimeout(() => {
this.nextStep();
}, 1);
},
stopTimer() {
if (this.timerId) {
clearInterval(this.timerId);
}
},
nextStep() {
for (let i = 0; i < this.stepSize; i++) {
this.renderer.nextStep();
this.validate();
}
this.viewModel = this.renderer.getModel();
if (this.isAutoStep && !this.isValid) {
this.startTimer();
}
},
validate() {
this.isValid = this.renderer.validateModel();
if (this.isValid) {
this.viewModel = this.renderer.getModel();
this.stopTimer();
}
},
init() {
this.viewModel = this.renderer.getModel();
const { rows, columns } = this.renderer.getSize();
this.viewHeight = rows;
this.viewWidth = columns;
this.isAutoStep = false;
this.validate();
}
},
watch: {
selectedData(dataIndex) {
this.renderer = new Renderer(TESTS[dataIndex]);
this.init();
},
isAutoStep(state) {
if (!state || this.isValid) {
this.stopTimer();
}
if (this.isValid) {
return;
}
if (state) {
this.startTimer();
}
}
},
beforeMount() {
this.renderer = new Renderer(TESTS[this.selectedData]);
},
mounted() {
this.init();
},
unmounted() {
if (this.timerId) {
clearInterval(this.timerId);
}
}
});
app.mount('#app');