@vnejs/plugins.feature.fastforward 0.1.0 → 0.1.2

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/events.js CHANGED
@@ -1,7 +1,12 @@
1
1
  export const SUBSCRIBE_EVENTS = {
2
2
  STOP: "vne:fastforward:stop",
3
3
  START: "vne:fastforward:start",
4
- CHECK: "vne:fastforward:check",
5
4
  TOGGLE: "vne:fastforward:toggle",
5
+
6
+ EMIT: "vne:fastforward:emit",
7
+ EMIT_CHECK: "vne:fastforward:emit_check",
8
+
9
+ CHECK: "vne:fastforward:check",
10
+
6
11
  CHANGED: "vne:fastforward:changed",
7
12
  };
@@ -0,0 +1,2 @@
1
+ export const DEFAULT_CHECK = true;
2
+ export const DEFAULT_DELAY = 50;
package/index.js CHANGED
@@ -2,8 +2,9 @@ import { regPlugin } from "@vnejs/shared";
2
2
 
3
3
  import { SUBSCRIBE_EVENTS } from "./const/events";
4
4
  import { SETTINGS_KEYS } from "./const/settings";
5
+ import * as params from "./const/params";
5
6
 
6
7
  import { Fastforward } from "./modules/fastforward";
7
8
  import { FastforwardVisits } from "./modules/visits";
8
9
 
9
- regPlugin("FASTFORWARD", { events: SUBSCRIBE_EVENTS, settings: SETTINGS_KEYS }, [Fastforward, FastforwardVisits]);
10
+ regPlugin("FASTFORWARD", { events: SUBSCRIBE_EVENTS, settings: SETTINGS_KEYS, params }, [Fastforward, FastforwardVisits]);
@@ -1,62 +1,62 @@
1
1
  import { Module } from "@vnejs/module";
2
2
 
3
- const skipNFrames = (n, cb) => (n > 0 ? requestAnimationFrame(() => skipNFrames(n - 1, cb)) : setImmediate(cb));
4
-
5
3
  export class Fastforward extends Module {
6
4
  name = "fastforward";
7
5
 
6
+ emitStop = () => this.emit(this.EVENTS.FASTFORWARD.STOP);
7
+ emitFastforwardEmit = () => this.emit(this.EVENTS.FASTFORWARD.EMIT);
8
+ emitFastforwardEmitCheck = () => this.emit(this.EVENTS.FASTFORWARD.CHECK);
9
+
8
10
  subscribe = () => {
9
11
  this.on(this.EVENTS.FASTFORWARD.START, this.onStart);
10
12
  this.on(this.EVENTS.FASTFORWARD.STOP, this.onStop);
11
13
  this.on(this.EVENTS.FASTFORWARD.TOGGLE, this.onToggle);
12
14
 
13
- this.on(this.EVENTS.INTERACT.ENDED, this.onInteractEnd);
15
+ this.on(this.EVENTS.FASTFORWARD.EMIT, this.onFastforwardEmit);
16
+ this.on(this.EVENTS.FASTFORWARD.EMIT_CHECK, this.onFastforwardEmitCheck);
14
17
 
15
- this.EVENTS.CHOOSE && this.on(this.EVENTS.CHOOSE.OPTION, this.onInteractEnd);
18
+ this.on(this.EVENTS.INTERACT.ENDED, this.emitFastforwardEmitCheck);
16
19
 
17
- this.on(this.EVENTS.STATE.CLEAR, this.onStop);
18
- this.on(this.EVENTS.SYSTEM.STARTED, this.onStop);
19
- };
20
+ this.EVENTS.CHOOSE && this.on(this.EVENTS.CHOOSE.OPTION, this.emitFastforwardEmitCheck);
20
21
 
21
- init = async ({ platform = this.CONST.PLATFORMS.WEB } = {}) => {
22
- await this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.FASTFORWARD.CHECK, value: true });
23
- await this.emit(this.EVENTS.SETTINGS.INIT, {
24
- name: this.SETTINGS.FASTFORWARD.DELAY,
25
- value: platform === this.CONST.PLATFORMS.WEB ? 10 : 1,
26
- });
22
+ this.on(this.EVENTS.SYSTEM.STARTED, this.emitStop);
23
+ this.on(this.EVENTS.STATE.CLEAR, this.emitStop);
27
24
  };
28
25
 
