Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x | import type { LinkableSchema, ObjLike, StateOptions } from '@anchorlib/core';
import { session } from '@anchorlib/storage';
import { onCleanup } from 'solid-js';
/**
* @deprecated Use `session()` instead.
* Creates a session state reference that automatically cleans up when the component unmounts.
*
* This function wraps the core `session` storage mechanism with Solid.js lifecycle management,
* ensuring that session state is properly cleaned up when the component using it is destroyed.
*
* @template T - The type of the state object, must extend ObjLike
* @template S - The schema type for the state, defaults to LinkableSchema
* @param name - A unique identifier for the session state
* @param init - The initial value for the state
* @param options - Optional configuration for state behavior and schema validation
* @returns A reactive state object that persists across sessions
*/
export function sessionRef<T extends ObjLike, S extends LinkableSchema = LinkableSchema>(
name: string,
init: T,
options?: StateOptions<S>
): T {
const state = session(name, init, options);
onCleanup(() => {
session.leave(state);
});
return state;
}
|