-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06830b8
commit f29a602
Showing
11 changed files
with
283 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# .github/workflows/publish.yml | ||
name: Publish to pub.dev | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v[0-9]+.[0-9]+.[0-9]+*' | ||
|
||
jobs: | ||
publish: | ||
permissions: | ||
id-token: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Flutter | ||
uses: subosito/flutter-action@v2 | ||
with: | ||
channel: stable | ||
|
||
- name: Install dependencies | ||
run: flutter pub get | ||
|
||
- name: Publish | ||
run: flutter pub publish --force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,5 @@ app.*.symbols | |
# Obfuscation related | ||
app.*.map.json | ||
|
||
coverage/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# 1.1.0 | ||
|
||
- ADD: Set callback for ValueSelectable classes; | ||
|
||
# 1.0.0+2 | ||
|
||
- First Version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
part of '../value_selectable.dart'; | ||
|
||
/// A selector that computes an asynchronous value based on a given scope. | ||
class AsyncValueSelector<T> extends ValueSelectable<T> { | ||
final FutureOr<T> Function(GetValue get) scope; | ||
final FutureOr<void> Function(dynamic action)? _set; | ||
|
||
final Queue<FutureOr Function()> _requestQueue = Queue(); | ||
bool _isProcessing = false; | ||
bool _isInitialized = false; | ||
|
||
late final _get = GetValue._(notifyListeners); | ||
final _readyCompleter = Completer<bool>(); | ||
|
||
/// Future that completes when the selector is ready. | ||
Future<bool> get isReady { | ||
_initialize(); | ||
return _readyCompleter.future; | ||
} | ||
|
||
late T _value; | ||
|
||
void _initialize() { | ||
if (!_isInitialized) { | ||
_isInitialized = true; | ||
_requestQueue.add(_initializeSelector); | ||
_processQueue(); | ||
} | ||
} | ||
|
||
@override | ||
T get value { | ||
_initialize(); | ||
return _value; | ||
} | ||
|
||
set value(dynamic newValue) { | ||
_initialize(); | ||
_requestQueue.add(() => _set?.call(newValue)); | ||
_processQueue(); | ||
} | ||
|
||
/// Constructs an AsyncValueSelector with an initial value and a scope function. | ||
AsyncValueSelector(this._value, this.scope, [this._set]); | ||
|
||
/// Processes the request queue, ensuring only one request is processed at a time. | ||
Future<void> _processQueue() async { | ||
if (_isProcessing || _requestQueue.isEmpty) return; | ||
|
||
_isProcessing = true; | ||
try { | ||
while (_requestQueue.isNotEmpty) { | ||
final request = _requestQueue.removeFirst(); | ||
await request(); | ||
} | ||
} catch (e) { | ||
rethrow; | ||
} finally { | ||
_isProcessing = false; | ||
} | ||
} | ||
|
||
@override | ||
void notifyListeners() { | ||
_requestQueue.add(() async { | ||
_value = await scope(_get); | ||
if (_get._isDisposed) return; | ||
super.notifyListeners(); | ||
}); | ||
_processQueue(); | ||
} | ||
|
||
/// Initializes the selector by computing the initial value. | ||
Future<void> _initializeSelector() async { | ||
_value = await scope(_get); | ||
super.notifyListeners(); | ||
_get._tracking = false; | ||
_readyCompleter.complete(true); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_get.dispose(); | ||
super.dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
part of '../value_selectable.dart'; | ||
|
||
/// A selector that computes a synchronous value based on a given scope. | ||
class ValueSelector<T> extends ValueSelectable<T> { | ||
final T Function(GetValue get) scope; | ||
final FutureOr<void> Function(dynamic action)? _set; | ||
late T _value; | ||
|
||
@override | ||
T get value => _value; | ||
|
||
set value(dynamic newValue) => _set?.call(newValue); | ||
|
||
late final _get = GetValue._(notifyListeners); | ||
|
||
/// Constructs a ValueSelector with an initial value and a scope function. | ||
ValueSelector(this.scope, [this._set]) { | ||
_value = scope(_get); | ||
_get._tracking = false; | ||
} | ||
|
||
@override | ||
void notifyListeners() { | ||
_value = scope(_get); | ||
super.notifyListeners(); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_get.dispose(); | ||
super.dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.