26
+ init = () =>
27
+ Promise.all([
28
+ this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.FASTFORWARD.CHECK, value: this.PARAMS.FASTFORWARD.DEFAULT_CHECK }),
29
+ this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.FASTFORWARD.DELAY, value: this.PARAMS.FASTFORWARD.DEFAULT_DELAY }),
30
+ ]);
31
+
29
32
  onToggle = () => this.setValue(!this.shared.isFastforwardOn);
30
33
  onStart = () => this.setValue(true);
31
34
  onStop = () => this.setValue(false);
32
- onInteractEnd = () =>
33
- this.shared.isFastforwardOn && skipNFrames(this.shared.settings[this.SETTINGS.FASTFORWARD.DELAY], this.interact);
35
+
36
+ onFastforwardEmit = async () => {
37
+ if (this.shared.settings[this.SETTINGS.FASTFORWARD.CHECK]) await this.checkVisited();
38
+ await this.emit(this.EVENTS.INTERACT.EMIT);
39
+ await this.emit(this.EVENTS.FASTFORWARD.EMIT_CHECK);
40
+ };
41
+ onFastforwardEmitCheck = () => this.shared.isFastforwardOn && setTimeout(this.emitFastforwardEmit, this.shared.settings[this.SETTINGS.FASTFORWARD.DELAY]);
34
42
 
35
43
  setValue = (value) => {
36
44
  this.shared.isFastforwardOn = value;
37
45
 
38
- if (value) this.shared.mediaNoTimeoutSources.push(this.name);
39
- else this.shared.mediaNoTimeoutSources = this.shared.mediaNoTimeoutSources.filter(this.notFastForward);
40
-
41
- if (value) this.shared.textNoAnimationSources.push(this.name);
42
- else this.shared.textNoAnimationSources = this.shared.textNoAnimationSources.filter(this.notFastForward);
43
-
44
- if (value) this.shared.viewForceAnimationSources.push(this.name);
45
- else this.shared.viewForceAnimationSources = this.shared.viewForceAnimationSources.filter(this.notFastForward);
46
+ if (value) {
47
+ this.shared.mediaNoTimeoutSources.push(this.name);
48
+ this.shared.textNoAnimationSources.push(this.name);
49
+ this.shared.viewForceAnimationSources.push(this.name);
50
+ } else {
51
+ this.shared.mediaNoTimeoutSources = this.shared.mediaNoTimeoutSources.filter(this.notFastForward);
52
+ this.shared.textNoAnimationSources = this.shared.textNoAnimationSources.filter(this.notFastForward);
53
+ this.shared.viewForceAnimationSources = this.shared.viewForceAnimationSources.filter(this.notFastForward);
54
+ }
46
55
 
47
56
  this.emit(this.EVENTS.FASTFORWARD.CHANGED, { value });
48
- value && this.interact();
49
- };
50
-
51
- checkVisited = async () => {
52
- const [isVisited] = await this.emit(this.EVENTS.FASTFORWARD.CHECK);
53
- !isVisited && this.setValue(false);
54
- };
55
57
 
56
- interact = async () => {
57
- if (this.shared.settings[this.SETTINGS.FASTFORWARD.CHECK]) await this.checkVisited();
58
- await this.emit(this.EVENTS.INTERACT.EMIT);
58
+ value && this.emitFastforwardEmit();
59
59
  };
60
-
60
+ checkVisited = async () => !(await this.emitOne(this.EVENTS.FASTFORWARD.CHECK)) && this.setValue(false);
61
61
  notFastForward = (s) => s !== this.name;
62
62
  }
package/modules/visits.js CHANGED
@@ -2,6 +2,7 @@ import { Module } from "@vnejs/module";
2
2
 
3
3
  export class FastforwardVisits extends Module {
4
4
  name = "fastforward.visits";
5
+
5
6
  visits = {};
6
7
 
7
8
  subscribe = () => {
@@ -33,11 +34,7 @@ export class FastforwardVisits extends Module {
33
34
 
34
35
  onVisitCheck = async () => Boolean(this.visits[await this.getHash()]);
35
36
 
36
- getHash = async () => {
37
- const [hash] = await this.emit(this.EVENTS.VENDORS.HASH, this.state);
38
-
39
- return hash;
40
- };
37
+ getHash = () => this.emitOne(this.EVENTS.VENDORS.HASH, this.state);
41
38
 
42
39
  getDefaultState = () => ({ text: "", label: "", speaker: "", meet: 0 });
43
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.feature.fastforward",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",