Skip to content

Commit 6f8da52

Browse files
authored
docs: various edits (#72)
1 parent 4435461 commit 6f8da52

File tree

4 files changed

+30
-28
lines changed

4 files changed

+30
-28
lines changed

src/Iterate/index.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useAsyncIter, type IterationResult } from '../useAsyncIter/index.js';
66
export { Iterate, type IterateProps };
77

88
/**
9-
* The `<Iterate>` helper component (also exported as `<It>`) is used to format and render an async
9+
* The `<Iterate>` component (also exported as `<It>`) is used to format and render an async
1010
* iterable (or a plain non-iterable value) directly onto a piece of UI.
1111
*
1212
* Essentially, can be seen as a {@link useAsyncIter `useAsyncIter`} hook in a component form,
@@ -46,15 +46,15 @@ export { Iterate, type IterateProps };
4646
* {@link useAsyncIter `useAsyncIter`} being a hook it has to re-render an entire
4747
* component's output for every new value.
4848
*
49-
* Given an async iterable as the `value` prop, this component will iterate it and render each new
49+
* Given an async iterable as the `value` prop, this component will iterate it and render every new
5050
* value that becomes available together with any possible completion or error it may run into.
51-
* If `value` is a plain (non async iterable) value, it will simply be rendered over as-is.
51+
* If `value` is a plain (non async iterable) value, it will simply be rendered as-is.
5252
*
5353
* Whenever given `value` is changed from the previous one seen, `<Iterate>` will close the previous
5454
* if it was async iterable before proceeding to iterate the new `value`. Care should be taken to
55-
* avoid passing a constantly recreated iterable object across re-renders, e.g; by declaring it outside the component body or control __when__ it
56-
* should be recreated with React's [`useMemo`](https://react.dev/reference/react/useMemo).
57-
* `<Iterate>` will automatically close its iterated iterable as soon as it gets unmounted.
55+
* avoid passing a constantly recreated iterable object across re-renders, e.g; by declaring it outside
56+
* the component body or by controlling __when__ it should be recreated with React's
57+
* [`useMemo`](https://react.dev/reference/react/useMemo). `<Iterate>` will automatically close its iterated iterable as soon as it gets unmounted.
5858
*
5959
* ---
6060
*
@@ -141,7 +141,7 @@ type IterateProps<TVal, TInitialVal = undefined> =
141141

142142
type IteratePropsWithRenderFunction<TVal, TInitialVal = undefined> = {
143143
/**
144-
* The source value to iterate over, an async iterable or a plain (non async iterable) value.
144+
* The source value to iterate over - an async iterable or a plain (non async iterable) value.
145145
*/
146146
value: TVal;
147147
/**

src/IterateMulti/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export { IterateMulti, type IterateMultiProps };
99
// TODO: The initial values should be able to be given in function/s form, with consideration for iterable sources that could be added in dynamically.
1010

1111
/**
12-
* The `<IterateMulti>` helper component (also exported as `<ItMulti>`) is used to combine and render
12+
* The `<IterateMulti>` component (also exported as `<ItMulti>`) is used to combine and render
1313
* any number of async iterables (or plain non-iterable values) directly onto a piece of UI.
1414
*
1515
* It's similar to `<Iterate>`, only it works with any changeable number of async iterables or plain values

src/iterateFormatted/index.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ import { type Iterate } from '../Iterate/index.js'; // eslint-disable-line @type
1414
export { iterateFormatted };
1515

1616
/**
17-
* An optional utility to format an async iterable's values inline where its passed into
18-
* an other consuming component.
17+
* A utility to inline-format an async iterable's values before passed into an other
18+
* consuming component.
19+
*
20+
* Can be thought of as mapping an async iterable before being rendered/passed over in the same way
21+
* you would commonly `.map(...)` an array before rendering/passing it over.
1922
*
2023
* @example
2124
* ```tsx
@@ -55,27 +58,26 @@ export { iterateFormatted };
5558
* This utility should come handy in places when you need a formatted (or _"mapped"_) version of
5659
* some existing async iterable before passing it as prop into an other component which consumes it
5760
* and you rather have the formatting logic right at the place in code of passing the prop instead
58-
* of far from it, having to perform the transformation using some `useMemo` call at the top of the
59-
* component.
61+
* of having to perform the transformation using some `useMemo` call at the top of the component.
6062
*
6163
* The utility's method of operation is to be given a `source` and return from it a new transformed
6264
* async iterable object, attaching it with some special metadata that tells library tools like
63-
* {@link Iterate `<Iterate>`} and {@link useAsyncIter `useAsyncIter`} to bind the iteration process
64-
* to the same original base object. This way, the outer "formatted" iterable may be recreated repeatedly
65-
* without concerns of restarting the iteration process (as long as the `source` arg is consistently
66-
* passed the same base object).
65+
* {@link Iterate `<Iterate>`} and {@link useAsyncIter `useAsyncIter`} that the original base object
66+
* is what the iteration process should be bound to instead of the given object. This way, the
67+
* resulting formatted iterable may be recreated repeatedly without concerns of restarting the
68+
* iteration process (as long as `source` is passed the same base iterable consistently).
6769
*
6870
* `source` may have a current value property (at `.value.current` - per the `AsyncIterableSubject`
6971
* interface), in which case it will be formatted via `formatFn` in the same way like yielded values.
7072
*
71-
* If `source` is a plain value and not an async iterable, it will be passed to the given `formatFn`
73+
* If `source` is a plain value and not an async iterable, it will be passed into the given `formatFn`
7274
* and returned on the spot.
7375
*
7476
* @template TIn The full type of the source input.
7577
* @template TRes The type of values resulting after formatting.
7678
*
7779
* @param source Any async iterable or plain value.
78-
* @param formatFn Function that performs formatting/mapping logic for each value of `source`
80+
* @param formatFn Function that performs formatting/mapping logic for each value of `source`.
7981
*
8082
* @returns a transformed async iterable emitting every value of `source` after formatting.
8183
*/

src/useAsyncIterState/index.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ export { useAsyncIterState, type AsyncIterStateResult, type AsyncIterableChannel
1212

1313
/**
1414
* Basically like {@link https://react.dev/reference/react/useState `React.useState`}, only that the value
15-
* is provided back __wrapped as an async iterable__.
15+
* is provided back __wrapped in an async iterable__.
1616
*
17-
* This hook allows a component to declare and manage a piece of state while easily letting you control
18-
* what specifically area(s) within the UI should be bound to it (should re-render in reaction to changes
19-
* in it) - for example, if combined with one or more {@link Iterate `<Iterate>`}s.
17+
* This hook allows a component to declare and manage a piece of state as an async iterable thus
18+
* letting you easily control what specific places in the app UI tree should be bound to it,
19+
* re-rendering in reaction to its changes (if used in conjunction with {@link Iterate `<Iterate>`}
20+
* for example).
21+
2022
*
2123
* @example
2224
* ```tsx
@@ -44,9 +46,9 @@ export { useAsyncIterState, type AsyncIterStateResult, type AsyncIterableChannel
4446
*
4547
* The returned async iterable can be passed over to any level down the component tree and rendered
4648
* using `<Iterate>`, `useAsyncIter`, and others. It also contains a `.value.current` property which shows
47-
* the current up to date state value at all times. Use this any time you need to read the immediate
49+
* the current up to date state value at any time. Use this any time you need to read the immediate
4850
* current state (for example as part of side effect logic) rather than directly rendering it, since
49-
* for rendering you may simply iterate values as part of an `<Iterate>`.
51+
* for rendering you may simply iterate the values as part of an `<Iterate>`.
5052
*
5153
* Returned also alongside the async iterable is a function for updating the state. Calling it with a new
5254
* value will cause the paired iterable to yield the updated state value as well as immediately set the
@@ -84,9 +86,7 @@ export { useAsyncIterState, type AsyncIterStateResult, type AsyncIterableChannel
8486
* }
8587
* ```
8688
*
87-
* The returned async iterable is a shared iterable - can be iterated by multiple consumers simultaneously
88-
* (e.g multiple {@link Iterate `<Iterate>`}s) and each would pick up the same yielded values and at the
89-
* same time.
89+
* The returned async iterable is a shared iterable so that if iterated by multiple consumers simultaneously (e.g multiple {@link Iterate `<Iterate>`}s) then all would pick up the same yields at the same time.
9090
*
9191
* The returned async iterable is automatically closed on host component unmount.
9292
*
@@ -97,7 +97,7 @@ export { useAsyncIterState, type AsyncIterStateResult, type AsyncIterableChannel
9797
*
9898
* @param initialValue Any optional starting value for the state iterable's `.value.current` property, defaults to `undefined`. You can pass an actual value, or a function that returns a value (which the hook will call once during mounting).
9999
*
100-
* @returns a stateful async iterable and a function with which to yield an update, both maintain stable references across re-renders.
100+
* @returns a stateful async iterable and a function for yielding an update. Both maintain stable references across re-renders.
101101
*
102102
* @see {@link Iterate `<Iterate>`}
103103
*/

0 commit comments

Comments
 (0)