UNPKG

svelte-search-engine

Version:

A wrapper for Google's Programmable Search Engine, providing a Svelte-friendly interface.

34 lines (33 loc) 963 B
import { searchType } from './store'; class Registry { #registry = new Set(); #createKey = (type, gname) => `${type}:${gname}`; has(type, gname) { return this.#registry.has(this.#createKey(type, gname)); } add(type, gname) { this.#registry.add(this.#createKey(type, gname)); return this; } delete(type, gname) { return this.#registry.delete(this.#createKey(type, gname)); } } export const registry = new Registry(); export function registryComponents(gname, components) { searchType.forEach((k) => { const component = components[k]; if (component) { registry.add(k, gname); } }); return () => unRegistryComponents(gname, components); } export function unRegistryComponents(gname, components) { searchType.forEach((k) => { const component = components[k]; if (component) { registry.delete(k, gname); } }); }