@vnejs/plugins.scenario.fastforward 0.1.15 → 0.1.17

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.
@@ -15,5 +15,4 @@ export declare class Fastforward extends ModuleCore<FastforwardPluginEvents, Fas
15
15
  onFastforwardEmit: () => Promise<void>;
16
16
  onFastforwardEmitCheck: () => number;
17
17
  setValue: (value: boolean) => void;
18
- notFastForward: (s: string) => boolean;
19
18
  }
@@ -32,17 +32,10 @@ export class Fastforward extends ModuleCore {
32
32
  onFastforwardEmitCheck = () => setTimeout(() => this.shared.isFastforwardOn && this.emit(this.EVENTS.FASTFORWARD.EMIT), this.shared.settings[this.SETTINGS.FASTFORWARD.DELAY]);
33
33
  setValue = (value) => {
34
34
  this.shared.isFastforwardOn = value;
35
- if (value) {
36
- this.shared.mediaNoTimeoutSources.push(this.name);
37
- this.shared.viewForceAnimationSources.push(this.name);
38
- }
39
- else {
40
- this.shared.mediaNoTimeoutSources = this.shared.mediaNoTimeoutSources.filter(this.notFastForward);
41
- this.shared.viewForceAnimationSources = this.shared.viewForceAnimationSources.filter(this.notFastForward);
42
- }
35
+ this.shared.mediaNoTimeoutSources.set(this.name, value);
36
+ this.shared.viewForceAnimationSources.set(this.name, value);
43
37
  this.emit(this.EVENTS.FASTFORWARD.CHANGED, { value });
44
38
  if (value)
45
39
  this.emit(this.EVENTS.FASTFORWARD.EMIT);
46
40
  };
47
- notFastForward = (s) => s !== this.name;
48
41
  }
@@ -5,7 +5,7 @@ import type { ModuleGlobalStateFastforwardVisits } from "@vnejs/contracts.scenar
5
5
  import type { FastforwardPluginConstants, FastforwardPluginEvents, FastforwardPluginParams, FastforwardPluginSettings } from "../types.js";
6
6
  export declare class FastforwardVisits extends ModuleCore<FastforwardPluginEvents, FastforwardPluginConstants, FastforwardPluginSettings, FastforwardPluginParams, ModuleGlobalStateFastforwardVisits> {
7
7
  name: string;
8
- visits: Record<string, number>;
8
+ visits: Set<string>;
9
9
  subscribe: () => void;
10
10
  init: () => Promise<void>;
11
11
  onExec: ({ module, block, line, args, keywords }?: ScenarioExecPayload) => Promise<void>;
@@ -1,8 +1,9 @@
1
1
  import "@vnejs/contracts.core.scenario";
2
2
  import { ModuleCore } from "@vnejs/module.core";
3
+ const STORAGE_VALUE = 1;
3
4
  export class FastforwardVisits extends ModuleCore {
4
5
  name = "fastforward.visits";
5
- visits = {};
6
+ visits = new Set();
6
7
  subscribe = () => {
7
8
  this.on(this.EVENTS.SCENARIO.EXEC, this.onExec);
8
9
  this.on(this.EVENTS.FASTFORWARD.CHECK, this.onVisitCheck);
@@ -12,19 +13,22 @@ export class FastforwardVisits extends ModuleCore {
12
13
  };
13
14
  init = async () => {
14
15
  await this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.FASTFORWARD.CHECK_VISITED, value: this.PARAMS.FASTFORWARD.DEFAULT_CHECK_VISITED });
15
- this.visits = (await this.emitOne(this.EVENTS.STORAGE.GET_ALL, { module: this.name }));
16
+ this.visits = new Set(Object.keys((await this.emitOne(this.EVENTS.STORAGE.GET_ALL, { module: this.name }))));
16
17
  };
17
18
  onExec = async ({ module, block, line, args = {}, keywords = [] } = {}) => {
18
19
  const key = (await this.emitOne(this.EVENTS.VENDORS.HASH, this.state));
19
- this.visits[key] = 1;
20
- this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key, value: 1 });
20
+ this.visits.add(key);
21
+ this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key, value: STORAGE_VALUE });
21
22
  this.setState({ module, block, line, args, keywords, label: this.globalState.scenario.label });
22
23
  };
23
24
  onVisitCheck = async () => {
24
- const isAllowed = !this.shared.settings[this.SETTINGS.FASTFORWARD.CHECK_VISITED] || Boolean(this.visits[(await this.getHash())]);
25
+ const isAllowed = !this.shared.settings[this.SETTINGS.FASTFORWARD.CHECK_VISITED] || this.visits.has((await this.getHash()));
25
26
  return { isAllowed, source: this.name };
26
27
  };
