Skip to content

Instantly share code, notes, and snippets.

@InfiniteXyy
Created July 28, 2022 07:58
Show Gist options
  • Save InfiniteXyy/a4631a43667fb63de402ea4234fad453 to your computer and use it in GitHub Desktop.
Save InfiniteXyy/a4631a43667fb63de402ea4234fad453 to your computer and use it in GitHub Desktop.
Frontend Framework Idea
let context = { components: [] };
function element(type, props, children) {
return React.createElement(
type,
props,
typeof children === 'function' ? children() : children,
);
}
const _ = new Proxy(
{},
{
get(type) {
return (children, props) => element(type, props, children);
},
},
);
function render(cb) {
context.components = [];
cb();
const components = <>{context.components}</>;
context.components = [];
return components;
}
function App() {
return render(() => {
_.div('title', { style: { fontSize: '20px ' } });
_.ul(
() => {
['react', 'vue'].forEach(type => _.li(type));
},
{ class: 'list' },
);
_.div('something');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment