-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.js
59 lines (48 loc) · 1.72 KB
/
main.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
import {
createCore,
startEventRecorder,
stopEventRecorder,
replayEvents,
useDefaultLogging,
} from "../../dist/core.es.js";
// import { } from "./eventNames.js";
// import { x, y } from "./dependencies.js";
// import { configuration } from "./configuration.js";
import * as tweetForm from "../simple/tweet-form.js";
import * as tweetList from "../simple/tweet-list.js";
import * as tweetCounter from "../simple/tweet-counter.js";
const core = createCore();
// listen for all events
useDefaultLogging(core);
let eventRecording;
let moduleInstanceNames = [];
const initialTweetsInHtml = 1;
const restart = async (initialCount = 0) => {
stopEventRecorder(core, eventRecording);
await Promise.all(moduleInstanceNames.map(moduleInstanceName => {
return core.stop(moduleInstanceName);
}));
eventRecording = startEventRecorder(core);
const tweetFormName = await core.start(tweetForm);
const tweetListName = await core.start(tweetList);
const tweetCounterFirstName = await core.start(tweetCounter, { name: `first counter`, data: initialCount});
moduleInstanceNames = [
tweetFormName,
tweetListName,
tweetCounterFirstName,
];
};
const controlZ = async () => {
const previousEvents = eventRecording.events;
// omit this and the function is basically a replay
previousEvents.pop(); // forget last
await restart();
replayEvents(core, previousEvents, { sameSpeed: false });
};
// const replay = async () => {
// const previousEvents = eventRecording.events;
// await restart();
// replayEvents(core, previousEvents, { sameSpeed: true });
// };
document.getElementById(`undo`).addEventListener(`click`, controlZ);
restart(initialTweetsInHtml);