/
githubmirror
/
preact
Обзор
Документация
Войти
/
githubmirror
/
preact
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
compat/src/Children.js
21 строка
576 B
Jovi De Croock
Golf: loose equality where the operands make it identical
06 авг 2026, 18:59
06 авг 2026, 18:59
5e96b7a
Код
Авторство
О чём код?
import { toChildArray } from 'preact'; const mapFn = (children, fn, context) => { if (children == null) return null; return toChildArray(toChildArray(children).map(fn.bind(context))); }; // This API is completely unnecessary for Preact, so it's basically passthrough. export const Children = { map: mapFn, forEach: mapFn, count(children) { return children ? toChildArray(children).length : 0; }, only(children) { const normalized = toChildArray(children); if (normalized.length != 1) throw 'Children.only'; return normalized[0]; }, toArray: toChildArray };