All files / solid/src/storage kv.ts

100% Statements 9/9
100% Branches 2/2
100% Functions 1/1
100% Lines 9/9

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 261x 1x                             1x 2x   2x 2x 2x   2x 2x  
import { kv, type KVState, type Storable } from '@anchorlib/storage/db';
import { onCleanup } from 'solid-js';
 
/**
 * @deprecated Use `kv()` instead.
 * Creates a reactive key-value store reference with automatic cleanup.
 *
 * This function initializes a key-value store and sets up automatic cleanup
 * when the component using this store is unmounted. It's designed to work
 * within Solid.js reactivity system.
 *
 * @template T - The type of the storable value, must extend Storable
 * @param name - The unique identifier for the key-value store
 * @param init - The initial value for the store
 * @returns A reactive key-value store state object
 */
export function kvRef<T extends Storable>(name: string, init: T): KVState<T> {
  const state = kv(name, init);
 
  onCleanup(() => {
    kv.leave(state);
  });
 
  return state;
}