jinyus / dart_beacon

A reactive primitive (signals) and state management library for dart and flutter
https://pub.dev/packages/state_beacon
28 stars 2 forks source link

Add synchronous option to wrap, buffer, bufferTime, debounce, throttle, filtered, and map methods #82

Closed jinyus closed 4 months ago

jinyus commented 4 months ago

Description

Wrapping was synchronous by default which also disabled auto-batching. This PR adds a the ability to customize this.

  test('should NOT autobatch when synchronous=true', () {
    final original = Beacon.writable(10);
    final wrapper = Beacon.writable(0);

    wrapper.wrap(original);
    expect(wrapper.value, 10);

    original.value = 20;
    expect(wrapper.value, 20);

    original.value = 30;
    expect(wrapper.value, 30);
  });

  test('should autobatch when synchronous=false', () async {
    final original = Beacon.writable(10);
    final wrapper = Beacon.writable(0);

    wrapper.wrap(original, synchronous: false);
    expect(wrapper.value, 0);
    await expectLater(wrapper.next(), completion(10));

    original.value = 20;
    original.value = 30;
    original.value = 40;
    original.value = 50;
    expect(wrapper.value, 10); // should not update immediately
    await expectLater(wrapper.next(), completion(50));
  });

Type of Change

codecov-commenter commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.00%. Comparing base (e5fc7bd) to head (fdfd87b). Report is 47 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #82 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 35 35 Lines 1016 1037 +21 ========================================= + Hits 1016 1037 +21 ``` | [Flag](https://app.codecov.io/gh/jinyus/dart_beacon/pull/82/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jinyus) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/jinyus/dart_beacon/pull/82/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jinyus) | `100.00% <100.00%> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jinyus#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.