diff --git a/packages/state_beacon_core/lib/src/extensions/wrap_utils.dart b/packages/state_beacon_core/lib/src/extensions/wrap_utils.dart index 130e1976..ce25f8b4 100644 --- a/packages/state_beacon_core/lib/src/extensions/wrap_utils.dart +++ b/packages/state_beacon_core/lib/src/extensions/wrap_utils.dart @@ -8,17 +8,33 @@ extension ReadableBeaconWrapUtils on ReadableBeacon { int count, { String? name, }) { + assert( + this is! BufferedBaseBeacon, + ''' +Chaining of buffered beacons is not supported! +Buffered beacons has to be the last in the chain. + +Good: someBeacon.filter().buffer(10); + +Bad: someBeacon.buffer(10).filter(); + +If you absolutely need this functionality, it has to be done manually with "wrap". +eg: +final beacon = Beacon.bufferedCount(count).wrap(someBufferedBeacon) +''', + ); + final beacon = Beacon.bufferedCount( count, name: name, )..wrap( this, disposeTogether: true, - startNow: false, + startNow: !isEmpty, ); - if (!isEmpty) { - beacon.add(peek()); + if (this case final WritableBeacon w) { + beacon._delegate = w; } return beacon; @@ -30,17 +46,32 @@ extension ReadableBeaconWrapUtils on ReadableBeacon { required Duration duration, String? name, }) { + assert( + this is! BufferedBaseBeacon, + ''' +Chaining of buffered beacons is not supported! +Buffered beacons has to be the last in the chain. + +Good: someBeacon.filter().buffer(10); + +Bad: someBeacon.buffer(10).filter(); + +If you absolutely need this functionality, it has to be done manually with .wrap. +eg: +final beacon = Beacon.bufferedCount(count).wrap(someBufferedBeacon) +''', + ); final beacon = Beacon.bufferedTime( duration: duration, name: name, )..wrap( this, disposeTogether: true, - startNow: false, + startNow: !isEmpty, ); - if (!isEmpty) { - beacon.add(peek()); + if (this case final WritableBeacon w) { + beacon._delegate = w; } return beacon; @@ -55,7 +86,7 @@ extension ReadableBeaconWrapUtils on ReadableBeacon { /// final count = Beacon.writable(10); /// final debouncedCount = count.debounce(duration: k10ms); /// - /// debouncedCount.value = 20; + /// debouncedCount.value = 20; // equivalent to count.value = 20; /// /// expect(count.value, equals(20)); /// @@ -71,6 +102,21 @@ extension ReadableBeaconWrapUtils on ReadableBeacon { required Duration duration, String? name, }) { + assert( + this is! BufferedBaseBeacon, + ''' +Chaining of buffered beacons is not supported! +Buffered beacons has to be the last in the chain. + +Good: someBeacon.filter().buffer(10); + +Bad: someBeacon.buffer(10).filter(); + +If you absolutely need this functionality, it has to be done manually with .wrap. +eg: +final beacon = Beacon.debounced(0).wrap(someBufferedBeacon) +''', + ); final beacon = Beacon.lazyDebounced( duration: duration, name: name, @@ -97,7 +143,7 @@ extension ReadableBeaconWrapUtils on ReadableBeacon { /// final count = Beacon.writable(10); /// final throttledCount = count.throttle(duration: k10ms); /// - /// throttledCount.value = 20; + /// throttledCount.value = 20; // equivalent to count.value = 20; /// /// expect(count.value, equals(20)); /// expect(throttledCount.value, equals(10)); // this is 10 because the update was throttled @@ -108,6 +154,21 @@ extension ReadableBeaconWrapUtils on ReadableBeacon { bool dropBlocked = true, String? name, }) { + assert( + this is! BufferedBaseBeacon, + ''' +Chaining of buffered beacons is not supported! +Buffered beacons has to be the last in the chain. + +Good: someBeacon.filter().buffer(10); + +Bad: someBeacon.buffer(10).filter(); + +If you absolutely need this functionality, it has to be done manually with .wrap. +eg: +final beacon = Beacon.throttled(0).wrap(someBufferedBeacon) +''', + ); final beacon = Beacon.lazyThrottled( duration: duration, dropBlocked: dropBlocked, @@ -135,7 +196,7 @@ extension ReadableBeaconWrapUtils on ReadableBeacon { /// final count = Beacon.writable(10); /// final filteredCount = count.filter(filter: (prev, next) => next > 10); /// - /// filteredCount.value = 20; + /// filteredCount.value = 20; // equivalent to count.value = 20; /// /// expect(count.value, equals(20)); /// expect(filteredCount.value, equals(20)); @@ -145,6 +206,21 @@ extension ReadableBeaconWrapUtils on ReadableBeacon { bool Function(T?, T)? filter, String? name, }) { + assert( + this is! BufferedBaseBeacon, + ''' +Chaining of buffered beacons is not supported! +Buffered beacons has to be the last in the chain. + +Good: someBeacon.filter().buffer(10); + +Bad: someBeacon.buffer(10).filter(); + +If you absolutely need this functionality, it has to be done manually with .wrap. +eg: +final beacon = Beacon.filtered(0).wrap(someBufferedBeacon) +''', + ); final beacon = Beacon.lazyFiltered( filter: filter, name: name,