Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "FEDX-1991: allow a nullable to be managed" #201

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions w_common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
## [3.3.0](https://github.com/Workiva/w_common/compare/3.2.0...3.3.0)
- Allow a nullable to be managed via `Disposable.manageDisposable` and
`Disposable.manageAndReturnTypedDisposable`.

## [3.2.0](https://github.com/Workiva/w_common/compare/3.1.0...3.2.0)

- Adds JsonMap and JsonMapObject typedefs

## [3.1.0](https://github.com/Workiva/w_common/compare/3.0.0...3.1.0)

- Adds JsonMap and JsonMapObject typedefs
- Update SDK minimum to 2.19.0 to support the non-function
typedef language feature.
- Raised package versions to their first nullsafe version.
Expand Down
9 changes: 4 additions & 5 deletions w_common/lib/src/browser/disposable_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,16 @@ class Disposable implements disposable_common.Disposable {
onError: onError, onDone: onDone, cancelOnError: cancelOnError);

@override
T manageAndReturnTypedDisposable<T extends disposable_common.Disposable?>(
T disposable) {
return _disposable.manageAndReturnTypedDisposable<T>(disposable);
}
T manageAndReturnTypedDisposable<T extends disposable_common.Disposable>(
T disposable) =>
_disposable.manageAndReturnTypedDisposable(disposable);

@override
Completer<T> manageCompleter<T>(Completer<T> completer) =>
_disposable.manageCompleter(completer);

@override
void manageDisposable(disposable_common.Disposable? disposable) =>
void manageDisposable(disposable_common.Disposable disposable) =>
_disposable.manageDisposable(disposable);

@override
Expand Down
12 changes: 4 additions & 8 deletions w_common/lib/src/common/disposable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,8 @@ class Disposable implements _Disposable, DisposableManagerV7, LeakFlagger {

@mustCallSuper
@override
T manageAndReturnTypedDisposable<T extends Disposable?>(T disposable) {
if (disposable == null) {
return disposable;
}

_throwOnInvalidCall(
'manageAndReturnTyped Disposable', 'disposable', disposable);
T manageAndReturnTypedDisposable<T extends Disposable>(T disposable) {
_throwOnInvalidCall('manageAndReturnDisposable', 'disposable', disposable);
manageDisposable(disposable);

return disposable;
Expand Down Expand Up @@ -557,7 +552,8 @@ class Disposable implements _Disposable, DisposableManagerV7, LeakFlagger {
return completer;
}

void manageDisposable(Disposable? disposable) {
void manageDisposable(Disposable disposable) {
// ignore: unnecessary_null_comparison
if (disposable == null) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion w_common/lib/src/common/disposable_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ abstract class DisposableManagerV7 {
/// }
///
/// A null parameter will result in a null return value.
T manageAndReturnTypedDisposable<T extends Disposable?>(T disposable);
T manageAndReturnTypedDisposable<T extends Disposable>(T disposable);

/// Automatically cancel a stream controller when this object is disposed.
///
Expand Down
19 changes: 1 addition & 18 deletions w_common/test/unit/disposable_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,9 @@ void testCommonDisposable(Func<StubDisposable> disposableFactory) {
expect(disposable.injected!.isDisposed, isFalse);
});

test('should not throw if value is null', () async {
StubDisposable? nullable;
var returnValue;
expect(() {
returnValue = disposable
.manageAndReturnTypedDisposable<StubDisposable?>(nullable);
}, returnsNormally);
expect(returnValue, isNull);
});

testManageMethod(
'manageAndReturnTypedDisposable',
(StubDisposable? argument) =>
(StubDisposable argument) =>
disposable.manageAndReturnTypedDisposable(argument),
disposableFactory());
});
Expand Down Expand Up @@ -825,13 +815,6 @@ void testCommonDisposable(Func<StubDisposable> disposableFactory) {
});

group('manageDisposable', () {
test('should not throw if value is null', () async {
StubDisposable? nullable;
expect(() {
disposable.manageDisposable(nullable);
}, returnsNormally);
});

test('should dispose child when parent is disposed', () async {
var childThing = disposableFactory();
disposable.manageDisposable(childThing);
Expand Down
Loading