UNPKG

svelte-search-engine

Version:

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

34 lines (33 loc) 936 B
import { searchElementApi } from './api'; import { registryComponents } from './registry'; import { subscribeComponents } from './store'; export const searchEngine = (node, param) => { if (!param) { return; } const api = searchElementApi(); let gname; let components = undefined; if (Array.isArray(param)) { const [conf, optConf] = param; gname = conf.gname; components = optConf.components; api.render(conf, optConf); } else { gname = param.gname; components = param.components; api.render({ ...param, div: node }); } if (!components) { return; } const unRegistryComponents = registryComponents(gname, components); const unsubscribeComponents = subscribeComponents(gname, components); return { destroy() { unRegistryComponents(); unsubscribeComponents(); } }; };