Skip to content

Commit

Permalink
[docs] obs(), toggle() (#1027)
Browse files Browse the repository at this point in the history
* builder_with_child docs

* .obs and .toggle docs

* typo

* Revert "builder_with_child docs"

This reverts commit 8075dc8.

---------

Co-authored-by: Sergey Molchanovsky <[email protected]>
  • Loading branch information
subzero911 and Sergey Molchanovsky authored Nov 25, 2024
1 parent 9ae8461 commit c5ab5ca
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/docs/api/observable.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@ abstract class _Todo with Store {
}
```

:::info Reactive Extensions

You can convert plain `int`, 'double', `bool`, and `String` literals into
an observable version with the `.obs()` extension method. For example:

```dart
var name = ''.obs(); // infers ObservableString
var counter = 0.obs(); // infers ObservableInt
```

You can toggle an internal value of `Observable<bool>` with `.toggle()`:

```dart
var lights = true.obs();
lights.toggle(); // now lights.value is false
```

:::

## Readonly

Generally speaking you want two things in your stores: reactive fields and
Expand Down

0 comments on commit c5ab5ca

Please sign in to comment.