Skip to content

Commit 7a0e6b0

Browse files
committed
add isObserved to docs
1 parent c562fa1 commit 7a0e6b0

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

docs/docs/api/observe.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,21 @@ const MyView: view = ({ barVal = observe.foo.bar }) => { ... }
4545

4646
Whenever an `observe`d value in state is changed (e.g with
4747
[update](/docs/api/update)), the view or producer using it is re-triggered.
48+
49+
## .isObserved()
50+
51+
If a reaction is needed in the case that a certain path is observed by a producer or a view, e.g. when needing to populate information on-demand, then `isObserved` can be used.
52+
53+
This will return a boolean with the status of the path.
54+
55+
```
56+
const Foo: producer = ({ status = observe.foo.bar.isObserved() }) => {
57+
if (!status) {
58+
// not being observed
59+
return
60+
}
61+
62+
// there is at least an observer
63+
// ...
64+
}
65+
```

0 commit comments

Comments
 (0)