[SYNC]
This commit is contained in:
@@ -63,8 +63,8 @@ class _AstromicFuturePresenterState<T> extends State<AstromicFuturePresenter<T>>
|
|||||||
//s1 --State
|
//s1 --State
|
||||||
//
|
//
|
||||||
//s1 --Controllers & Listeners
|
//s1 --Controllers & Listeners
|
||||||
widget.controller.getRefreshStream(widget.id).listen((_) {
|
widget.controller.getRefreshStream(widget.id).listen((uA) {
|
||||||
_refreshFuture(); // Force future recreation on refresh
|
_refreshFuture(updatedArgs: uA); // Force future recreation on refresh
|
||||||
});
|
});
|
||||||
//s1 --Controllers & Listeners
|
//s1 --Controllers & Listeners
|
||||||
//
|
//
|
||||||
@@ -121,17 +121,17 @@ class _AstromicFuturePresenterState<T> extends State<AstromicFuturePresenter<T>>
|
|||||||
}
|
}
|
||||||
|
|
||||||
//S1 -- Method to reinitialize or update `_future` with a new instance
|
//S1 -- Method to reinitialize or update `_future` with a new instance
|
||||||
void _refreshFuture() {
|
void _refreshFuture({Map<String,dynamic>? updatedArgs}) {
|
||||||
// Increment the refresh key to ensure a unique future instance
|
// Increment the refresh key to ensure a unique future instance
|
||||||
_refreshKey++;
|
_refreshKey++;
|
||||||
setState(() {
|
setState(() {
|
||||||
_initializeFuture();
|
_initializeFuture(updatedArgs: updatedArgs);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//S1 -- Method to reinitialize or update `_future` with a new instance
|
//S1 -- Method to reinitialize or update `_future` with a new instance
|
||||||
void _initializeFuture() {
|
void _initializeFuture({Map<String,dynamic>? updatedArgs}) {
|
||||||
widget.controller.setProvidedArguments(widget.neededArguments ?? <String,dynamic>{});
|
widget.controller.setProvidedArguments(updatedArgs ?? widget.neededArguments ?? <String,dynamic>{});
|
||||||
_future = widget.controller.getFuture(widget.id)?.then((dynamic result) => result as T?);
|
_future = widget.controller.getFuture(widget.id)?.then((dynamic result) => result as T?);
|
||||||
}
|
}
|
||||||
//!SECTION
|
//!SECTION
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import 'dart:async';
|
|||||||
class AstromicPresenterController {
|
class AstromicPresenterController {
|
||||||
late final Map<String, (Future Function(Map<String, dynamic> args)? fetch, int c)> _futures;
|
late final Map<String, (Future Function(Map<String, dynamic> args)? fetch, int c)> _futures;
|
||||||
late final Map<String, Stream Function(Map<String, dynamic> args)?> _streams;
|
late final Map<String, Stream Function(Map<String, dynamic> args)?> _streams;
|
||||||
late final Map<String, StreamController<void>> _futureRefreshers;
|
late final Map<String, StreamController<Map<String,dynamic>?>> _futureRefreshers;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ class AstromicPresenterController {
|
|||||||
Map<String, (Future Function(Map<String, dynamic> args)? fetch, int startCycle)> futures = const {},
|
Map<String, (Future Function(Map<String, dynamic> args)? fetch, int startCycle)> futures = const {},
|
||||||
Map<String, Stream Function(Map<String, dynamic> args)?> streams = const {},
|
Map<String, Stream Function(Map<String, dynamic> args)?> streams = const {},
|
||||||
}) : _futures = futures.map((k, v) => MapEntry(k, (v.$1, v.$2))),
|
}) : _futures = futures.map((k, v) => MapEntry(k, (v.$1, v.$2))),
|
||||||
_futureRefreshers = futures.map((k, v) => MapEntry(k, StreamController<void>.broadcast())),
|
_futureRefreshers = futures.map((k, v) => MapEntry(k, StreamController<Map<String,dynamic>?>.broadcast())),
|
||||||
_streams = streams;
|
_streams = streams;
|
||||||
|
|
||||||
Map<String,dynamic> providedArguments = {};
|
Map<String,dynamic> providedArguments = {};
|
||||||
@@ -46,7 +46,7 @@ class AstromicPresenterController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the refresh stream of a future using it's ID.
|
/// Get the refresh stream of a future using it's ID.
|
||||||
Stream<void> getRefreshStream<T>(String id) {
|
Stream<Map<String,dynamic>?> getRefreshStream<T>(String id) {
|
||||||
assert(_futures.containsKey(id), 'did you add a future with this id?');
|
assert(_futures.containsKey(id), 'did you add a future with this id?');
|
||||||
|
|
||||||
return _futureRefreshers[id]!.stream;
|
return _futureRefreshers[id]!.stream;
|
||||||
@@ -60,10 +60,10 @@ class AstromicPresenterController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Refresh a future using it's ID.
|
/// Refresh a future using it's ID.
|
||||||
void refreshFuture(String id) {
|
void refreshFuture(String id, {Map<String,dynamic>? updatedArgs}) {
|
||||||
assert(_futures.containsKey(id), 'did you add a future with this id?');
|
assert(_futures.containsKey(id), 'did you add a future with this id?');
|
||||||
|
|
||||||
_futureRefreshers[id]!.add(null);
|
_futureRefreshers[id]!.add(updatedArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dispose of a future using it's ID.
|
/// Dispose of a future using it's ID.
|
||||||
|
|||||||
Reference in New Issue
Block a user