@vnejs/plugins.canvas.child.bg 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.
@@ -17,11 +17,13 @@ export class LayerBgChange extends ModuleCore {
17
17
  await this.emit(this.EVENTS.LAYER_BG.STATE_UPDATE, { id: realId, name, args: clonedArgs });
18
18
  if (!duration || this.shared.viewForceAnimationSources.isNotEmpty())
19
19
  return this.emitChildChange(layer, realId, 0, { ...changeArgs, transition: 0 });
20
+ const durationMs = Number(duration);
20
21
  const { resolve: skipResolve, promise: skipPromise } = createPromiseResolve();
22
+ await this.emitChildChange(layer, realId, 0, { transition: durationMs });
21
23
  return this.emit(this.EVENTS.INTERACT.PUSH_POP, {
22
24
  key: `${this.name}_${layer}_${name}`,
23
25
  skipHandler: () => void this.emit(this.EVENTS.LAYER.UPDATE_FORCE, { layer })?.then(skipResolve),
24
- handler: () => Promise.race([this.emitChildChange(layer, realId, Number(duration), { ...changeArgs, transition: duration }), skipPromise]),
26
+ handler: () => Promise.race([this.emitChildChange(layer, realId, durationMs, { ...changeArgs, transition: durationMs }), skipPromise]),
25
27
  });
26
28
  };
27
29
  getBgId = async (id, layer) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.canvas.child.bg",
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",
@@ -28,12 +28,15 @@ export class LayerBgChange extends ModuleCore<BgPluginEvents, BgPluginConstants,
28
28
 
29
29
  if (!duration || this.shared.viewForceAnimationSources.isNotEmpty()) return this.emitChildChange(layer, realId, 0, { ...changeArgs, transition: 0 });
30
30
 
31
+ const durationMs = Number(duration);
31
32
  const { resolve: skipResolve, promise: skipPromise } = createPromiseResolve();
32
33
 
34
+ await this.emitChildChange(layer, realId, 0, { transition: durationMs });
35
+
33
36
  return this.emit(this.EVENTS.INTERACT.PUSH_POP, {
34
37
  key: `${this.name}_${layer}_${name}`,
35
38
  skipHandler: () => void this.emit(this.EVENTS.LAYER.UPDATE_FORCE, { layer })?.then(skipResolve),
36
- handler: () => Promise.race([this.emitChildChange(layer, realId, Number(duration), { ...changeArgs, transition: duration }), skipPromise]),
39
+ handler: () => Promise.race([this.emitChildChange(layer, realId, durationMs, { ...changeArgs, transition: durationMs }), skipPromise]),
37
40
  });
38
41
  };
39
42
 
@@ -0,0 +1,51 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { SUBSCRIBE_EVENTS as INTERACT_EVENTS } from "@vnejs/contracts.core.interact";
4
+ import { spyEvent, stubEvent } from "@vnejs/test-utils";
5
+
6
+ import { LayerBgChange } from "../modules/change.js";
7
+ import { createBgTestModule, LAYER_EVENTS, registerBgPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
8
+
9
+ describe("LayerBgChange", () => {
10
+ beforeEach(() => {
11
+ registerBgPluginVne();
12
+ });
13
+
14
+ it("CHANGE without duration swaps src in one CHILD_CHANGE with transition 0", async () => {
15
+ const { observer } = createBgTestModule(LayerBgChange);
16
+ const childChange = spyEvent(observer, LAYER_EVENTS.CHILD_CHANGE);
17
+
18
+ await observer.emit(SUBSCRIBE_EVENTS.CHANGE, { id: "bg-1", name: "hero", layer: "bl" });
19
+
20
+ expect(childChange).toHaveBeenCalledOnce();
21
+ expect(childChange.mock.calls[0][0]).toMatchObject({
22
+ layer: "bl",
23
+ childId: "bg-1",
24
+ duration: 0,
25
+ props: { src: "hero.png", transition: 0 },
26
+ });
27
+ });
28
+
29
+ it("CHANGE with duration enables transition before swapping src", async () => {
30
+ const { observer } = createBgTestModule(LayerBgChange);
31
+ const childChange = spyEvent(observer, LAYER_EVENTS.CHILD_CHANGE);
32
+
33
+ stubEvent(observer, INTERACT_EVENTS.PUSH_POP, async ({ handler }: { handler?: () => unknown } = {}) => handler?.());
34
+
35
+ await observer.emit(SUBSCRIBE_EVENTS.CHANGE, { id: "bg-1", name: "hero", layer: "bl", duration: 300 });
36
+
37
+ expect(childChange).toHaveBeenCalledTimes(2);
38
+ expect(childChange.mock.calls[0][0]).toMatchObject({
39
+ layer: "bl",
40
+ childId: "bg-1",
41
+ duration: 0,
42
+ props: { transition: 300 },
43
+ });
44
+ expect(childChange.mock.calls[1][0]).toMatchObject({
45
+ layer: "bl",
46
+ childId: "bg-1",
47
+ duration: 300,
48
+ props: { src: "hero.png", transition: 300 },
49
+ });
50
+ });
51
+ });