@vnejs/plugins.text.wall 0.2.3 → 0.2.4

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.
@@ -4,6 +4,6 @@ import type { ModuleGlobalStateTextWall } from "@vnejs/contracts.text.wall";
4
4
  import type { TextWallPluginConstants, TextWallPluginEvents, TextWallPluginParams, TextWallPluginSettings } from "../types.js";
5
5
  export declare class TextWallEmitBefore extends ModuleCore<TextWallPluginEvents, TextWallPluginConstants, TextWallPluginSettings, TextWallPluginParams, ModuleGlobalStateTextWall> {
6
6
  name: string;
7
- init: () => Promise<import("@vnejs/shared").EmitResults<"vne:text:emit_before_reg">> | undefined;
7
+ subscribe: () => void;
8
8
  onTextEmitBefore: ({ isExtend }?: TextEmitBeforePayload) => Promise<import("@vnejs/shared").EmitResults<"vne:text_wall:state_update"> | undefined>;
9
9
  }
@@ -2,7 +2,9 @@ import { ModuleCore } from "@vnejs/module.core";
2
2
  import { getTextSpeakerInfo } from "@vnejs/contracts.text";
3
3
  export class TextWallEmitBefore extends ModuleCore {
4
4
  name = "text.wall.emit.before";
5
- init = () => this.emit(this.EVENTS.TEXT.EMIT_BEFORE_REG, { handler: this.onTextEmitBefore });
5
+ subscribe = () => {
6
+ this.on(this.EVENTS.TEXT.EMIT_BEFORE, this.onTextEmitBefore);
7
+ };
6
8
  onTextEmitBefore = async ({ isExtend = false } = {}) => {
7
9
  const state = this.globalState["text.wall"];
8
10
  if (isExtend || !state.isStarted || this.shared.isTextWallSetStateInProcess)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.text.wall",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,7 +15,9 @@ export class TextWallEmitBefore extends ModuleCore<
15
15
  > {
16
16
  name = "text.wall.emit.before";
17
17
 
18
- init = () => this.emit(this.EVENTS.TEXT.EMIT_BEFORE_REG, { handler: this.onTextEmitBefore });
18
+ subscribe = () => {
19
+ this.on(this.EVENTS.TEXT.EMIT_BEFORE, this.onTextEmitBefore);
20
+ };
19
21
 
20
22
  onTextEmitBefore = async ({ isExtend = false }: TextEmitBeforePayload = {}) => {
21
23
  const state = this.globalState["text.wall"];
@@ -10,13 +10,14 @@ describe("TextWallEmitBefore", () => {
10
10
  registerTextWallPluginVne();
11
11
  });
12
12
 
13
- it("init registers emit before handler", async () => {
13
+ it("subscribe registers emit before handler", () => {
14
14
  const { module, observer } = createTextWallTestModule(TextWallEmitBefore, { subscribe: false });
15
- const emitBeforeReg = spyEvent(observer, TEXT_EVENTS.EMIT_BEFORE_REG);
16
15
 
17
- await (module as TextWallEmitBefore).init();
16
+ (module as TextWallEmitBefore).subscribe();
18
17
 
19
- expect(emitBeforeReg).toHaveBeenCalledExactlyOnceWith({ handler: (module as TextWallEmitBefore).onTextEmitBefore });
18
+ expect(observer.subscribers[TEXT_EVENTS.EMIT_BEFORE]?.flatMap((group) => group.subscribers)).toEqual(
19
+ expect.arrayContaining([expect.objectContaining({ func: (module as TextWallEmitBefore).onTextEmitBefore })]),
20
+ );
20
21
  });
21
22
 
22
23
  it("skips when wall is not started", async () => {