@vnejs/plugins.feature.fastforward 0.1.0 → 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/events.js +6 -1
- package/const/params.js +2 -0
- package/index.js +2 -1
- package/modules/fastforward.js +33 -34
- package/modules/visits.js +1 -0
- package/package.json +1 -1
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
|
};
|
package/const/params.js
ADDED
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]);
|
package/modules/fastforward.js
CHANGED
|
@@ -1,62 +1,61 @@
|
|
|
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.
|
|
15
|
+
this.on(this.EVENTS.FASTFORWARD.EMIT, this.onFastforwardEmit);
|
|
16
|
+
this.on(this.EVENTS.FASTFORWARD.EMIT_CHECK, this.onFastforwardEmitCheck);
|
|
14
17
|
|
|
15
|
-
this.
|
|
18
|
+
this.on(this.EVENTS.INTERACT.ENDED, this.emitFastforwardEmitCheck);
|
|
16
19
|
|
|
17
|
-
this.on(this.EVENTS.
|
|
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
|
-
|
|
22
|
-
|
|
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
|
-
|
|
33
|
-
|
|
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
|
+
};
|
|
40
|
+
onFastforwardEmitCheck = () => this.shared.isFastforwardOn && setTimeout(this.emitFastforwardEmit, this.shared.settings[this.SETTINGS.FASTFORWARD.DELAY]);
|
|
34
41
|
|
|
35
42
|
setValue = (value) => {
|
|
36
43
|
this.shared.isFastforwardOn = value;
|
|
37
44
|
|
|
38
|
-
if (value)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
else
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
if (value) {
|
|
46
|
+
this.shared.mediaNoTimeoutSources.push(this.name);
|
|
47
|
+
this.shared.textNoAnimationSources.push(this.name);
|
|
48
|
+
this.shared.viewForceAnimationSources.push(this.name);
|
|
49
|
+
} else {
|
|
50
|
+
this.shared.mediaNoTimeoutSources = this.shared.mediaNoTimeoutSources.filter(this.notFastForward);
|
|
51
|
+
this.shared.textNoAnimationSources = this.shared.textNoAnimationSources.filter(this.notFastForward);
|
|
52
|
+
this.shared.viewForceAnimationSources = this.shared.viewForceAnimationSources.filter(this.notFastForward);
|
|
53
|
+
}
|
|
46
54
|
|
|
47
55
|
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
56
|
|
|
56
|
-
|
|
57
|
-
if (this.shared.settings[this.SETTINGS.FASTFORWARD.CHECK]) await this.checkVisited();
|
|
58
|
-
await this.emit(this.EVENTS.INTERACT.EMIT);
|
|
57
|
+
value && this.emitFastforwardEmit();
|
|
59
58
|
};
|
|
60
|
-
|
|
59
|
+
checkVisited = async () => !(await this.emitOne(this.EVENTS.FASTFORWARD.CHECK)) && this.setValue(false);
|
|
61
60
|
notFastForward = (s) => s !== this.name;
|
|
62
61
|
}
|
package/modules/visits.js
CHANGED