This repository has been archived by the owner on Sep 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Support for throttleProp and debounceProp #168
Comments
Throttling and debouncing are good ideas, but what do you mean by throttling a specific prop? Either the whole component updates or not, right? |
Oh I think I see what you mean:
Is that right? |
@acdlite Yes. In my mind it will be something like this mapPropsStream(props$ =>
Observable.combineLatest(
props$
.pluck('throttledProps')
.distinctUntilChanged()
.throttle(900),
props$
.map(({ throttledProps, ...otherProps }) => otherProps)
.distinctUntilChanged(undefined, shallowEqual),
(throttledProps, otherProps) => ({ ...otherProps, throttledProps })
)
) but without Observable. |
I can implement them if they look good |
Sure! |
Closed
@wuct Maybe implement these with middleware and submit the PR to my |
@acdlite sure. I will find some time for it this week :) |
Hey guys, just implemented these two as a part of my HOCs collection – https://github.com/deepsweet/hocs |
With lodash import throttle from "lodash/throttle"
const throttleHandler = (
propName,
delay,
options = {
leading: true,
trailing: true
}
) => WrappedComponent =>
class extends React.PureComponent {
original = () => {
this.props[propName]()
}
originalThrottled = throttle(this.original, delay, options)
replace = {
[propName]: this.originalThrottled
}
render() {
return <WrappedComponent {...this.props} {...this.replace} />
}
} |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
throttleProp
Only update a prop at most once per every
wait
milliseconds.debounceProp
is similar. Might be useful when a prop is updated frequently. How do you think?The text was updated successfully, but these errors were encountered: