@vnejs/plugins.scenario.pause 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/const/const.js ADDED
@@ -0,0 +1 @@
1
+ export const LINE_REG = /^(?<time>\d+)?$/;
@@ -0,0 +1,4 @@
1
+ export const SUBSCRIBE_EVENTS = {
2
+ START: "vne:pause:start",
3
+ END: "vne:pause:end",
4
+ };
File without changes
package/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import { regPlugin } from "@vnejs/shared";
2
+
3
+ import * as constants from "./const/const";
4
+ import { SUBSCRIBE_EVENTS } from "./const/events";
5
+
6
+ import { Pause } from "./modules/pause";
7
+
8
+ regPlugin("PAUSE", { constants, events: SUBSCRIBE_EVENTS }, [Pause]);
@@ -0,0 +1,51 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ export class Pause extends Module {
4
+ name = "pause";
5
+
6
+ pauseTimeout = null;
7
+ pauseResolve = null;
8
+
9
+ emitPauseEnd = () => this.emit(this.EVENTS.PAUSE.END);
10
+
11
+ subscribe = () => {
12
+ this.on(this.EVENTS.PAUSE.START, this.onPauseStart);
13
+ this.on(this.EVENTS.PAUSE.END, this.onPauseEnd);
14
+
15
+ this.on(this.EVENTS.STATE.CLEAR, this.onPauseEnd);
16
+ };
17
+
18
+ init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.execHandler });
19
+
20
+ execHandler = (line, args) => {
21
+ const { time } = line.match(this.CONST.PAUSE.LINE_REG).groups;
22
+
23
+ return this.emit(this.EVENTS.PAUSE.START, time ? { time: Number(time), ...args } : args);
24
+ };
25
+
26
+ onPauseStart = async ({ time } = {}) => {
27
+ this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { action: "start", time } });
28
+
29
+ if (!this.shared.isFastforwardOn) await new Promise(this.createPromiseFunc(time));
30
+
31
+ this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
32
+ };
33
+ onPauseEnd = async () => {
34
+ this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { action: "end" } });
35
+
36
+ clearTimeout(this.pauseTimeout);
37
+
38
+ await this.emit(this.EVENTS.INTERACT.POP, { key: this.name });
39
+
40
+ typeof this.pauseResolve === "function" && this.pauseResolve();
41
+ this.pauseResolve = null;
42
+ };
43
+
44
+ createPromiseFunc = (time) => async (resolve) => {
45
+ this.pauseResolve = resolve;
46
+
47
+ await this.emit(this.EVENTS.INTERACT.PUSH, { key: this.name, handler: this.emitPauseEnd });
48
+
49
+ if (time) this.pauseTimeout = setTimeout(this.onPauseEnd, time);
50
+ };
51
+ }
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@vnejs/plugins.scenario.pause",
3
+ "version": "0.1.1",
4
+ "main": "index.js",
5
+ "scripts": {
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",
10
+ "publish:major": "npm version major && npm publish --access public",
11
+ "publish:minor": "npm version minor && npm publish --access public",
12
+ "publish:patch": "npm version patch && npm publish --access public"
13
+ },
14
+ "author": "",
15
+ "license": "ISC",
16
+ "description": ""
17
+ }