Skip to content

Commit

Permalink
docs: simplify count example on readme
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoryConrad committed Jul 29, 2023
1 parent 1e7efea commit 1b187ac
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,13 @@ Define your "capsules" (en-_capsulated_ pieces of state) at the top level:
//
// This particular capsule manages a count from a classic example counter app,
// using the state side effect.
(int, void Function()) _countManagerCapsule(CapsuleHandle use) {
(int, void Function()) countCapsule(CapsuleHandle use) {
final (count, setCount) = use.state(0);
return (count, () => setCount(count + 1));
}
// This capsule provides the current count.
int countCapsule(CapsuleHandle use) => use(_countManagerCapsule).$1;
// This capsule provides a function that increments the count.
void Function() incrementCountCapsule(CapsuleHandle use) =>
use(_countManagerCapsule).$2;
// This capsule provides the current count, plus one.
int countPlusOneCapsule(CapsuleHandle use) => use(countCapsule) + 1;
int countPlusOneCapsule(CapsuleHandle use) => use(countCapsule).$1 + 1;
```

You can then use capsules in your widgets in the same fashion;
Expand Down

0 comments on commit 1b187ac

Please sign in to comment.