seitu 0.2.5 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Readable, Subscribable } from '../core';
|
|
2
|
+
import type { UseSubscriptionOptions } from './hooks';
|
|
3
|
+
export interface SubscriptionProps<S extends Subscribable<any> & Readable<any>, R = S['~']['output']> extends Pick<UseSubscriptionOptions<S, R>, 'selector'> {
|
|
4
|
+
value: S;
|
|
5
|
+
children: (value: R) => React.ReactNode;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Declarative component that subscribes to a reactive value and passes it to a render function.
|
|
9
|
+
* Re-renders when the value (or selected value) changes. Use when you prefer a component API
|
|
10
|
+
* over the useSubscription hook.
|
|
11
|
+
*
|
|
12
|
+
* @example Basic usage
|
|
13
|
+
* ```tsx twoslash title="/app/page.tsx"
|
|
14
|
+
* 'use client'
|
|
15
|
+
*
|
|
16
|
+
* import { createSessionStorage } from 'seitu/web'
|
|
17
|
+
* import { Subscription } from 'seitu/react'
|
|
18
|
+
* import * as z from 'zod'
|
|
19
|
+
*
|
|
20
|
+
* const sessionStorage = createSessionStorage({
|
|
21
|
+
* schemas: { count: z.number(), name: z.string() },
|
|
22
|
+
* defaultValues: { count: 0, name: '' },
|
|
23
|
+
* })
|
|
24
|
+
*
|
|
25
|
+
* export default function Page() {
|
|
26
|
+
* return (
|
|
27
|
+
* <Subscription value={sessionStorage}>
|
|
28
|
+
* {(value) => <div>{value.count}</div>}
|
|
29
|
+
* </Subscription>
|
|
30
|
+
* )
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example With selector
|
|
35
|
+
* ```tsx twoslash title="/app/page.tsx"
|
|
36
|
+
* 'use client'
|
|
37
|
+
*
|
|
38
|
+
* import { createSessionStorage } from 'seitu/web'
|
|
39
|
+
* import { Subscription } from 'seitu/react'
|
|
40
|
+
* import * as z from 'zod'
|
|
41
|
+
*
|
|
42
|
+
* const sessionStorage = createSessionStorage({
|
|
43
|
+
* schemas: { count: z.number(), name: z.string() },
|
|
44
|
+
* defaultValues: { count: 0, name: '' },
|
|
45
|
+
* })
|
|
46
|
+
*
|
|
47
|
+
* export default function Page() {
|
|
48
|
+
* return (
|
|
49
|
+
* <Subscription value={sessionStorage} selector={(v) => v.count}>
|
|
50
|
+
* {(count) => <div>{count}</div>}
|
|
51
|
+
* </Subscription>
|
|
52
|
+
* )
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function Subscription<S extends Subscribable<any> & Readable<any>, R = S['~']['output']>({ value, selector, children, }: SubscriptionProps<S, R>): import("react").ReactNode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/vitest';
|
package/dist/react/index.d.ts
CHANGED
package/dist/react.js
CHANGED
|
@@ -278,4 +278,7 @@ function L(t, n) {
|
|
|
278
278
|
return e(l.get()), t;
|
|
279
279
|
}, [l, r]), u;
|
|
280
280
|
}
|
|
281
|
-
|
|
281
|
+
function R({ value: e, selector: t, children: n }) {
|
|
282
|
+
return n(L(e, { selector: t }));
|
|
283
|
+
}
|
|
284
|
+
export { R as Subscription, L as useSubscription };
|