Skip to content

Commit 78bb1f6

Browse files
authored
Merge pull request #25 from youngdo212/feature/ts-plugins
타입스크립트 적용: 플러그인
2 parents b2de18b + 5195588 commit 78bb1f6

33 files changed

+1013
-538
lines changed

jest.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
2+
preset: 'ts-jest/presets/js-with-babel',
23
moduleDirectories: ['node_modules', 'src'],
34
moduleNameMapper: {
45
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':

package-lock.json

+117
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"sass-loader": "^10.1.0",
5555
"style-loader": "^2.0.0",
5656
"terser-webpack-plugin": "^4.2.3",
57+
"ts-jest": "^26.4.4",
5758
"typescript": "^4.1.3",
5859
"webpack": "^4.44.2",
5960
"webpack-cli": "^4.2.0",

src/base/plugin/Plugin.test.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import config from '../../config/defaults';
44

55
it('core속성을 가진다', () => {
66
class TestPlugin extends Plugin {
7-
addEventListeners() {
7+
protected addEventListeners() {
88
// do nothing.
99
}
1010
}
@@ -17,7 +17,7 @@ it('core속성을 가진다', () => {
1717

1818
it('video속성을 가진다', () => {
1919
class TestPlugin extends Plugin {
20-
addEventListeners() {
20+
protected addEventListeners() {
2121
// do nothing.
2222
}
2323
}
@@ -30,7 +30,7 @@ it('video속성을 가진다', () => {
3030

3131
it('enabled 속성을 가지며 기본 값은 true이다', () => {
3232
class TestPlugin extends Plugin {
33-
addEventListeners() {
33+
protected addEventListeners() {
3434
// do nothing.
3535
}
3636
}
@@ -43,7 +43,7 @@ it('enabled 속성을 가지며 기본 값은 true이다', () => {
4343

4444
it('인스턴스를 생성하면 이벤트 리스너를 추가한다', () => {
4545
class MyPlugin extends Plugin {
46-
addEventListeners() {
46+
protected addEventListeners() {
4747
this.listenTo(this.core, eventName, this.handleEvent);
4848
}
4949
handleEvent() {
@@ -62,7 +62,7 @@ it('인스턴스를 생성하면 이벤트 리스너를 추가한다', () => {
6262

6363
it('disable을 통해 플러그인을 사용하지 못하게 만든다', () => {
6464
class MyPlugin extends Plugin {
65-
addEventListeners() {
65+
protected addEventListeners() {
6666
this.listenTo(this.core, eventName, this.handleEvent);
6767
}
6868
handleEvent() {
@@ -82,7 +82,7 @@ it('disable을 통해 플러그인을 사용하지 못하게 만든다', () => {
8282

8383
it('enable을 통해 플러그인을 다시 사용가능하게 만든다', () => {
8484
class MyPlugin extends Plugin {
85-
addEventListeners() {
85+
protected addEventListeners() {
8686
this.listenTo(this.core, eventName, this.handleEvent);
8787
}
8888
handleEvent() {
@@ -107,7 +107,7 @@ it('enable을 통해 플러그인을 다시 사용가능하게 만든다', () =>
107107

108108
it('플러그인을 파괴한다', () => {
109109
class MyPlugin extends Plugin {
110-
addEventListeners() {
110+
protected addEventListeners() {
111111
this.listenTo(this.core, eventName1, this.handleEvent);
112112
}
113113
handleEvent() {

src/base/plugin/Plugin.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ export default abstract class Plugin extends Events {
5555
* Core에 이벤트 리스너를 등록한다.
5656
* NOTE: disable/enable을 제대로 작동시키기 위해서 반드시 this.listenTo 메소드를 이용해 이벤트 리스너를 등록해야한다.
5757
*/
58-
abstract addEventListeners(): void;
58+
protected abstract addEventListeners(): void;
5959

6060
/**
6161
* 플러그인을 작동시킨다.
6262
* 이 함수는 disable 이후에 다시 플러그인을 작동시킬 때만 사용해야 한다.
6363
*/
64-
enable(): void {
64+
public enable(): void {
6565
if (this._enabled) return;
6666
this.addEventListeners();
6767
this._enabled = true;
@@ -70,15 +70,15 @@ export default abstract class Plugin extends Events {
7070
/**
7171
* 플러그인을 작동하지 않도록 한다.
7272
*/
73-
disable(): void {
73+
public disable(): void {
7474
this.stopListening();
7575
this._enabled = false;
7676
}
7777

7878
/**
7979
* 플러그인을 파괴하여 등록된 이벤트 리스너를 전부 제거한다.
8080
*/
81-
destroy(): Plugin {
81+
public destroy(): Plugin {
8282
this.off();
8383
this.stopListening();
8484
return this;

src/base/ui-plugin/UIPlugin.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ export default abstract class UIPlugin extends UIObject<'div'> {
2424
/**
2525
* 모든 UI 플러그인은 내부에서 core를 갖는다.
2626
*/
27-
get core(): Core {
27+
public get core(): Core {
2828
return this._core;
2929
}
3030

3131
/**
3232
* core를 통해서 video에 접근할 수 있다.
3333
*/
34-
get video(): Video {
34+
public get video(): Video {
3535
return this._core.video;
3636
}
3737

3838
/**
3939
* 플러그인 활성화 여부
4040
*/
41-
get enabled(): boolean {
41+
public get enabled(): boolean {
4242
return this._enabled;
4343
}
4444

@@ -56,13 +56,13 @@ export default abstract class UIPlugin extends UIObject<'div'> {
5656
* Core에 이벤트 리스너를 등록한다.
5757
* NOTE: disable/enable을 제대로 작동시키기 위해서 반드시 this.listenTo 메소드를 이용해 이벤트 리스너를 등록해야한다.
5858
*/
59-
abstract addEventListeners(): void;
59+
protected abstract addEventListeners(): void;
6060

6161
/**
6262
* 플러그인을 작동시킨다.
6363
* 이 함수는 disable 이후에 다시 플러그인을 작동시킬 때만 사용해야 한다.
6464
*/
65-
enable(): void {
65+
public enable(): void {
6666
if (this._enabled) return;
6767
this.addEventListeners();
6868
showElement(this.el);
@@ -72,7 +72,7 @@ export default abstract class UIPlugin extends UIObject<'div'> {
7272
/**
7373
* 플러그인을 작동하지 않도록 한다.
7474
*/
75-
disable(): void {
75+
public disable(): void {
7676
this.stopListening();
7777
hideElement(this.el);
7878
this._enabled = false;
@@ -83,7 +83,7 @@ export default abstract class UIPlugin extends UIObject<'div'> {
8383
*
8484
* @returns {UIPlugin}
8585
*/
86-
render(): UIPlugin {
86+
public render(): UIPlugin {
8787
return this;
8888
}
8989
}

src/components/html-video/HTMLVideo.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
/** @module components/html-video */
22

3-
import type { Attributes, Config, EventHandlerNameMap } from '../../types';
3+
import type {
4+
Attributes,
5+
Config,
6+
EventHandlerNameMap,
7+
VideoError,
8+
} from '../../types';
49
import './HTMLVideo.scss';
510
import Events from '../../base/events';
611
import Video from '../../base/video';
712
import mime from 'mime/lite';
813
import { canPlayVideoType } from '../../utils/element';
14+
import i18n from '../../utils/i18n';
915

1016
/**
1117
* HTML 비디오 엘리먼트를 나타내는 클래스
@@ -104,8 +110,11 @@ export default class HTMLVideo extends Video {
104110
/**
105111
* 비디오의 에러 이벤트를 발생시킨다
106112
*/
107-
onError(event: Event): void {
108-
this.emit(Events.VIDEO_ERROR, event);
113+
onError(): void {
114+
const error: VideoError = {
115+
message: i18n.get('notFoundVideo', this.config),
116+
};
117+
this.emit(Events.VIDEO_ERROR, error);
109118
}
110119

111120
/**

src/components/no-video/NoVideo.scss

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.better-player__no-video {
2+
display: block;
23
width: 100%;
34
height: 100%;
45
box-sizing: border-box;

src/components/no-video/NoVideo.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/** @module components/no-video */
22

3-
import type { Attributes, Config } from '../../types';
3+
import type { Attributes, Config, VideoError } from '../../types';
44
import './NoVideo.scss';
55
import Video from '../../base/video';
66
import { defer } from '../../utils/function';
77
import Events from '../../base/events';
8+
import i18n from '../../utils/i18n';
89

910
/**
1011
* 지원하지 않는 비디오 포맷을 리소스로 사용하거나 리소스를 아예 제공하지
@@ -29,8 +30,8 @@ export default class NoVideo extends Video {
2930
*/
3031
private throwError(): void {
3132
defer(() => {
32-
const error = {
33-
message: this.config.i18n.notSupportVideoFormat,
33+
const error: VideoError = {
34+
message: i18n.get('notSupportVideoFormat', this.config),
3435
};
3536
this.emit(Events.VIDEO_ERROR, error);
3637
});

0 commit comments

Comments
 (0)