Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hoc081098/disposebag
:zap: A package to help disposing StreamSubscriptions and closing Sinks. :cyclone:
https://github.com/hoc081098/disposebag
bloc-pattern bloc-pattern-rxdart disposebag disposing-streams flutter-bloc flutter-bloc-pattern flutter-bloc-pattern-rxdart flutter-bloc-patterns flutter-bloc-rxdart flutter-reactive flutter-rx flutter-rxdart rxdart rxdart-bloc rxdart-epic rxdart-flutter rxdart-helper stream-dispose
Last synced: 23 days ago
JSON representation
:zap: A package to help disposing StreamSubscriptions and closing Sinks. :cyclone:
- Host: GitHub
- URL: https://github.com/hoc081098/disposebag
- Owner: hoc081098
- License: mit
- Created: 2019-07-23T15:44:38.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-06-13T10:31:23.000Z (5 months ago)
- Last Synced: 2024-06-13T13:22:43.179Z (5 months ago)
- Topics: bloc-pattern, bloc-pattern-rxdart, disposebag, disposing-streams, flutter-bloc, flutter-bloc-pattern, flutter-bloc-pattern-rxdart, flutter-bloc-patterns, flutter-bloc-rxdart, flutter-reactive, flutter-rx, flutter-rxdart, rxdart, rxdart-bloc, rxdart-epic, rxdart-flutter, rxdart-helper, stream-dispose
- Language: Dart
- Homepage: https://pub.dev/packages/disposebag
- Size: 114 KB
- Stars: 12
- Watchers: 1
- Forks: 2
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Authors: AUTHORS
Awesome Lists containing this project
README
# disposebag
## Author: [Petrus Nguyễn Thái Học](https://github.com/hoc081098)
[![Dart CI](https://github.com/hoc081098/disposebag/actions/workflows/dart.yml/badge.svg)](https://github.com/hoc081098/disposebag/actions/workflows/dart.yml)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/335930f9b71d4564b5523ccc788663f9)](https://app.codacy.com/manual/hoc081098/disposebag?utm_source=github.com&utm_medium=referral&utm_content=hoc081098/disposebag&utm_campaign=Badge_Grade_Dashboard)
[![Pub](https://img.shields.io/pub/v/disposebag)](https://pub.dev/packages/disposebag)
[![Pub](https://img.shields.io/pub/v/disposebag?include_prereleases)](https://pub.dev/packages/disposebag)
[![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-lints-40c4ff.svg)](https://pub.dev/packages/lints)A package helps to cancel StreamSubscriptions and close Sinks.
## Medium article
[How to easily cancel streams in Flutter](https://hoc081098.medium.com/how-to-easily-cancel-streams-in-dart-flutter-69cad1980267)
## Usage
A simple usage example:
```dart
import 'package:disposebag/disposebag.dart';
import 'dart:async';main() async {
final controllers = [];
final subscriptions = [];final bag = DisposeBag([...subscriptions, ...controllers]);
await Stream.value(3).listen(null).disposedBy(bag);
await StreamController.broadcast().disposedBy(bag);
await StreamController.broadcast(sync: true).disposedBy(bag);await bag.dispose();
print("Bag disposed. It's all good");
}
```### API
## 1. Add, addAll
```dart
Future DisposeBag.add(StreamSubscription);
Future DisposeBag.add(Sink);
Future DisposeBag.addAll(Iterable);
Future DisposeBag.addAll(Iterable);// extension methods
Future StreamSubscription.disposedBy(DisposeBag);
Future Sink.disposedBy(DisposeBag);
Future Iterable.disposedBy(DisposeBag);
Future Iterable.disposedBy(DisposeBag);
```## 2. Delete (removes but does not dispose)
```dart
bool delete(StreamSubscription);
bool delete(Sink);
```## 3. Remove (removes and disposes)
```dart
Future remove(StreamSubscription);
Future remove(Sink);
```## 4. Clear, dispose
```dart
Future clear();
Future dispose();
```## Features and bugs
Please file feature requests and bugs at the [issue tracker][tracker].
[tracker]: https://github.com/hoc081098/disposebag/issues/new