Skip to content

Commit 20e45a5

Browse files
Victor Olivajosepot
andauthored
Update reference docs to match 0.8.0 (#38)
* update core reference to 0.8.0 * update utils reference to 0.8.2 * Update docs/api/core/subscribe.md Co-authored-by: Josep M Sobrepere <josepot@gmail.com>
1 parent 9e147ab commit 20e45a5

File tree

12 files changed

+213
-39
lines changed

12 files changed

+213
-39
lines changed

docs/api/core/bind.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Binds an Observable factory function to React, and returns a hook and shared str
6161
```ts
6262
function bind<A extends unknown[], O>(
6363
getObservable: (...args: A) => Observable<O>,
64-
defaultValue?: T,
64+
defaultValue?: (...args: A) => T | T,
6565
): [(...args: A) => Exclude<O, typeof SUSPENSE>, (...args: A) => Observable<O>]
6666
```
6767

docs/api/core/subscribe.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,32 @@ id: subscribe
33
title: <Subscribe />
44
---
55

6-
A React Component that creates a subscription to the provided Observable once
7-
the component mounts, and unsubscribes when the component unmounts.
6+
A React Component that manages the subscription of its children's Observables.
87

9-
It also acts as a Suspense boundary, rendering a fallback element until the
10-
suspended element resolves.
8+
It will subscribe to all the observables used by its children before they get
9+
mounted, and will unsubscribe from all of them once it unmounts.
10+
11+
If given a fallback, it also acts as a Suspense boundary, rendering the fallback
12+
element until the suspended element resolves.
1113

1214
```tsx
1315
const Subscribe: React.FC<{
14-
source$: Observable<any>
16+
source$?: Observable<any>
1517
fallback?: JSX.Element
1618
}>
1719
```
1820
1921
#### Properties
2022
21-
- `source$`: Source Observable that the Component will subscribe to.
23+
- `source$`: (Optional) Source Observable that the Component should subscribe to, before its children renders.
2224
- `fallback`: (Optional) The JSX Element to be rendered before the
2325
subscription is created. Default: `null`.
2426
25-
:::note Important
26-
This Component doesn't trigger any updates.
27+
:::note
28+
This Component doesn't trigger any updates if any of its subscription emits.
2729
:::
2830
29-
## See also
30-
31-
- [`useSubscribe()`](useSubscribe)
31+
:::note Important
32+
This Component first mounts itself rendering `null`, subscribes to `source$` and
33+
then it renders its children.
34+
:::

docs/api/core/useSubscribe.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

docs/api/utils/collect.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ title: collect(filter)
33
sidebar_label: collect()
44
---
55

6+
:::caution
7+
This function is deprecated. [`partitionByKey`](partitionByKey) covers its intended use case.
8+
:::
9+
610
A [pipeable operator] that collects all the [`GroupedObservable`]s emitted by
711
the source and emits a `Map` with the active inner observables.
812

docs/api/utils/collectValues.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
title: collectValues()
33
---
44

5+
:::caution
6+
This function is deprecated. [`partitionByKey`](partitionByKey) with
7+
[`combineKeys`](combineKeys) covers its intended use case.
8+
:::
9+
510
A [pipeable operator] that collects all the [`GroupedObservable`]s emitted by
611
the source and emits a `Map` with the latest values of the inner Observables.
712

docs/api/utils/combineKeys.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: combineKeys()
3+
sidebar_label: combineKeys()
4+
---
5+
6+
Creates a stream that constructs a Map with the latest value of the inner stream
7+
of each key.
8+
9+
```ts
10+
export const combineKeys = <K, T>(
11+
keys$: Observable<Array<K> | Set<K>>,
12+
getInner$: (key: K) => Observable<T>,
13+
): Observable<Map<K, T>>
14+
```
15+
16+
#### Arguments
17+
18+
- `keys$`: Stream of the list of keys to subscribe to.
19+
- `getInner$`: Function that returns the stream for each key.
20+
21+
#### Returns
22+
23+
A stream with a map containing the latest value from the stream of each key.
24+
25+
## See also
26+
27+
- [`partitionByKey()`](partitionByKey)

docs/api/utils/contextBinder.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: contextBinder()
3+
sidebar_label: contextBinder()
4+
---
5+
6+
Returns a version of bind where its hook will have the first parameters bound
7+
the results of the provided function (which can use hooks)
8+
9+
```ts
10+
export function contextBinder<A extends unknown[], T>(
11+
...args: Array<() => any>
12+
): typeof bind
13+
```
14+
15+
#### Arguments
16+
17+
- `...args`: A list of functions that its result will be bound to the first arguments
18+
within `getObservable` of the `bind` function enhanced by this function.
19+
20+
#### Returns
21+
22+
An enhanced `bind` function where it will have its first arguments bound to the
23+
return values of the input functions
24+
25+
### Example
26+
27+
```tsx
28+
const MyContext = React.createContext<number>(0);
29+
30+
const myContextBind = contextBinder(
31+
() => useContext(MyContext)
32+
);
33+
34+
const [useValue, value$] = myContextBind(
35+
(myContextValue, prefix: string) =>
36+
of(prefix + ' ' + myContextValue)
37+
)
38+
39+
const Component = () => {
40+
const contextDisplay = useValue('Current context value:'))
41+
42+
return <div>{contextDisplay}</div>
43+
}
44+
```
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: createKeyedSignal()
3+
sidebar_label: createKeyedSignal()
4+
---
5+
6+
Creates a Signal grouped by a key. Essentially splits the producer and consumer
7+
of a Subject for each key.
8+
9+
```ts
10+
export function createKeyedSignal<A extends unknown[], T>(
11+
keySelector?: (signal: T) => K,
12+
mapper?: (...args: A) => T,
13+
): [(key: K) => GroupedObservable<K, T>, (...args: A) => void]
14+
```
15+
16+
#### Arguments
17+
18+
- `keySelector?`: (Optional) A function that extracts the key from the emitted value.
19+
If omitted, it will use the first argument as the key.
20+
21+
- `mapper?`: (Optional) A function for mapping the arguments of the emitter function into
22+
the value of the Observable.
23+
24+
Defaults to `(v: Payload) => v`
25+
26+
#### Returns
27+
28+
`[1, 2]`:
29+
30+
1. A function that returns the observable for a given key
31+
32+
2. The emitter function
33+
34+
## See also
35+
36+
- [`createSignal()`](createSignal)

docs/api/utils/createSignal.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: createSignal()
3+
sidebar_label: createSignal()
4+
---
5+
6+
Creates a Signal: it's like a subject, but with the consumer and the producer split.
7+
8+
```ts
9+
export function createSignal<A extends unknown[], T>(
10+
mapper?: (...args: A) => T,
11+
): [Observable<T>, (...args: A) => void]
12+
```
13+
14+
#### Arguments
15+
16+
- `mapper?`: (Optional) A function for mapping the arguments of the emitter function into
17+
the value of the Observable.
18+
19+
Defaults to `(v: Payload) => v`
20+
21+
#### Returns
22+
23+
`[1, 2]`:
24+
25+
1. The observable for the signal
26+
27+
2. The emitter function
28+
29+
## See also
30+
31+
- [`createKeyedSignal()`](createKeyedSignal)

docs/api/utils/partitionByKey.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: partitionByKey()
3+
sidebar_label: partitionByKey()
4+
---
5+
6+
Groups the elements from the source stream by using a key selector, and maps
7+
each of these groups by using a map function.
8+
9+
```ts
10+
export function partitionByKey<T, K, R>(
11+
stream: Observable<T>,
12+
keySelector: (value: T) => K,
13+
streamSelector: (grouped: Observable<T>, key: K) => Observable<R>,
14+
): [(key: K) => GroupedObservable<K, R>, Observable<K[]>]
15+
```
16+
17+
#### Arguments
18+
19+
- `stream`: Input stream
20+
- `keySelector`: Function that specifies the key for each element in `stream`
21+
- `streamSelector`: Function to apply to each resulting group
22+
23+
#### Returns
24+
25+
`[1, 2]`:
26+
27+
1. A function that accepts a key and returns a stream for the group of that key.
28+
29+
2. A stream with the list of active keys
30+
31+
## See also
32+
33+
- [`combineKeys()`](combineKeys)

0 commit comments

Comments
 (0)