From 0247b89fc8dfccb45f53120b83348b63e79ffeb7 Mon Sep 17 00:00:00 2001 From: Aiden Bai Date: Tue, 6 Jul 2021 02:12:49 -0700 Subject: [PATCH] docs: add fre as alternative library --- README.md | 2 +- src/createElement.ts | 3 ++- src/m.ts | 20 ++++++++++---------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 6bb712003f..ea62f79309 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ We expect all Million contributors to abide by the terms of our [Code of Conduct ## Acknowledgments -Million takes heavy inspiration from [React](/~https://github.com/facebook/react), and believes in the core philosophies and values behind [Lucia](/~https://github.com/aidenybai/lucia) and [Inferno](/~https://github.com/infernojs/inferno). Feel free to check them out if you interested in an alternative library to use. +Million takes heavy inspiration from [React](/~https://github.com/facebook/react), and believes in the core philosophies and values behind [Lucia](/~https://github.com/aidenybai/lucia), [Fre](/~https://github.com/yisar/fre), and [Inferno](/~https://github.com/infernojs/inferno). Feel free to check them out if you interested in an alternative library to use. _Why is it called "Million"? The name originated with the goal of being able to handle [1M+ ops/sec for benchmarks](/~https://github.com/aidenybai/million/tree/main/benchmarks#readme)_ diff --git a/src/createElement.ts b/src/createElement.ts index 5c64dfb9cc..4912e47e72 100644 --- a/src/createElement.ts +++ b/src/createElement.ts @@ -11,10 +11,11 @@ export const createElement = (vnode: VNode, attachField = true): HTMLElement | T if (typeof vnode === 'string') return document.createTextNode(vnode); const el = Object.assign(document.createElement(vnode.tag), vnode.props); - vnode.children && + if (vnode.children) { vnode.children.forEach((child) => { el.appendChild(createElement(child)); }); + } if (attachField) el[OLD_VNODE_FIELD] = vnode; diff --git a/src/m.ts b/src/m.ts index 8a209f58f8..b6353885a2 100644 --- a/src/m.ts +++ b/src/m.ts @@ -21,16 +21,6 @@ export const ns = (tag: string, props: VProps, children?: VNode[]): void => { } }; -/** - * Generates a style string based on a styleObject - * @param {object} styleObject - Object with styles - * @returns - */ -export const style = (styleObject: Record): string => - Object.entries(styleObject) - .map((style) => style.join(':')) - .join(';'); - /** * Generates a className string based on a classObject * @param {object} classObject - Object with classes paired with boolean values to toggle @@ -41,6 +31,16 @@ export const className = (classObject: Record): string => .filter((className) => classObject[className]) .join(' '); +/** + * Generates a style string based on a styleObject + * @param {object} styleObject - Object with styles + * @returns + */ +export const style = (styleObject: Record): string => + Object.entries(styleObject) + .map((style) => style.join(':')) + .join(';'); + /** * Helper method for creating a VNode * @param {string} tag - The tagName of an HTMLElement