From c2fa59d888b20df1e4cf40f864ef1e8c3ec24f43 Mon Sep 17 00:00:00 2001 From: Dmitry Samsonov Date: Fri, 20 Jul 2018 18:37:39 +0200 Subject: [PATCH] with-debounce-handler: invoke actual function from component props --- packages/debounce-handler/src/index.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/debounce-handler/src/index.js b/packages/debounce-handler/src/index.js index e4da6f3..8fa33e6 100644 --- a/packages/debounce-handler/src/index.js +++ b/packages/debounce-handler/src/index.js @@ -7,21 +7,25 @@ const debounceHandler = (handlerName, delay, leadingCall) => (Target) => { constructor (props, context) { super(props, context) - const debounced = debounce(props[handlerName], delay, leadingCall) + this.debouncedPropInvoke = debounce( + (...args) => this.props[handlerName](...args), + delay, + leadingCall + ) - this[handlerName] = (e, ...rest) => { + this.handler = (e, ...rest) => { if (e && typeof e.persist === 'function') { e.persist() } - - return debounced(e, ...rest) + + return this.debouncedPropInvoke(e, ...rest) } } - + render () { return createElement(Target, { ...this.props, - [handlerName]: this[handlerName] + [handlerName]: this.handler }) } }