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

feature - add event filter operators like system.ignoreEvent, system.debounceOn #84

Closed
2 tasks done
beeth0ven opened this issue Sep 11, 2021 · 0 comments
Closed
2 tasks done
Assignees
Labels
enhancement New feature or request

Comments

@beeth0ven
Copy link
Contributor

beeth0ven commented Sep 11, 2021

We are proposal to add event filter operators. these operators can prevent unnecessary event dispatching. Here is initial imaging of these operators, it may change before we implementing them, but we issued the demand first:

  • system.ignoreEvent - ignore candidate event when it met some condition
  • system.debounceOn - apply debounce logic to some events

system.ignoreEvent

Ignore candidate event when it met some condition.

Usage:

  futureSystem
    ...
    .ignoreEvent(
      when: (state, event) => event is TriggerLoadData && state.loading // ignore trigger if already loading
    ) 
    ...

Above code shown if the system is already in loading status, then upcoming TriggerLoadData event will be ignored.
This operator will intercept event if some condition is met based on current state and the candidate event.

system.debounceOn

Apply debounce logic to some events

Usage:

  searchSystem
    ...
    .on<UpdateKeyword>(
      reduce: (state, event) => state.copyWith(keyword: event.keyword)
    )
    .debounceOn<UpdateKeyword>(duration: const Duration(seconds: 1))
    ...

Above code shown if UpdateKeyword event is dispatched with high frequency (quick typing), system will intercept these events to reduce unnecessary dispatching, it will pass (not inercept) event if 1 seconds has passed without dispatch another UpdateKeyword event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant