@vnejs/plugins.feature.history 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/modules/history.js +29 -41
- package/package.json +5 -6
package/modules/history.js
CHANGED
|
@@ -3,12 +3,13 @@ import { Module } from "@vnejs/module";
|
|
|
3
3
|
export class History extends Module {
|
|
4
4
|
name = "history";
|
|
5
5
|
|
|
6
|
+
isLoadInProcess = false;
|
|
7
|
+
|
|
6
8
|
subscribe = () => {
|
|
7
9
|
this.on(this.EVENTS.HISTORY.LOAD, this.onHistoryLoad);
|
|
8
10
|
this.on(this.EVENTS.HISTORY.BACK, this.onHistoryBack);
|
|
9
11
|
|
|
10
|
-
this.on(this.EVENTS.TEXT.
|
|
11
|
-
this.on(this.EVENTS.TEXT.EMIT_END, this.onTextEmitEnd);
|
|
12
|
+
this.on(this.EVENTS.TEXT.INTERACT, this.onTextInteract);
|
|
12
13
|
|
|
13
14
|
this.on(this.EVENTS.STATE.CLEAR, this.setDefaultState);
|
|
14
15
|
this.on(this.EVENTS.STATE.SET, this.onSetState);
|
|
@@ -18,60 +19,47 @@ export class History extends Module {
|
|
|
18
19
|
this.shared.history = { storage: {}, storageKeys: [] };
|
|
19
20
|
};
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
this.
|
|
23
|
-
this.presavedHistory.scenario.curLine++;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
onTextEmit = async () => {
|
|
27
|
-
if (!this.presavedHistory) return;
|
|
28
|
-
|
|
29
|
-
const lastHistory = this.state.history[this.state.history.length - 1];
|
|
30
|
-
if (lastHistory && this.presavedHistory.text.originalText === lastHistory.text) return;
|
|
22
|
+
onTextInteract = async ({ state: textInteractState } = {}) => {
|
|
23
|
+
if (this.isLoadInProcess || textInteractState !== this.CONST.TEXT.INTERACT_STATES.EMPTY) return;
|
|
31
24
|
|
|
25
|
+
const state = await this.emitOne(this.EVENTS.STATE.GET);
|
|
32
26
|
const uid = (await this.emitOne(this.EVENTS.VENDORS.UID)).split("-").slice(0, 3).join("");
|
|
33
27
|
|
|
34
|
-
this.
|
|
28
|
+
this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { action: "add", uid } });
|
|
35
29
|
|
|
36
|
-
|
|
30
|
+
const [speaker, label, text] = [state?.text?.text?.speaker, state?.scenario.label, state?.text?.originalText];
|
|
31
|
+
|
|
32
|
+
this.shared.history.storage[uid] = state;
|
|
37
33
|
this.shared.history.storageKeys.push(uid);
|
|
38
|
-
this.state.history.push({
|
|
39
|
-
uid,
|
|
40
|
-
label: this.presavedHistory.scenario.label,
|
|
41
|
-
text: this.presavedHistory.text.originalText,
|
|
42
|
-
speaker: this.presavedHistory.text.speaker,
|
|
43
|
-
meet: this.presavedHistory.meet[this.presavedHistory.text.speaker] || 0,
|
|
44
|
-
});
|
|
34
|
+
this.state.history.push({ uid, label, text, speaker, meet: state?.["text.meet"]?.[speaker] || 0 });
|
|
45
35
|
|
|
46
36
|
while (this.state.history.length > 50) this.state.history.shift();
|
|
47
|
-
this.
|
|
48
|
-
while (this.shared.history.storageKeys.length > 100)
|
|
49
|
-
delete this.shared.history.storage[this.shared.history.storageKeys.shift()];
|
|
37
|
+
while (this.shared.history.storageKeys.length > 100) delete this.shared.history.storage[this.shared.history.storageKeys.shift()];
|
|
50
38
|
};
|
|
51
39
|
|
|
52
40
|
onHistoryLoad = async ({ uid } = {}) => {
|
|
41
|
+
this.isLoadInProcess = true;
|
|
42
|
+
|
|
53
43
|
const state = this.shared.history.storage[uid];
|
|
54
44
|
|
|
55
|
-
if (state) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
45
|
+
if (!state) return this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { action: "deleted" } });
|
|
46
|
+
|
|
47
|
+
while (this.shared.history.storageKeys.length) {
|
|
48
|
+
const uidToDelete = this.shared.history.storageKeys.pop();
|
|
49
|
+
delete this.shared.history.storage[uidToDelete];
|
|
50
|
+
if (uidToDelete === uid) break;
|
|
51
|
+
}
|
|
52
|
+
const clonedState = await this.emitOne(this.EVENTS.VENDORS.CLONE, state);
|
|
53
|
+
await this.emit(this.EVENTS.STATE.LOAD, clonedState);
|
|
54
|
+
this.emit(this.EVENTS.SCENARIO.LABEL_GET, { label: state.scenario.label });
|
|
55
|
+
|
|
56
|
+
this.isLoadInProcess = false;
|
|
66
57
|
};
|
|
67
58
|
|
|
68
|
-
onHistoryBack = () =>
|
|
69
|
-
this.state.history.length &&
|
|
70
|
-
this.emit(this.EVENTS.HISTORY.LOAD, { uid: this.state.history[this.state.history.length - 1].uid });
|
|
59
|
+
onHistoryBack = () => this.state.history.length && this.emit(this.EVENTS.HISTORY.LOAD, { uid: this.state.history[this.state.history.length - 1].uid });
|
|
71
60
|
|
|
72
|
-
onSetState =
|
|
73
|
-
this.state.history =
|
|
74
|
-
this.presavedHistory = await this.emitOne(this.EVENTS.VENDORS.CLONE, globalState);
|
|
61
|
+
onSetState = ({ [this.name]: state } = {}) => {
|
|
62
|
+
this.state.history = state.history;
|
|
75
63
|
};
|
|
76
64
|
|
|
77
65
|
getDefaultState = () => ({ history: [] });
|
package/package.json
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.feature.history",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
|
+
"publish:major:plugin": "npm run publish:major",
|
|
8
|
+
"publish:minor:plugin": "npm run publish:minor",
|
|
9
|
+
"publish:patch:plugin": "npm run publish:patch",
|
|
7
10
|
"publish:major": "npm version major && npm publish --access public",
|
|
8
11
|
"publish:minor": "npm version minor && npm publish --access public",
|
|
9
12
|
"publish:patch": "npm version patch && npm publish --access public"
|
|
10
13
|
},
|
|
11
14
|
"author": "",
|
|
12
15
|
"license": "ISC",
|
|
13
|
-
"description": ""
|
|
14
|
-
"peerDependencies": {
|
|
15
|
-
"@vnejs/shared": "*",
|
|
16
|
-
"@vnejs/module": "*"
|
|
17
|
-
}
|
|
16
|
+
"description": ""
|
|
18
17
|
}
|