Skip to content

Commit

Permalink
Improve README
Browse files Browse the repository at this point in the history
  • Loading branch information
mstniy committed Dec 17, 2023
1 parent 27f8c24 commit de0e1eb
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ First you define your state:

```
int? currentThreshold;
List<int> currentUnfilteredItems;
var currentUnfilteredItems = <int>[];
```

Followed by setting up listeners:
Expand All @@ -116,6 +116,7 @@ And your state computation logic:

```
void updateDB() {
if (currentThreshold == null) return ;
final filteredItems = currentUnfilteredItems.
filter((x) => x > currentThreshold).
toList();
Expand Down Expand Up @@ -196,7 +197,7 @@ final sum = Computed<int>.withPrev((prev) {
- A: Short answer is: you can't. The functions passed to Computed should be pure computations, free of side effects. If you are meaning to use an external value as part of the computation, see `.use`. If you want to react to a stream of external events, see `.react`. If you wish to produce external side effects, see `.listen` or `.as[Broadcast]Stream`.

- Q: Why am I getting `Computed expressions must be purely functional. Please use listeners for side effects.`
- A: On debug mode, Computed runs the given computations twice to make sure they behave identically. If this does not hold, it throws this assertion. Possible reasons include mutating and using a mutable value inside the computation or returning a type which does not implement deep comparisons, like `List` or `Set`.
- A: On debug mode, Computed runs the given computations twice and checks if both calls return the same value. If this does not hold, it throws this assertion. Possible reasons include mutating and using a mutable value inside the computation or returning a type which does not implement deep comparisons, like `List` or `Set`.

## <a name='Pitfalls'></a>Pitfalls

Expand Down

0 comments on commit de0e1eb

Please sign in to comment.