@@ -596,10 +596,19 @@ declare module 'svelte' {
596596 [ K in keyof T ] : ( ) => T [ K ] ;
597597 } ;
598598
599+ /** Decode a value. The value will be whatever the evaluated JavaScript emitted by the corresponding {@link Encode} function evaluates to. */
599600 type Decode < T > = ( value : any ) => T ;
600601
602+ /** Encode a value as a string. The string should be _valid JavaScript code_ -- for example, the output of `devalue`'s `uneval` function. */
601603 type Encode < T > = ( value : T ) => string ;
602604
605+ /**
606+ * Custom encode and decode options. This must be used in combination with an environment variable to enable treeshaking, eg:
607+ * ```ts
608+ * import { BROWSER } from 'esm-env';
609+ * const transport: Transport<MyType> = BROWSER ? { decode: myDecodeFunction } : { encode: myEncodeFunction };
610+ * ```
611+ */
603612 type Transport < T > =
604613 | {
605614 encode : Encode < T > ;
@@ -610,10 +619,26 @@ declare module 'svelte' {
610619 decode : Decode < T > ;
611620 } ;
612621
622+ /** Make the result of a function hydratable. This means it will be serialized on the server and available synchronously during hydration on the client. */
613623 type Hydratable = {
614- < T > ( key : string , fn : ( ) => T , options ?: { transport ?: Transport < T > } ) : T ;
624+ < T > (
625+ /**
626+ * A key to identify this hydratable value. Each hydratable value must have a unique key.
627+ * If writing a library that utilizes `hydratable`, prefix your keys with your library name to prevent naming collisions.
628+ */
629+ key : string ,
630+ /**
631+ * A function that returns the value to be hydrated. On the server, this value will be stashed and serialized.
632+ * On the client during hydration, the value will be used synchronously instead of invoking the function.
633+ */
634+ fn : ( ) => T ,
635+ options ?: { transport ?: Transport < T > }
636+ ) : T ;
637+ /** Get a hydratable value from the server-rendered store. If used after hydration, will always return `undefined`. Only works on the client. */
615638 get : < T > ( key : string , options ?: { decode ?: Decode < T > } ) => T | undefined ;
639+ /** Check if a hydratable value exists in the server-rendered store. */
616640 has : ( key : string ) => boolean ;
641+ /** Set a hydratable value. Only works on the server during `render`. */
617642 set : < T > ( key : string , value : T , options ?: { encode ?: Encode < T > } ) => void ;
618643 } ;
619644
0 commit comments