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

[Feat] Deletegate writes made to chained beacons to parents. #55

Closed jinyus closed 7 months ago

jinyus commented 7 months ago

Description

Before the PR chaining wasn't allowed:

final queryBeacon = Beacon.writable('')
                       .filter(filter: (prev,next) => next.length > 3)
                       .debounce(duration: k500ms);

This is because in the example above, queryBeacon would be a debounced beacon and setting its value would not pass the mutation to the writable, then to the filtered beacon to be processed. This PR does just that.

When a write is made to a chained beacon, the write is passed up to all its parents before it reaches to itself. This also means that the mutation might not reach it at all. For example:

queryBeacon.value = "a";

This code will pass up the mutation to the writable which then passes it to the filtered beacon, but the filtered beacon rejects strings with less than 3 characters so the value will be dropped and the update will never reach the debounced beacon. There is also no rollback support so the mutations made to the writable will persist. ie: the writeable's value is now a while the filtered and debounced beacons still has a value of an empty string.

codecov-commenter commented 7 months ago

Codecov Report

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

Comparison is base (bde8f95) 100.00% compared to head (423ddc4) 100.00%. Report is 49 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #55 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 33 33 Lines 850 929 +79 ========================================= + Hits 850 929 +79 ``` | [Flag](https://app.codecov.io/gh/jinyus/dart_beacon/pull/55/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/55/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.