Skip to content

Commit

Permalink
VM restriction, avoid ciclick
Browse files Browse the repository at this point in the history
  • Loading branch information
JhonaCodes committed Nov 22, 2024
1 parent c3fa8d7 commit 5ed56c5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
31 changes: 31 additions & 0 deletions lib/src/implements/notifier_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ abstract class StateNotifierImpl<T> extends ChangeNotifier implements ValueListe
if (kFlutterMemoryAllocationsEnabled) {
ChangeNotifier.maybeDispatchObjectCreation(this);
}

}


Expand All @@ -71,6 +72,36 @@ abstract class StateNotifierImpl<T> extends ChangeNotifier implements ValueListe
_value = newState;
}

@protected
@override
String toString() => '${describeIdentity(this)}($value)';

@protected
@override
void addListener(VoidCallback listener) {
super.addListener(listener);
}


@protected
@override
void removeListener(VoidCallback listener) => super.removeListener(listener);


@protected
@override
void dispose() => super.dispose();


@immutable
@protected
@override
void notifyListeners() => super.notifyListeners();


@immutable
@protected
@override
bool get hasListeners => super.hasListeners;

}
5 changes: 3 additions & 2 deletions lib/src/viewmodel/async_viewmodel_impl.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import 'package:flutter/material.dart';
import 'package:reactive_notifier/src/handler/async_state.dart';
import 'package:reactive_notifier/src/implements/notifier_impl.dart';

/// Base ViewModel implementation for handling asynchronous operations with state management.
///
/// Provides a standardized way to handle loading, success, and error states for async data.
abstract class AsyncViewModelImpl<T> extends ChangeNotifier {
abstract class AsyncViewModelImpl<T> extends StateNotifierImpl<T> {
AsyncState<T> _state = AsyncState.initial();
AsyncState<T> get state => _state;
Object? get error => _state.error;
StackTrace? get stackTrace => _state.stackTrace;

AsyncViewModelImpl({bool loadOnInit = true}) {
AsyncViewModelImpl(super._value, {bool loadOnInit = true}) {
if (loadOnInit) {
reload();
}
Expand Down

0 comments on commit 5ed56c5

Please sign in to comment.