Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobaraujo7 authored Jun 30, 2024
1 parent ff501d4 commit c309456
Showing 1 changed file with 1 addition and 51 deletions.
52 changes: 1 addition & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,58 +54,8 @@ void main() {
```

### AsyncValueSelector

Computes an asynchronous value based on a given scope.

```dart
import 'package:flutter/widgets.dart';
import 'package:value_notifier_selectors/value_notifier_selectors.dart';
import 'dart:async';
void main() async {
final valueNotifier = ValueNotifier<int>(1);
final selector = AsyncValueSelector<int>(0, (get) async => get(valueNotifier) + 1);
await selector.isReady;
print(selector.value); // Outputs: 2
valueNotifier.value = 2;
await Future.delayed(Duration(milliseconds: 300));
print(selector.value); // Outputs: 3
}
```

## Advance Usage

As classes `ValueSelectable` trabalham devirando valores de outros `ValueListenable`, mas isso
também pode ser feito por meio de ações utilizando o setter do `value` de um `ValueSelectable`.
Note que ao alterar esse `value` nada acontecerá se a função `set` não for implementada no construtor de uma das classes do `ValueSelectable`.

Com isso em mente poderemos fazer derivações utilizando ações de uma forma parecida com um `Reducer`:

```dart
final counterState = ValueNotifier<int>(0);
final selectorState = ValueSelector<int>(
(get) => get(counterState) + 1,
(action) {
if (action == 'INCREMENT') counterState.value++;
if (action == 'DECREMENT') counterState.value--;
},
);
// directly change
counterState.value = 1;
// indirectly change
selectorState.value = 'INCREMENT';
selectorState.value = 'DECREMENT';
```


## Contributing

Contributions are welcome! Please open an issue or submit a pull request.
Contributions are welcome! Please open an issue or submit a pull request.

0 comments on commit c309456

Please sign in to comment.