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

chore: deprecate refreshing #357

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions packages/signals_core/lib/src/async/future.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class FutureSignal<T> extends StreamSignal<T> {
}) : super(() => fn().asStream(), cancelOnError: true);

@override
@Deprecated("Use `reload` instead.")
Future<void> refresh() async {
await super.refresh();
await future;
Expand Down
1 change: 1 addition & 0 deletions packages/signals_core/lib/src/async/signal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ class AsyncSignal<T> extends Signal<AsyncState<T>>
}

/// Refresh the future
@Deprecated("Use `reload` instead.")
Future<void> refresh() async {
value = switch (value) {
AsyncData<T> data => AsyncDataRefreshing<T>(data.value),
Expand Down
10 changes: 10 additions & 0 deletions packages/signals_core/lib/src/async/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ sealed class AsyncState<T> {
}

/// Create a state with a value that is refreshing
@Deprecated("Use `AsyncState.dataReloading` instead.")
factory AsyncState.dataRefreshing(T data) {
return AsyncDataRefreshing<T>(data);
}
Expand All @@ -198,6 +199,7 @@ sealed class AsyncState<T> {
}

/// Create a state with an error that is refreshing
@Deprecated("Use `AsyncState.errorReloading` instead.")
factory AsyncState.errorRefreshing(Object error, [StackTrace? stackTrace]) {
return AsyncErrorRefreshing<T>(error, stackTrace ?? StackTrace.current);
}
Expand All @@ -223,6 +225,7 @@ sealed class AsyncState<T> {

/// Returns true if the state is refreshing with a loading flag,
/// has a value or error and is not the loading state
@Deprecated("Use `isReloading` instead.")
bool get isRefreshing;

/// Returns true if the state is reloading with having a value or error,
Expand Down Expand Up @@ -346,6 +349,7 @@ class AsyncDataReloading<T> extends AsyncData<T> implements AsyncLoading<T> {

/// A loading state with a value. Signals the query conditions that led to the data
/// has remained the same and is being refreshed
@Deprecated("Use `AsyncDataReloading` instead.")
class AsyncDataRefreshing<T> extends AsyncData<T> implements AsyncLoading<T> {
/// Create a state with a value that is refreshing
const AsyncDataRefreshing(super.data);
Expand All @@ -354,6 +358,7 @@ class AsyncDataRefreshing<T> extends AsyncData<T> implements AsyncLoading<T> {
bool get isLoading => true;

@override
@Deprecated("Use `isReloading` instead.")
bool get isRefreshing => true;

@override
Expand Down Expand Up @@ -381,6 +386,7 @@ class AsyncData<T> extends AsyncState<T> {
bool get isLoading => false;

@override
@Deprecated("Use `isReloading` instead.")
bool get isRefreshing => false;

@override
Expand Down Expand Up @@ -434,6 +440,7 @@ class AsyncErrorReloading<T> extends AsyncError<T> implements AsyncLoading<T> {

/// A loading state with an error. Signal the query conditions that led to the error
/// has remained the same and is being refreshed.
@Deprecated("Use `AsyncErrorReloading` instead.")
class AsyncErrorRefreshing<T> extends AsyncError<T> implements AsyncLoading<T> {
/// Create a state with an error that is refreshing
const AsyncErrorRefreshing(super.error, super.stackTrace);
Expand All @@ -442,6 +449,7 @@ class AsyncErrorRefreshing<T> extends AsyncError<T> implements AsyncLoading<T> {
bool get isLoading => true;

@override
@Deprecated("Use `isReloading` instead.")
bool get isRefreshing => true;

@override
Expand Down Expand Up @@ -471,6 +479,7 @@ class AsyncError<T> extends AsyncState<T> {
bool get isLoading => false;

@override
@Deprecated("Use `isReloading` instead.")
bool get isRefreshing => false;

@override
Expand Down Expand Up @@ -520,6 +529,7 @@ class AsyncLoading<T> extends AsyncState<T> {
bool get isLoading => true;

@override
@Deprecated("Use `isReloading` instead.")
bool get isRefreshing => false;

@override
Expand Down
1 change: 1 addition & 0 deletions packages/signals_core/lib/src/async/stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ class StreamSignal<T> extends AsyncSignal<T> {
}

@override
@Deprecated("Use `reload` instead.")
Future<void> refresh() async {
super.refresh();
_stream.recompute();
Expand Down
2 changes: 1 addition & 1 deletion packages/signals_core/test/async/state_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void main() {
expect(value, true);
});
});

group('pattern matching', () {
test('loading', () {
final s = AsyncState<int>.loading();
Expand Down