diff --git a/.npmignore b/.npmignore index 8b49b57f..27a69612 100644 --- a/.npmignore +++ b/.npmignore @@ -8,5 +8,6 @@ doc/ flow/ node_modules/ tool/ +bundle-size/ .babelrc .flowconfig diff --git a/__tests__/bugfix.js b/__tests__/bugfix.js new file mode 100644 index 00000000..f1c96b8c --- /dev/null +++ b/__tests__/bugfix.js @@ -0,0 +1,26 @@ +import Chimee from 'index'; +test('redudant event bind on video', () => { + const wrapper = document.createElement('div'); + const fn = jest.fn(); + const cfn = jest.fn(); + const wfn = jest.fn(); + const plugin = { + name: 'redudantEventBind', + events: { + click: fn, + c_click: cfn, + w_click: wfn + } + }; + Chimee.install(plugin); + const player = new Chimee({ + wrapper, + plugin: ['redudantEventBind'] + }); + player.__dispatcher.dom.videoElement.dispatchEvent(new Event('click')); + expect(fn).toHaveBeenCalledTimes(1); + player.__dispatcher.dom.container.dispatchEvent(new Event('click')); + expect(cfn).toHaveBeenCalledTimes(1); + player.__dispatcher.dom.wrapper.dispatchEvent(new Event('click')); + expect(wfn).toHaveBeenCalledTimes(1); +}); diff --git a/build/rollup.config.base.js b/build/rollup.config.base.js index dee34328..60965ec0 100644 --- a/build/rollup.config.base.js +++ b/build/rollup.config.base.js @@ -11,6 +11,7 @@ import babel from 'rollup-plugin-babel'; import resolve from 'rollup-plugin-node-resolve'; import commonjs from 'rollup-plugin-commonjs'; import replace from 'rollup-plugin-replace'; +import visualizer from 'rollup-plugin-visualizer'; const babelConfig = { common: { presets: [ @@ -83,6 +84,9 @@ export default function (mode) { commonjs(), replace({ 'process.env.PLAYER_VERSION': `'${version}'` + }), + visualizer({ + filename: `bundle-size/${mode}.html` }) ] }; diff --git a/bundle-size/common.html b/bundle-size/common.html new file mode 100644 index 00000000..4a334c30 --- /dev/null +++ b/bundle-size/common.html @@ -0,0 +1,152 @@ + + RollUp Visualizer + + +
+
+

RollUp Visualizer

+ +
+ +
+
+
+ + + \ No newline at end of file diff --git a/bundle-size/es.html b/bundle-size/es.html new file mode 100644 index 00000000..4a334c30 --- /dev/null +++ b/bundle-size/es.html @@ -0,0 +1,152 @@ + + RollUp Visualizer + + +
+
+

RollUp Visualizer

+ +
+ +
+
+
+ + + \ No newline at end of file diff --git a/bundle-size/iife.html b/bundle-size/iife.html new file mode 100644 index 00000000..8a235a4f --- /dev/null +++ b/bundle-size/iife.html @@ -0,0 +1,152 @@ + + RollUp Visualizer + + +
+
+

RollUp Visualizer

+ +
+ +
+
+
+ + + \ No newline at end of file diff --git a/bundle-size/min.html b/bundle-size/min.html new file mode 100644 index 00000000..2f300c04 --- /dev/null +++ b/bundle-size/min.html @@ -0,0 +1,152 @@ + + RollUp Visualizer + + +
+
+

RollUp Visualizer

+ +
+ +
+
+
+ + + \ No newline at end of file diff --git a/bundle-size/umd.html b/bundle-size/umd.html new file mode 100644 index 00000000..9890a494 --- /dev/null +++ b/bundle-size/umd.html @@ -0,0 +1,152 @@ + + RollUp Visualizer + + +
+
+

RollUp Visualizer

+ +
+ +
+
+
+ + + \ No newline at end of file diff --git a/demo/base/index.js b/demo/base/index.js index 4cca395f..756de4e0 100644 --- a/demo/base/index.js +++ b/demo/base/index.js @@ -33,6 +33,12 @@ }, c_contextmenu (evt) { console.log(evt); + }, + c_click (evt) { + console.warn(evt); + }, + click (evt) { + console.log(evt); } } }; diff --git a/package.json b/package.json index b74219db..f290038e 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "rollup-plugin-replace": "^1.1.1", "rollup-plugin-serve": "^0.4.0", "rollup-plugin-uglify": "^2.0.1", + "rollup-plugin-visualizer": "^0.3.1", "rollup-watch": "^4.3.1" }, "jest": { diff --git a/src/dispatcher/dom.js b/src/dispatcher/dom.js index d2951df2..a7271d0d 100644 --- a/src/dispatcher/dom.js +++ b/src/dispatcher/dom.js @@ -110,9 +110,12 @@ export default class Dom { */ this.installVideo(videoElement); domEvents.forEach(key => { - const fn = this._getEventHandler(key, {penetrate: true}); - this.videoDomEventHandlerList.push(fn); - addEvent(this.videoElement, key, fn); + const cfn = (...args) => this.__dispatcher.bus.triggerSync('c_' + key, ...args); + this.containerDomEventHandlerList.push(cfn); + addEvent(this.container, key, cfn); + const wfn = (...args) => this.__dispatcher.bus.triggerSync('w_' + key, ...args); + this.wrapperDomEventHandlerList.push(wfn); + addEvent(this.wrapper, key, wfn); }); this._bindFullScreen(); }