Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully refactored throttle method (object form arguments, pass latest value, supports target) #31

Merged
merged 11 commits into from
Jun 13, 2020

Conversation

sergeysova
Copy link
Member

@sergeysova sergeysova commented Jun 13, 2020

BREAKING CHANGE: unnamed arguments removed, supports only object form, pass payload from the latest source trigger

closes #25

const throttled = throttle({ source: unit, timeout: 200 })

throttled.watch(payload => console.log("triggered", payload))

unit(1)
unit(2)
unit(3)

// after 200ms
// => triggered 1
throttle({
  source, timeout: 200, target
})

BREAKING CHANGE: unnamed arguments removed, supports only object form

closes #25
@sergeysova sergeysova added feature New functionality BREAKING CHANGES Some features changes without backward compatibility and removed feature New functionality labels Jun 13, 2020
@sergeysova sergeysova self-assigned this Jun 13, 2020
@sergeysova sergeysova marked this pull request as draft June 13, 2020 15:12
babel plugin passes sid, loc and name to specific config as argument
@sergeysova sergeysova marked this pull request as ready for review June 13, 2020 15:30
throttle/readme.md Outdated Show resolved Hide resolved
throttle/readme.md Outdated Show resolved Hide resolved
throttle/readme.md Outdated Show resolved Hide resolved
throttle/readme.md Outdated Show resolved Hide resolved
@victordidenko
Copy link
Contributor

Suggestion: throttle should accept and return target, e.g. like guard

const throttled = throttle({ source: unit, timeout: 200 })

// or

const throttled = createEvent()
throttle({
  source: unit,
  timeout: 200,
  target: throttled
})

@victordidenko
Copy link
Contributor

victordidenko commented Jun 13, 2020

Also, I don't like that throttled unit triggered with first throttled argument

const trigger = createEvent()
const throttled = throttle({ source: trigger, timeout: 40 })

trigger(0)
trigger(1)
trigger(2)

throttled will be triggered with 0. I think correct behaviour is when throttled should be triggered with 2.

For example, see lodash's throttle documentation:

The func is invoked with the last arguments provided to the throttled function.

UPD: following next comment, with leading and trailing edges true by default, throttled should be triggered twice, immediately with 0, and after 40ms with 2

@victordidenko
Copy link
Contributor

Also, it would be cool to have options for leading and trailing edges :)
Leading edge should be true by default, so

const trigger = createEvent()
const throttled = throttle({ source: trigger, timeout: 40 })
trigger(0)

throttled should be triggered immediately, not after 40ms. And just once, of course.

sergeysova and others added 2 commits June 13, 2020 23:27
@effector effector deleted a comment Jun 13, 2020
@effector effector deleted a comment Jun 13, 2020
BREAKING CHANGE: now payload sent from last source trigger
@ghost
Copy link

ghost commented Jun 13, 2020

DeepCode failed to analyze this pull request

Something went wrong despite trying multiple times, sorry about that.
Please comment this pull request with "Retry DeepCode" to manually retry, or contact us so that a human can look into the issue.

@sergeysova sergeysova merged commit de4c088 into master Jun 13, 2020
@sergeysova sergeysova deleted the chore/25-migrate-throttle branch June 13, 2020 21:14
@sergeysova sergeysova changed the title throttle method refactored, now supports only with object form Fully refactored throttle method (object form arguments, pass latest value, supports target) Jun 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BREAKING CHANGES Some features changes without backward compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate from effector-throttle
2 participants