27
- onClear = () => this.emit(this.EVENTS.STORAGE.RM_ALL, { module: this.name });
28
+ onClear = () => {
29
+ this.visits.clear();
30
+ return this.emit(this.EVENTS.STORAGE.RM_ALL, { module: this.name });
31
+ };
28
32
  getHash = () => this.emitOne(this.EVENTS.VENDORS.HASH, this.state);
29
33
  getDefaultState = () => ({ label: "", args: {}, keywords: [] });
30
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.scenario.fastforward",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -51,18 +51,11 @@ export class Fastforward extends ModuleCore<FastforwardPluginEvents, Fastforward
51
51
  setValue = (value: boolean) => {
52
52
  this.shared.isFastforwardOn = value;
53
53
 
54
- if (value) {
55
- this.shared.mediaNoTimeoutSources.push(this.name);
56
- this.shared.viewForceAnimationSources.push(this.name);
57
- } else {
58
- this.shared.mediaNoTimeoutSources = this.shared.mediaNoTimeoutSources.filter(this.notFastForward);
59
- this.shared.viewForceAnimationSources = this.shared.viewForceAnimationSources.filter(this.notFastForward);
60
- }
54
+ this.shared.mediaNoTimeoutSources.set(this.name, value);
55
+ this.shared.viewForceAnimationSources.set(this.name, value);
61
56
 
62
57
  this.emit(this.EVENTS.FASTFORWARD.CHANGED, { value } satisfies FastforwardChangedPayload);
63
58
 
64
59
  if (value) this.emit(this.EVENTS.FASTFORWARD.EMIT);
65
60
  };
66
-
67
- notFastForward = (s: string) => s !== this.name;
68
61
  }
@@ -6,6 +6,8 @@ import type { FastforwardCheckResult, ModuleGlobalStateFastforwardVisits } from
6
6
 
7
7
  import type { FastforwardPluginConstants, FastforwardPluginEvents, FastforwardPluginParams, FastforwardPluginSettings } from "../types.js";
8
8
 
9
+ const STORAGE_VALUE = 1;
10
+
9
11
  export class FastforwardVisits extends ModuleCore<
10
12
  FastforwardPluginEvents,
11
13
  FastforwardPluginConstants,
@@ -15,7 +17,7 @@ export class FastforwardVisits extends ModuleCore<
15
17
  > {
16
18
  name = "fastforward.visits";
17
19
 
18
- visits: Record<string, number> = {};
20
+ visits = new Set<string>();
19
21
 
20
22
  subscribe = () => {
21
23
  this.on(this.EVENTS.SCENARIO.EXEC, this.onExec);
@@ -30,25 +32,29 @@ export class FastforwardVisits extends ModuleCore<
30
32
  init = async () => {
31
33
  await this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.FASTFORWARD.CHECK_VISITED, value: this.PARAMS.FASTFORWARD.DEFAULT_CHECK_VISITED });
32
34
 
33
- this.visits = (await this.emitOne(this.EVENTS.STORAGE.GET_ALL, { module: this.name })) as Record<string, number>;
35
+ this.visits = new Set(Object.keys((await this.emitOne(this.EVENTS.STORAGE.GET_ALL, { module: this.name })) as Record<string, number>));
34
36
  };
35
37
 
36
38
  onExec = async ({ module, block, line, args = {}, keywords = [] }: ScenarioExecPayload = {}) => {
37
39
  const key = (await this.emitOne(this.EVENTS.VENDORS.HASH, this.state)) as string;
38
40
 
39
- this.visits[key] = 1;
40
- this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key, value: 1 });
41
+ this.visits.add(key);
42
+ this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key, value: STORAGE_VALUE });
41
43
 
42
44
  this.setState({ module, block, line, args, keywords, label: this.globalState.scenario.label });
43
45
  };
44
46
 
45
47
  onVisitCheck = async () => {
46
- const isAllowed = !this.shared.settings[this.SETTINGS.FASTFORWARD.CHECK_VISITED] || Boolean(this.visits[(await this.getHash()) as string]);
48
+ const isAllowed = !this.shared.settings[this.SETTINGS.FASTFORWARD.CHECK_VISITED] || this.visits.has((await this.getHash()) as string);
47
49
 
48
50
  return { isAllowed, source: this.name } satisfies FastforwardCheckResult;
49
51
  };
50
52
 
51
- onClear = () => this.emit(this.EVENTS.STORAGE.RM_ALL, { module: this.name });
53
+ onClear = () => {
54
+ this.visits.clear();
55
+
56
+ return this.emit(this.EVENTS.STORAGE.RM_ALL, { module: this.name });
57
+ };
52
58
 
53
59
  getHash = () => this.emitOne(this.EVENTS.VENDORS.HASH, this.state);
54
60