Created
July 28, 2022 07:58
-
-
Save InfiniteXyy/a4631a43667fb63de402ea4234fad453 to your computer and use it in GitHub Desktop.
Frontend Framework Idea
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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