You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reactivity.md
+37-39Lines changed: 37 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -162,22 +162,18 @@ const name = Generators.observe((notify) => {
162
162
});
163
163
```
164
164
165
-
As another example, here is using `Generators.observe` to expose the current pointer coordinates:
165
+
As another example, here is using `Generators.observe` to expose the current pointer coordinates as `pointer` = <spanstyle="font-variant-numeric: tabular-nums;">[${pointer.join(", ")}]</span>:
And here’s a generator `j` that increments once a second, defined directly by an immediately-invoked async generator function.
176
+
And here’s a generator `j` = <spanstyle="font-variant-numeric: tabular-nums;">${j}</div> that increments once a second, defined directly by an immediately-invoked async generator function.
If a generator does not explicitly `await`, it will yield once every [animation frame](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame), typically 60 times per second. Generators also automatically pause when the page is put in a background tab.
187
+
If a generator does not explicitly `await`, as `i` = <spanstyle="font-variant-numeric: tabular-nums;">${i}</div> below, it will yield once every [animation frame](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame), typically 60 times per second. Generators also automatically pause when the page is put in a background tab.
196
188
197
189
```js echo
198
190
consti= (function* () {
@@ -202,47 +194,53 @@ const i = (function* () {
202
194
})();
203
195
```
204
196
205
-
```js echo
206
-
i
207
-
```
208
-
209
197
As you might imagine, you can use such a generator to drive an animation. A generator is typically easier than a `requestAnimationFrame` loop because the animation is declarative — the code runs automatically whenever `i` changes — and because you don’t have to handle [invalidation](#invalidation) to terminate the loop.
You can also use a generator to stream live data. Here is a WebSocket that listens for the current price of Bitcoin, keeping the last minute of data in memory.
In the future, Plot will support more interaction methods, including brushing. Please upvote [#5](https://github.com/observablehq/plot/issues/5) if you are interested in this feature.
0 commit comments