-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
|
||
export default function CodeSandbox({ id }: { id: string }) { | ||
return ( | ||
<iframe | ||
src={`https://codesandbox.io/embed/${id}?fontsize=14&hidenavigation=1&theme=dark`} | ||
style={{ | ||
width: '100%', | ||
height: '80vh', | ||
border: '0', | ||
borderRadius: 4, | ||
overflow: 'hidden', | ||
}} | ||
title="managing-lists-simple" | ||
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking" | ||
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts" | ||
></iframe> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
title: Managing lists | ||
--- | ||
|
||
import CodeSandbox from "./CodeSandbox" | ||
|
||
These recipes cover a good way of optimally rendering lists by using React-RxJS. Only the instances that have updated will rerender. | ||
|
||
These recipes mainly show an example of how to use [partitionByKey](api/utils/partitionByKey.md) together with [combineKeys](api/utils/combineKeys.md) | ||
|
||
## Simple | ||
|
||
We'll start by getting a list of stocks with the latest price from each one of them, and rendering them as they update. | ||
|
||
<CodeSandbox id="managing-lists-simple-cvwyu" /> | ||
|
||
## Medium | ||
|
||
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. | ||
|
||
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. | ||
|
||
<CodeSandbox id="managing-lists-vwz8l" /> | ||
|
||
## Advanced | ||
|
||
Let's consider instead that we want the user to subscribe or unsubscribe from stocks, so that we can add a bit of interactivity. | ||
|
||
`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. | ||
|
||
<CodeSandbox id="managing-lists-advanced-vf8y8" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters