Skip to content

Commit 6e05d41

Browse files
committed
add managing lists recipe
1 parent ea6be45 commit 6e05d41

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

docs/recipes/CodeSandbox.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react';
2+
3+
export default function CodeSandbox({ id }: { id: string }) {
4+
return (
5+
<iframe
6+
src={`https://codesandbox.io/embed/${id}?fontsize=14&hidenavigation=1&theme=dark`}
7+
style={{
8+
width: '100%',
9+
height: '80vh',
10+
border: '0',
11+
borderRadius: 4,
12+
overflow: 'hidden',
13+
}}
14+
title="managing-lists-simple"
15+
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
16+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
17+
></iframe>
18+
)
19+
}

docs/recipes/managing-lists.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: Managing lists
3+
---
4+
5+
import CodeSandbox from "./CodeSandbox"
6+
7+
These recipes cover a good way of optimally rendering lists by using React-RxJS. Only the instances that have updated will rerender.
8+
9+
These recipes mainly show an example of how to use [partitionByKey](api/utils/partitionByKey.md) together with [combineKeys](api/utils/combineKeys.md)
10+
11+
## Simple
12+
13+
We'll start by getting a list of stocks with the latest price from each one of them, and rendering them as they update.
14+
15+
<CodeSandbox id="managing-lists-simple-cvwyu" />
16+
17+
## Medium
18+
19+
Now let's imagine we need to calculate an aggregate value from all instances. In this case, we want to calculate a market index based on the price and the volume for each stock.
20+
21+
To do that, we don't need to change much: We can calculate the contribution for the index from each stock in `partitionByKey`, and we can use `combineKeys` to sum all of them up.
22+
23+
<CodeSandbox id="managing-lists-vwz8l" />
24+
25+
## Advanced
26+
27+
Let's consider instead that we want the user to subscribe or unsubscribe from stocks, so that we can add a bit of interactivity.
28+
29+
`partitionByKey` keeps each instance alive until the inner observable completes. This example shows how to use it so we can remove stocks when the user presses on the button.
30+
31+
<CodeSandbox id="managing-lists-advanced-vf8y8" />

sidebars.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
someSidebar: {
33
Introduction: ["motivation", "quick-start", "features"],
4-
Recipes: ["recipes/invalidate-query"],
4+
Recipes: ["recipes/managing-lists", "recipes/invalidate-query"],
55
"API Reference": [
66
{
77
type: "category",

0 commit comments

Comments
 (0)