Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Commit

Permalink
with-debounce-handler: invoke actual function from component props
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Samsonov committed Jul 20, 2018
1 parent c78586c commit c2fa59d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/debounce-handler/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
}
Expand Down

0 comments on commit c2fa59d

Please sign in to comment.