Skip to content

Commit

Permalink
Update deps, example (#16)
Browse files Browse the repository at this point in the history
* update deps

* update example

* update example

* update readme
  • Loading branch information
hoc081098 authored Jun 23, 2022
1 parent 6a2377f commit 23ee775
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 20 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Run example

on:
push:
branches: [ master ]
paths-ignore: [ '**.md' ]
pull_request:
branches: [ master ]
paths-ignore: [ '**.md' ]
workflow_dispatch:

jobs:
run-example:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./example
steps:
- uses: actions/checkout@v3

- name: Setup Dart
uses: dart-lang/[email protected]
with:
sdk: stable

- name: Print Dart version
run: dart --version

- name: Install dependencies
run: dart pub get

- name: Run lib/disposebag_example.dart
run: dart run lib/disposebag_example.dart
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![codecov](https://codecov.io/gh/hoc081098/disposebag/branch/master/graph/badge.svg)](https://codecov.io/gh/hoc081098/disposebag)
[![Build Status](https://travis-ci.org/hoc081098/disposebag.svg?branch=master)](https://travis-ci.org/hoc081098/disposebag)
[![GitHub](https://img.shields.io/github/license/hoc081098/disposebag?color=4EB1BA)](https://opensource.org/licenses/MIT)
[![Style](https://img.shields.io/badge/style-pedantic-40c4ff.svg)](https://github.com/dart-lang/pedantic)
[![Style](https://img.shields.io/badge/style-lints-40c4ff.svg)](https://pub.dev/packages/lints)

A package helps to cancel StreamSubscriptions and close Sinks.

Expand Down
17 changes: 14 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
include: package:pedantic/analysis_options.1.11.0.yaml
include: package:lints/recommended.yaml

analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false

linter:
rules:
- prefer_final_locals
- public_member_api_docs
- prefer_relative_imports
- prefer_final_locals
- prefer_relative_imports
# https://github.com/dart-lang/lints#migrating-from-packagepedantic
- always_declare_return_types
- prefer_single_quotes
- unawaited_futures
- unsafe_html
3 changes: 3 additions & 0 deletions disposebag.iml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<excludeFolder url="file://$MODULE_DIR$/flutter_disposebag/.idea" />
<excludeFolder url="file://$MODULE_DIR$/flutter_disposebag/.pub" />
<excludeFolder url="file://$MODULE_DIR$/flutter_disposebag/build" />
<excludeFolder url="file://$MODULE_DIR$/example/build" />
<excludeFolder url="file://$MODULE_DIR$/example/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:async';
import 'package:disposebag/disposebag.dart';

List<Object> get _disposables {
final controllers = <StreamController>[
final controllers = <StreamController<Object>>[
StreamController<int>()
..add(1)
..add(2),
Expand All @@ -29,13 +29,14 @@ List<Object> get _disposables {
}

void main() async {
DisposeBagConfigs.logger = disposeBagDefaultLogger;
final bag = DisposeBag(_disposables);

// add & addAll
await bag.add(Stream.value(1).listen(null));
await bag.addAll([
Stream.value(2).listen(null),
Stream.periodic(const Duration(seconds: 1)).listen(null),
Stream<void>.periodic(const Duration(seconds: 1)).listen(null),
]);

// disposedBy
Expand All @@ -44,20 +45,20 @@ void main() async {
await StreamController<int>.broadcast(sync: true).disposedBy(bag);

// await before clearing
await Future.delayed(const Duration(seconds: 1));
await Future<void>.delayed(const Duration(seconds: 1));
await bag.clear();
await bag.clear();
await bag.clear();

// adding after clearing
await Future.delayed(const Duration(seconds: 1));
await Future<void>.delayed(const Duration(seconds: 1));
await Stream.periodic(const Duration(milliseconds: 100), (i) => i)
.listen(print)
.disposedBy(bag);

// await before disposing
await Future.delayed(const Duration(seconds: 2));
await Future<void>.delayed(const Duration(seconds: 2));
await bag.dispose();
print("Bag disposed: ${bag.isDisposed}. It's all good");
await Future.delayed(const Duration(seconds: 2));
await Future<void>.delayed(const Duration(seconds: 2));
}
14 changes: 14 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: disposebag_example
description: disposebag_example
publish_to: none
version: 1.5.0

environment:
sdk: '>=2.12.0 <3.0.0'

dependencies:
disposebag: any

dependency_overrides:
disposebag:
path: ../../disposebag
3 changes: 2 additions & 1 deletion lib/src/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ enum BagResult {
typedef Logger = void Function(
DisposeBag bag,
BagResult result,
Set<dynamic> resources, [
Set<Object> resources, [
Object? error,
StackTrace? stackTrace,
]);

/// Default `DisposeBag` logger
// ignore: prefer_function_declarations_over_variables
final Logger disposeBagDefaultLogger =
(bag, result, resources, [error, stackTrace]) {
switch (result) {
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ environment:
sdk: '>=2.12.0 <3.0.0'

dependencies:
meta: ^1.3.0
meta: ^1.7.0
collection: ^1.15.0

dev_dependencies:
pedantic: ^1.11.0
lints: ^1.0.1
test: ^1.16.8
# mockito: ^3.0.0
14 changes: 7 additions & 7 deletions test/disposebag_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void main() {

group('DisposeBag.delete', () {
test('DisposeBag.delete', () async {
final subscription = Stream.empty().listen(null);
final subscription = Stream<Never>.empty().listen(null);
final controller = StreamController<int>()..stream.listen(null);
final bag = DisposeBag([subscription, controller]);

Expand All @@ -157,7 +157,7 @@ void main() {
});

test('DisposeBag.delete.isDisposed', () async {
final subscription = Stream.empty().listen(null);
final subscription = Stream<Never>.empty().listen(null);
final controller = StreamController<int>()..stream.listen(null);

final bag = DisposeBag([subscription, controller]);
Expand Down Expand Up @@ -198,7 +198,7 @@ void main() {
});

test('DisposeBag.remove.isDisposed', () async {
final subscription = Stream.empty().listen(null);
final subscription = Stream<Never>.empty().listen(null);
final controller = StreamController<int>()..stream.listen(null);

final bag = DisposeBag([subscription, controller]);
Expand Down Expand Up @@ -344,12 +344,12 @@ void main() {
Stream.value(3).listen((event) {}),
]);
expect(disposeBag.disposables.length, 3);
disposeBag.disposables.forEach(
(s) => expect(
for (final s in disposeBag.disposables) {
expect(
s,
const TypeMatcher<StreamSubscription<int>>(),
),
);
);
}
});

test('DisposeBag.isDisposed', () async {
Expand Down

0 comments on commit 23ee775

Please sign in to comment.