Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyraspopov committed Sep 14, 2024
1 parent 383514a commit c2fb2d7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,29 @@ count(20);
// No output
```

### Working with dependencies

When signals are read in `derive()` or `watch()` functions, they are tracked as dependencies so the
derived signal or the watcher can re-run when the used signal is updated. These dependencies are
dynamic so can be used under some conditions:

```js
let enabled = os.signal(false);
let count = os.signal(0);

os.watch(() => {
if (enabled()) {
console.log(`The count is ${count()}.`);
} else {
console.log("Nothing to see here!");
}
});
```

In this example, the watcher going to log "Nothing to see here!" while value of `enabled` remains
`false`. Reading `count` earlier than the condition where it is used means logging "Nothing to see
here" every time `count` is updated, even though it's not going to be actually used.

### Observing External Sources

The `observe` method creates a signal that subscribes to an external source of values:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "inertial",
"version": "0.2.2",
"version": "0.3.0",
"type": "module",
"description": "A tiny library for integrating reactive signals anywhere.",
"author": "Oleksii Raspopov",
Expand Down

0 comments on commit c2fb2d7

Please sign in to comment.