Skip to content

Commit 83cc58c

Browse files
Merge pull request #27 from andrewvasilchuk/feature/typed-events
feat: type check events
2 parents 8ee46d5 + d77a1d0 commit 83cc58c

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"typescript": "^4.0.2",
7474
"vue": "^2.6.12",
7575
"vue-template-compiler": "^2.6.12",
76+
"vue-typed-emit": "^1.0.0",
7677
"vue-typed-refs": "^1.0.0"
7778
},
7879
"peerDependencies": {

src/VueLazyYoutubeVideo.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import Vue from 'vue'
22
import type { PropType, CreateElement, VNode } from 'vue'
3+
import type { WithEvents } from 'vue-typed-emit'
34
import type { WithRefs } from 'vue-typed-refs'
45

5-
import type {
6-
LoadIframeEventPayload,
7-
InitPlayerEventPayload,
8-
Refs,
9-
Thumbnail,
10-
} from './types'
6+
import type { Events, Refs, Thumbnail } from './types'
117
import { startsWith, isAspectRatio } from './helpers'
128
import {
139
DEFAULT_ALT_ATTRIBUTE,
@@ -22,7 +18,7 @@ import {
2218
} from './constants'
2319
import { Event } from './event'
2420

25-
export default (Vue as WithRefs<Refs>).extend({
21+
export default (Vue as WithRefs<Refs, WithEvents<Events>>).extend({
2622
name: 'VueLazyYoutubeVideo',
2723
props: {
2824
src: {
@@ -135,8 +131,7 @@ export default (Vue as WithRefs<Refs>).extend({
135131
return `${(b / a) * 100}%`
136132
},
137133
onIframeLoad() {
138-
const payload: LoadIframeEventPayload = { iframe: this.$refs.iframe }
139-
this.$emit(Event.LOAD_IFRAME, payload)
134+
this.$emit(Event.LOAD_IFRAME, { iframe: this.$refs.iframe })
140135

141136
if (this.enablejsapi) {
142137
try {
@@ -173,8 +168,7 @@ export default (Vue as WithRefs<Refs>).extend({
173168
'[vue-lazy-youtube-video]: YT.Player can not be instantiated without iframe element'
174169
)
175170
this.playerInstance = new YT.Player(iframe, this.playerOptions)
176-
const payload: InitPlayerEventPayload = { instance: this.playerInstance }
177-
this.$emit(Event.INIT_PLAYER, payload)
171+
this.$emit(Event.INIT_PLAYER, { instance: this.playerInstance })
178172
return this.playerInstance
179173
},
180174
getPlayerInstance() {

src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import type { Event } from './event'
2+
3+
export interface Events {
4+
[Event.LOAD_IFRAME]: LoadIframeEventPayload
5+
[Event.INIT_PLAYER]: InitPlayerEventPayload
6+
}
7+
18
export interface LoadIframeEventPayload {
29
iframe?: HTMLIFrameElement
310
}

0 commit comments

Comments
 (0)