UNPKG

compiler.page

Version:

The compiler.page website.

30 lines (29 loc) 897 B
export function init(id, key) { const el = document.getElementById(id) if (!el) { console.warn('Parent element for component %s with id %s not found', key, id) return {} } const parent = el.parentElement if (!parent) { console.warn('Parent of element for component %s with id %s not found', key, id) return {} } return { parent, el } } export function makeIo(options = {}) { const { rootMargin = '76px', log = true, ...rest } = options const io = new IntersectionObserver((entries) => { entries.forEach(({ target, isIntersecting }) => { if (isIntersecting) { if (target.render) { if (log) console.warn('Rendering component %s into the element %s ', target.render.meta.key, target.render.meta.id) target.render() io.unobserve(target) } } }) }, { rootMargin, ...rest }) return io }