@vnejs/plugins.scenario.autoread 0.1.11 → 0.1.12

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,7 +4,6 @@ import type { AutoreadPluginConstants, AutoreadPluginEvents, AutoreadPluginParam
4
4
  import type { SettingsChangedResult } from "@vnejs/module.core";
5
5
  export declare class Autoread extends ModuleCore<AutoreadPluginEvents, AutoreadPluginConstants, AutoreadPluginSettings, AutoreadPluginParams> {
6
6
  name: string;
7
- disableSources: string[];
8
7
  autoreadTimeout: ReturnType<typeof setTimeout> | undefined;
9
8
  subscribe: () => void;
10
9
  init: () => Promise<[unknown[] | undefined, unknown[] | undefined]>;
@@ -1,7 +1,7 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
+ import { SourcesSet } from "@vnejs/sources-set";
2
3
  export class Autoread extends ModuleCore {
3
4
  name = "autoread";
4
- disableSources = [];
5
5
  autoreadTimeout;
6
6
  subscribe = () => {
7
7
  this.on(this.EVENTS.AUTOREAD.TRY, this.onTry);
@@ -11,13 +11,16 @@ export class Autoread extends ModuleCore {
11
11
  this.on(this.EVENTS.STATE.CLEAR, this.clearTimeout);
12
12
  this.on(this.EVENTS.STATE.SET, this.onStateSet);
13
13
  };
14
- init = () => Promise.all([
15
- this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.AUTOREAD.ENABLED, value: this.PARAMS.AUTOREAD.DEFAULT_ENABLED }),
16
- this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.AUTOREAD.DELAY, value: this.PARAMS.AUTOREAD.DEFAULT_DELAY }),
17
- ]);
14
+ init = () => {
15
+ this.shared.autoreadDisableSources = new SourcesSet();
16
+ return Promise.all([
17
+ this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.AUTOREAD.ENABLED, value: this.PARAMS.AUTOREAD.DEFAULT_ENABLED }),
18
+ this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.AUTOREAD.DELAY, value: this.PARAMS.AUTOREAD.DEFAULT_DELAY }),
19
+ ]);
20
+ };
18
21
  onTry = async () => {
19
22
  this.emitLog({ action: "try" });
20
- if (!this.shared.settings[this.SETTINGS.AUTOREAD.ENABLED] || this.disableSources.length)
23
+ if (!this.shared.settings[this.SETTINGS.AUTOREAD.ENABLED] || this.shared.autoreadDisableSources.isNotEmpty())
21
24
  return;
22
25
  await this.waitRerender();
23
26
  const elements = document.elementsFromPoint(window.innerHeight / 2, window.innerHeight / 2);
@@ -30,17 +33,17 @@ export class Autoread extends ModuleCore {
30
33
  this.createTimeout();
31
34
  };
32
35
  onPush = ({ source = "" } = {}) => {
33
- this.disableSources.push(source);
36
+ this.shared.autoreadDisableSources.add(source);
34
37
  this.clearTimeout();
35
38
  };
36
39
  onPop = ({ source = "" } = {}) => {
37
- this.disableSources = this.disableSources.filter((s) => s !== source);
38
- if (!this.disableSources.length)
40
+ this.shared.autoreadDisableSources.rm(source);
41
+ if (this.shared.autoreadDisableSources.isEmpty())
39
42
  this.createTimeout();
40
43
  };
41
44
  onSettingsChanged = ({ name, value }) => name === this.SETTINGS.AUTOREAD.ENABLED && this.emit(value ? this.EVENTS.AUTOREAD.POP : this.EVENTS.AUTOREAD.PUSH, { source: this.name });
42
45
  onStateSet = () => {
43
- this.disableSources = [];
46
+ this.shared.autoreadDisableSources.clear();
44
47
  this.clearTimeout();
45
48
  this.createTimeout();
46
49
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.scenario.autoread",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -34,7 +34,8 @@
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@vnejs/module.core": "~0.1.0",
37
- "@vnejs/shared": "~0.1.0"
37
+ "@vnejs/shared": "~0.1.0",
38
+ "@vnejs/sources-set": "~0.1.0"
38
39
  },
39
40
  "devDependencies": {
40
41
  "@vnejs/configs.ts-common": "~0.1.0"
@@ -1,5 +1,6 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
2
  import type { AutoreadSourcePayload } from "@vnejs/contracts.scenario.autoread";
3
+ import { SourcesSet } from "@vnejs/sources-set";
3
4
 
4
5
  import type { AutoreadPluginConstants, AutoreadPluginEvents, AutoreadPluginParams, AutoreadPluginSettings } from "../types.js";
5
6
  import type { SettingsChangedResult } from "@vnejs/module.core";
@@ -7,7 +8,6 @@ import type { SettingsChangedResult } from "@vnejs/module.core";
7
8
  export class Autoread extends ModuleCore<AutoreadPluginEvents, AutoreadPluginConstants, AutoreadPluginSettings, AutoreadPluginParams> {
8
9
  name = "autoread";
9
10
 
10
- disableSources: string[] = [];
11
11
  autoreadTimeout: ReturnType<typeof setTimeout> | undefined;
12
12
 
13
13
  subscribe = () => {
@@ -21,16 +21,19 @@ export class Autoread extends ModuleCore<AutoreadPluginEvents, AutoreadPluginCon
21
21
  this.on(this.EVENTS.STATE.SET, this.onStateSet);
22
22
  };
23
23
 
24
- init = () =>
25
- Promise.all([
24
+ init = () => {
25
+ this.shared.autoreadDisableSources = new SourcesSet();
26
+
27
+ return Promise.all([
26
28
  this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.AUTOREAD.ENABLED, value: this.PARAMS.AUTOREAD.DEFAULT_ENABLED }),
27
29
  this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.AUTOREAD.DELAY, value: this.PARAMS.AUTOREAD.DEFAULT_DELAY }),
28
30
  ]);
31
+ };
29
32
 
30
33
  onTry = async () => {
31
34
  this.emitLog({ action: "try" });
32
35
 
33
- if (!this.shared.settings[this.SETTINGS.AUTOREAD.ENABLED] || this.disableSources.length) return;
36
+ if (!this.shared.settings[this.SETTINGS.AUTOREAD.ENABLED] || this.shared.autoreadDisableSources.isNotEmpty()) return;
34
37
 
35
38
  await this.waitRerender();
36
39
 
@@ -45,21 +48,21 @@ export class Autoread extends ModuleCore<AutoreadPluginEvents, AutoreadPluginCon
45
48
  };
46
49
 
47
50
  onPush = ({ source = "" }: AutoreadSourcePayload = {}) => {
48
- this.disableSources.push(source);
51
+ this.shared.autoreadDisableSources.add(source);
49
52
  this.clearTimeout();
50
53
  };
51
54
 
52
55
  onPop = ({ source = "" }: AutoreadSourcePayload = {}) => {
53
- this.disableSources = this.disableSources.filter((s) => s !== source);
56
+ this.shared.autoreadDisableSources.rm(source);
54
57
 
55
- if (!this.disableSources.length) this.createTimeout();
58
+ if (this.shared.autoreadDisableSources.isEmpty()) this.createTimeout();
56
59
  };
57
60
 
58
61
  onSettingsChanged = ({ name, value }: SettingsChangedResult) =>
59
62
  name === this.SETTINGS.AUTOREAD.ENABLED && this.emit(value ? this.EVENTS.AUTOREAD.POP : this.EVENTS.AUTOREAD.PUSH, { source: this.name });
60
63
 
61
64
  onStateSet = () => {
62
- this.disableSources = [];
65
+ this.shared.autoreadDisableSources.clear();
63
66
 
64
67
  this.clearTimeout();
65
68
  this.createTimeout();