From 9b42c5ff5257f107506020b182722ff506cc25da Mon Sep 17 00:00:00 2001 From: James Hall Date: Sat, 6 Aug 2016 10:17:09 +0100 Subject: [PATCH] Fix mapXDispatch and allow plugin to access onWheel (credit: lkzhao) (#578) * Fix mapXDispatch && allow plugin to access onWheel see https://github.com/zeit/hyperterm/pull/563 --- lib/components/term.js | 5 ++++- lib/utils/plugins.js | 23 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/components/term.js b/lib/components/term.js index ea57b4b0..b259f0fb 100644 --- a/lib/components/term.js +++ b/lib/components/term.js @@ -65,7 +65,10 @@ export default class Term extends Component { iframeWindow.addEventListener('wheel', this.onWheel); } - onWheel () { + onWheel (e) { + if (this.props.onWheel) { + this.props.onWheel(e); + } this.term.prefs_.set('scrollbar-visible', true); clearTimeout(this.scrollbarsHideTimer); if (!this.scrollMouseEnter) { diff --git a/lib/utils/plugins.js b/lib/utils/plugins.js index da178f54..c38aecde 100644 --- a/lib/utils/plugins.js +++ b/lib/utils/plugins.js @@ -266,7 +266,28 @@ export function connect (stateFn, dispatchFn, c, d = {}) { }); return ret; }, - dispatchFn, + function (dispatch) { + let ret = dispatchFn(dispatch); + connectors[name].dispatch.forEach((fn) => { + let ret_; + + try { + ret_ = fn(dispatch, ret); + } catch (err) { + console.error(err.stack); + notify('Plugin error', `${fn._pluginName}: Error occurred in \`map${name}Dispatch\`. Check Developer Tools for details.`); + return; + } + + if (!ret_ || 'object' !== typeof ret_) { + notify('Plugin error', `${fn._pluginName}: Invalid return value of \`map${name}Dispatch\` (object expected).`); + return; + } + + ret = ret_; + }); + return ret; + }, c, d )(decorate(Class, name));