Nothing works, I dont understand modern javascript

This commit is contained in:
Igor Katson 2023-11-21 00:50:35 +00:00
parent 72666e9258
commit d5cf369a75
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
139 changed files with 10138 additions and 55 deletions

View file

@ -0,0 +1,21 @@
import { toChildArray } from 'preact';
const mapFn = (children, fn) => {
if (children == null) return null;
return toChildArray(toChildArray(children).map(fn));
};
// 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
};