@vnejs/compatibility.scenario.choose-with-scenario.history 0.2.2 → 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 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 CompatibilityScenarioChooseWithScenarioHistory extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
6
6
  name: string;
7
- init: () => Promise<import("@vnejs/shared").EmitResults<"vne:choose:option_before_reg">> | undefined;
7
+ subscribe: () => void;
8
8
  onChooseOptionBefore: () => undefined;
9
9
  }
package/dist/index.js CHANGED
@@ -5,7 +5,9 @@ import { regModule } from "@vnejs/shared";
5
5
  const HISTORY_CHOICE_LOC_KEY = "choice";
6
6
  export class CompatibilityScenarioChooseWithScenarioHistory extends ModuleCore {
7
7
  name = "compatibility.scenario.choose-with-scenario.history";
8
- init = () => this.emit(this.EVENTS.CHOOSE.OPTION_BEFORE_REG, { handler: this.onChooseOptionBefore });
8
+ subscribe = () => {
9
+ this.on(this.EVENTS.CHOOSE.OPTION_BEFORE, this.onChooseOptionBefore);
10
+ };
9
11
  onChooseOptionBefore = () => void this.emit(this.EVENTS.HISTORY.ADD, { locKey: HISTORY_CHOICE_LOC_KEY });
10
12
  }
11
13
  regModule(CompatibilityScenarioChooseWithScenarioHistory);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/compatibility.scenario.choose-with-scenario.history",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -11,7 +11,9 @@ const HISTORY_CHOICE_LOC_KEY = "choice";
11
11
  export class CompatibilityScenarioChooseWithScenarioHistory extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
12
12
  name = "compatibility.scenario.choose-with-scenario.history";
13
13
 
14
- init = () => this.emit(this.EVENTS.CHOOSE.OPTION_BEFORE_REG, { handler: this.onChooseOptionBefore });
14
+ subscribe = () => {
15
+ this.on(this.EVENTS.CHOOSE.OPTION_BEFORE, this.onChooseOptionBefore);
16
+ };
15
17
 
16
18
  onChooseOptionBefore = () => void this.emit(this.EVENTS.HISTORY.ADD, { locKey: HISTORY_CHOICE_LOC_KEY });
17
19
  }
@@ -8,25 +8,21 @@ import { CHOOSE_EVENTS, createCompatibilityTestModule, HISTORY_EVENTS, registerC
8
8
  describe("CompatibilityScenarioChooseWithScenarioHistory", () => {
9
9
  beforeEach(() => registerCompatibilityVne());
10
10
 
11
- it("init registers CHOOSE.OPTION_BEFORE handler", async () => {
11
+ it("subscribe registers CHOOSE.OPTION_BEFORE handler", () => {
12
12
  const { module, observer } = createCompatibilityTestModule(CompatibilityScenarioChooseWithScenarioHistory, { subscribe: false });
13
- const reg = spyEvent(observer, CHOOSE_EVENTS.OPTION_BEFORE_REG);
14
13
 
15
- await (module as CompatibilityScenarioChooseWithScenarioHistory).init();
14
+ (module as CompatibilityScenarioChooseWithScenarioHistory).subscribe();
16
15
 
17
- expect(reg).toHaveBeenCalledOnce();
18
- expect(reg.mock.calls[0]?.[0]?.handler).toEqual(expect.any(Function));
16
+ expect(observer.subscribers[CHOOSE_EVENTS.OPTION_BEFORE]?.flatMap((group) => group.subscribers)).toEqual(
17
+ expect.arrayContaining([expect.objectContaining({ func: (module as CompatibilityScenarioChooseWithScenarioHistory).onChooseOptionBefore })]),
18
+ );
19
19
  });
20
20
 
21
- it("registered handler emits HISTORY.ADD with locKey choice", async () => {
22
- const { module, observer } = createCompatibilityTestModule(CompatibilityScenarioChooseWithScenarioHistory, { subscribe: false });
23
- const reg = spyEvent(observer, CHOOSE_EVENTS.OPTION_BEFORE_REG);
21
+ it("CHOOSE.OPTION_BEFORE emits HISTORY.ADD with locKey choice", async () => {
22
+ const { observer } = createCompatibilityTestModule(CompatibilityScenarioChooseWithScenarioHistory);
24
23
  const add = spyEvent(observer, HISTORY_EVENTS.ADD);
25
24
 
26
- await (module as CompatibilityScenarioChooseWithScenarioHistory).init();
27
-
28
- const handler = reg.mock.calls[0]?.[0]?.handler as () => unknown;
29
- await handler();
25
+ await observer.emit(CHOOSE_EVENTS.OPTION_BEFORE);
30
26
 
31
27
  expect(add).toHaveBeenCalledOnce();
32
28
  expect(add.mock.calls[0]?.[0]).toMatchObject({ locKey: "choice" });