@vnejs/compatibility.text-with-scenario.history 0.2.1 → 0.2.3
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/dist/index.d.ts +2 -2
- package/dist/index.js +3 -1
- package/package.json +1 -1
- package/src/index.ts +5 -3
- package/src/tests/history.test.ts +7 -12
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ import { ModuleCore } from "@vnejs/module.core";
|
|
|
4
4
|
import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "./types.js";
|
|
5
5
|
export declare class CompatibilityTextWithScenarioHistory extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
|
|
6
6
|
name: string;
|
|
7
|
-
|
|
8
|
-
onTextEmitNext: () => Promise<
|
|
7
|
+
subscribe: () => void;
|
|
8
|
+
onTextEmitNext: () => Promise<import("@vnejs/shared").EmitResults<"vne:history:add"> | undefined>;
|
|
9
9
|
}
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,9 @@ import { getTextSpeakerInfo } from "@vnejs/contracts.text";
|
|
|
6
6
|
const MARK_REG = /\{.*?\}/g;
|
|
7
7
|
export class CompatibilityTextWithScenarioHistory extends ModuleCore {
|
|
8
8
|
name = "compatibility.text-with-scenario.history";
|
|
9
|
-
|
|
9
|
+
subscribe = () => {
|
|
10
|
+
this.on(this.EVENTS.TEXT.EMIT_NEXT, this.onTextEmitNext);
|
|
11
|
+
};
|
|
10
12
|
onTextEmitNext = async () => {
|
|
11
13
|
const texts = this.globalState.text.texts;
|
|
12
14
|
if (!texts.length)
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import "@vnejs/contracts.text";
|
|
|
4
4
|
import { ModuleCore } from "@vnejs/module.core";
|
|
5
5
|
import { regModule } from "@vnejs/shared";
|
|
6
6
|
|
|
7
|
-
import { getTextSpeakerInfo } from "@vnejs/contracts.text";
|
|
7
|
+
import { getTextSpeakerInfo, type TextSpeakerEntry } from "@vnejs/contracts.text";
|
|
8
8
|
|
|
9
9
|
import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "./types.js";
|
|
10
10
|
|
|
@@ -13,7 +13,9 @@ const MARK_REG = /\{.*?\}/g;
|
|
|
13
13
|
export class CompatibilityTextWithScenarioHistory extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
|
|
14
14
|
name = "compatibility.text-with-scenario.history";
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
subscribe = () => {
|
|
17
|
+
this.on(this.EVENTS.TEXT.EMIT_NEXT, this.onTextEmitNext);
|
|
18
|
+
};
|
|
17
19
|
|
|
18
20
|
onTextEmitNext = async () => {
|
|
19
21
|
const texts = this.globalState.text.texts;
|
|
@@ -25,7 +27,7 @@ export class CompatibilityTextWithScenarioHistory extends ModuleCore<PluginEvent
|
|
|
25
27
|
const args = texts[texts.length - 1].args;
|
|
26
28
|
const speakerState = this.globalState["text.speaker"];
|
|
27
29
|
const speaker = speakerState.speaker;
|
|
28
|
-
const speakerInfo = await this.emitClone(getTextSpeakerInfo(speakerState, speaker));
|
|
30
|
+
const speakerInfo = await this.emitClone<TextSpeakerEntry | undefined>(getTextSpeakerInfo(speakerState, speaker));
|
|
29
31
|
|
|
30
32
|
return this.emit(this.EVENTS.HISTORY.ADD, { label, text, args, speaker, speakerInfo });
|
|
31
33
|
};
|
|
@@ -8,32 +8,27 @@ import { createCompatibilityTestModule, HISTORY_EVENTS, registerCompatibilityVne
|
|
|
8
8
|
describe("CompatibilityTextWithScenarioHistory", () => {
|
|
9
9
|
beforeEach(() => registerCompatibilityVne());
|
|
10
10
|
|
|
11
|
-
it("
|
|
11
|
+
it("subscribe registers TEXT.EMIT_NEXT handler", () => {
|
|
12
12
|
const { module, observer } = createCompatibilityTestModule(CompatibilityTextWithScenarioHistory, { subscribe: false });
|
|
13
|
-
const reg = spyEvent(observer, TEXT_EVENTS.EMIT_NEXT_REG);
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
(module as CompatibilityTextWithScenarioHistory).subscribe();
|
|
16
15
|
|
|
17
|
-
expect(
|
|
18
|
-
|
|
16
|
+
expect(observer.subscribers[TEXT_EVENTS.EMIT_NEXT]?.flatMap((group) => group.subscribers)).toEqual(
|
|
17
|
+
expect.arrayContaining([expect.objectContaining({ func: (module as CompatibilityTextWithScenarioHistory).onTextEmitNext })]),
|
|
18
|
+
);
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
it("handler emits HISTORY.ADD with stripped text", async () => {
|
|
22
|
-
const {
|
|
23
|
-
subscribe: false,
|
|
22
|
+
const { observer } = createCompatibilityTestModule(CompatibilityTextWithScenarioHistory, {
|
|
24
23
|
state: {
|
|
25
24
|
"text": { uid: "u1", texts: [{ text: "Hello {mark}", args: { a: 1 } }], tokens: [], speaker: "hero" },
|
|
26
25
|
"text.speaker": { speaker: "hero", args: {}, speakersInfo: {} },
|
|
27
26
|
"scenario": { curLine: 1, label: "scene" },
|
|
28
27
|
},
|
|
29
28
|
});
|
|
30
|
-
const reg = spyEvent(observer, TEXT_EVENTS.EMIT_NEXT_REG);
|
|
31
29
|
const add = spyEvent(observer, HISTORY_EVENTS.ADD);
|
|
32
30
|
|
|
33
|
-
await (
|
|
34
|
-
|
|
35
|
-
const handler = reg.mock.calls[0]?.[0]?.handler as () => Promise<unknown>;
|
|
36
|
-
await handler();
|
|
31
|
+
await observer.emit(TEXT_EVENTS.EMIT_NEXT);
|
|
37
32
|
|
|
38
33
|
expect(add).toHaveBeenCalledOnce();
|
|
39
34
|
expect(add.mock.calls[0]?.[0]).toMatchObject({ label: "scene", text: "Hello ", speaker: "hero", args: { a: 1 } });
|