Skip to content

Commit

Permalink
Change duration to a positional argument for chaining methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyus committed Mar 2, 2024
1 parent 4ce61e9 commit 9356e92
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 35 deletions.
12 changes: 6 additions & 6 deletions packages/state_beacon_core/lib/src/extensions/chain.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ final beacon = Beacon.bufferedCount<T>(count).wrap(someBufferedBeacon)
/// expect(bufferedBeacon.value, equals([20]));
/// ```
/// See: `Beacon.bufferedTime` for more details.
BufferedTimeBeacon<T> bufferTime({
required Duration duration,
BufferedTimeBeacon<T> bufferTime(
Duration duration, {
String? name,
bool synchronous = true,
}) {
Expand Down Expand Up @@ -121,8 +121,8 @@ final beacon = Beacon.bufferedCount<T>(count).wrap(someBufferedBeacon)
/// ```
///
/// See: `Beacon.debounced` for more details.
DebouncedBeacon<T> debounce({
required Duration duration,
DebouncedBeacon<T> debounce(
Duration duration, {
String? name,
bool synchronous = true,
}) {
Expand Down Expand Up @@ -167,8 +167,8 @@ final beacon = Beacon.debounced<T>(0).wrap(someBufferedBeacon)
/// expect(throttledCount.value, equals(10)); // this is 10 because the update was throttled
/// ```
/// See: `Beacon.throttled` for more details.
ThrottledBeacon<T> throttle({
required Duration duration,
ThrottledBeacon<T> throttle(
Duration duration, {
bool dropBlocked = true,
bool synchronous = true,
String? name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void main() {
},
isLazy: true,
);
final buff = beacon.bufferTime(duration: k1ms);
final buff = beacon.bufferTime(k1ms);

expect(buff.value, isEmpty);

Expand Down Expand Up @@ -386,7 +386,7 @@ void main() {

final s = Beacon.streamRaw(() => getStream(count.value), isLazy: true);

final buffered = s.bufferTime(duration: k10ms * 10);
final buffered = s.bufferTime(k10ms * 10);

await delay(k1ms * 16); // only 0 and 1 in the first 16 ms

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void main() {
return controller.stream;
},
);
final buff = beacon.bufferTime(duration: k1ms);
final buff = beacon.bufferTime(k1ms);

expect(buff.value, isEmpty);

Expand Down
2 changes: 1 addition & 1 deletion packages/state_beacon_core/test/src/core_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ void main() {
await delay(k1ms);
expect(beacon.value.unwrap(), equals(0));

final buff = beacon.bufferTime(duration: k10ms);
final buff = beacon.bufferTime(k10ms);

count.set(1);

Expand Down
47 changes: 22 additions & 25 deletions packages/state_beacon_core/test/src/extensions/chain_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ void main() {
final beacon = Beacon.lazyWritable<int>();

final buffered = beacon.buffer(3);
final bufferedTime = beacon.bufferTime(duration: k10ms);
final debounced = beacon.debounce(duration: k10ms);
final throttled = beacon.throttle(duration: k10ms);
final bufferedTime = beacon.bufferTime(k10ms);
final debounced = beacon.debounce(k10ms);
final throttled = beacon.throttle(k10ms);
final filtered = beacon.filter(
(p0, p1) => p1.isEven,
);
Expand Down Expand Up @@ -70,7 +70,7 @@ void main() {
test('should return a BufferedTimeBeacon', () async {
final beacon = Beacon.writable(0);

final buffered = beacon.bufferTime(duration: k10ms);
final buffered = beacon.bufferTime(k10ms);

expect(buffered, isA<BufferedTimeBeacon<int>>());

Expand All @@ -92,7 +92,7 @@ void main() {
test('should return a DebouncedBeacon', () async {
final beacon = Beacon.writable(0);

final debounced = beacon.debounce(duration: k10ms);
final debounced = beacon.debounce(k10ms);

expect(debounced, isA<DebouncedBeacon<int>>());

Expand All @@ -113,7 +113,7 @@ void main() {
test('should return a ThrottledBeacon', () async {
final beacon = Beacon.writable(0);

final throttled = beacon.throttle(duration: k10ms);
final throttled = beacon.throttle(k10ms);

expect(throttled, isA<ThrottledBeacon<int>>());

Expand Down Expand Up @@ -153,8 +153,8 @@ void main() {

final beacon = count
.filter(neverFilter)
.throttle(duration: k10ms)
.debounce(duration: k10ms)
.throttle(k10ms)
.debounce(k10ms)
.filter(neverFilter);

Beacon.effect(() => beacon.value);
Expand Down Expand Up @@ -269,8 +269,8 @@ void main() {
final count = Beacon.writable<int>(10, name: 'count');

final filtered = count
.throttle(duration: k10ms, name: 'throttled')
.debounce(duration: k10ms, name: 'debounced')
.throttle(k10ms, name: 'throttled')
.debounce(k10ms, name: 'debounced')
.filter(neverFilter, name: 'f1')
.filter(neverFilter, name: 'f2');

Expand Down Expand Up @@ -367,22 +367,22 @@ void main() {
throwsA(isA<AssertionError>()),
);
expect(
() => buffered.debounce(duration: k1ms),
() => buffered.debounce(k1ms),
throwsA(isA<AssertionError>()),
);
expect(
() => buffered.throttle(duration: k1ms),
() => buffered.throttle(k1ms),
throwsA(isA<AssertionError>()),
);
expect(
() => buffered.bufferTime(duration: k1ms),
() => buffered.bufferTime(k1ms),
throwsA(isA<AssertionError>()),
);
expect(
() => count
.filter(name: 'f1', (_, n) => n > 5)
.buffer(2, name: 'buffered')
.debounce(duration: k10ms),
.debounce(k10ms),
throwsA(isA<AssertionError>()),
);
});
Expand All @@ -409,8 +409,7 @@ void main() {
test('should debounce input beacon', () async {
// BeaconObserver.instance = LoggingObserver();
final stream = Stream.periodic(k1ms, (i) => i).take(9);
final beacon =
stream.toRawBeacon(isLazy: true).debounce(duration: k10ms).buffer(5);
final beacon = stream.toRawBeacon(isLazy: true).debounce(k10ms).buffer(5);

BeaconScheduler.flush();

Expand All @@ -421,10 +420,8 @@ void main() {
test('should throttle input beacon', () async {
// BeaconObserver.instance = LoggingObserver();
final stream = Stream.periodic(k1ms, (i) => i).take(15);
final beacon = stream
.toRawBeacon(isLazy: true)
.throttle(duration: k10ms * 1.3)
.buffer(2);
final beacon =
stream.toRawBeacon(isLazy: true).throttle(k10ms * 1.3).buffer(2);

BeaconScheduler.flush();

Expand All @@ -440,7 +437,7 @@ void main() {
final stream = Stream.periodic(k1ms, (i) => i).take(15);
final beacon = stream
.toRawBeacon(isLazy: true)
.throttle(duration: k10ms, dropBlocked: false)
.throttle(k10ms, dropBlocked: false)
.buffer(2);

BeaconScheduler.flush();
Expand Down Expand Up @@ -500,7 +497,7 @@ void main() {
test('should force all delegated writes (throttled)', () async {
final count = Beacon.writable<int>(10, name: 'count');

final tbeacon = count.throttle(duration: k10ms, name: 'throttled');
final tbeacon = count.throttle(k10ms, name: 'throttled');

final buff = count.buffer(5, name: 'buff');

Expand All @@ -519,7 +516,7 @@ void main() {
test('should force all delegated writes (debounced)', () async {
final count = Beacon.writable<int>(10);

final tbeacon = count.debounce(duration: k10ms);
final tbeacon = count.debounce(k10ms);

final buff = count.buffer(5);

Expand Down Expand Up @@ -576,7 +573,7 @@ void main() {
test('should force all delegated writes (bufferedTime)', () async {
final count = Beacon.writable<int>(10);

final tbeacon = count.bufferTime(duration: k10ms);
final tbeacon = count.bufferTime(k10ms);

final buff = count.buffer(5);

Expand Down Expand Up @@ -615,7 +612,7 @@ void main() {
.toRawBeacon(isLazy: true)
.filter((_, n) => n.isEven)
.map((v) => v + 1)
.throttle(duration: k1ms);
.throttle(k1ms);

await expectLater(beacon.toStream(), emitsInOrder([1, 3, 5]));

Expand Down

0 comments on commit 9356e92

Please sign in to comment.