-
Notifications
You must be signed in to change notification settings - Fork 33
Description
Summary
I think it would be useful to include a top-level importSource attribute to the VDOM spec:
{
"importSource": {
"source": string,
"fallback": string,
}
}The purpose of this attribute is to include ReactJS components in your VDOM that you write or import. You can see this demonstrated in the "ReactJS Components" example from my project idom:
https://idom-sandbox.herokuapp.com/client/index.html
How it Should Work
The source string should be JSX that, when eval'd, will return a component. The attributes and children from the rest of the VDOM will then be passed to this component. For example, the following model:
jsx = """
function Button({ children }) {
return <button>{ children... }</button>
}
"""
vdom = {
"children": ["click me!"],
"importSource": {
"source": jsx,
"fallback": "loading...",
}
}
should result in the the HTML below:
<button>click me!</button>Importing Other Libraries
You should also be able to return a promise from the JSX that results in a component (hence the presence of the fallback key in the proposed importSource dict):
jsx="""
import('the-package').then(pkg => pkg.default);
"""
Things to Think About
What if the JSX were like a module, and the tagName referred to a member of the exported object (this is similar to what I'm doing in iDOM right now):
jsx = """
function Button({ children }) {
return <button>{ children... }</button>
}
export default {
SimpleButton: Button
}
"""
vdom = {
"tagName": "SimpleButton",
"children": ["click me!"],
"importSource": {
"source": jsx,
"fallback": "loading...",
}
}The idea behind this approach is that you could create an API for JSX that looks a bit like this:
jsx_module = JsxModule(source)
button = jsx_module.SimpleButton("click me!")
something_else = jsx_module.SomeOtherComponent(...)