-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VDOM as a Gateway to Plugins #72
Comments
ping: @mpacer |
Yeah I think @gnestor had hoped for a safelist of components, and that it would be those that are |
Hi @rmorshea! 👋 First, vdom doesn't support any tag names that are not native DOM elements. We can change that but that's the first blocker. Second, this could (and probably should) be a separate Python library (e.g. vdom_react). Third, I was able to prototype this in the notebook: # In[1]
from IPython.display import HTML
def render_component(package, module, props, stylesheets = []):
# Generate a unique id for the root DOM node (that React mounts to)
id = str(hash(package + str(props)))
# Optionally load stylesheets that the React component depends on
css = '\n'.join([f'<link href="{url}" rel="stylesheet" />' for url in stylesheets])
html = f'''
<div id="{id}" style="padding: 10px;""></div>
<script type="module">
import React from '//dev.jspm.io/react';
import ReactDOM from '//dev.jspm.io/react-dom';
import ImportedPackage from '//dev.jspm.io/{package}';
// Import a specific or the default module from the package
const ImportedComponent = '{module}' ?
ImportedPackage['{module}'] :
(ImportedPackage.default ? ImportedPackage.default : ImportedPackage);
ReactDOM.render(
React.createElement(ImportedComponent, {props}),
document.getElementById('{id}')
);
</script>
'''
return HTML(html + css)
# In[2]
render_component(
package='@blueprintjs/core',
module='Button',
props={
'intent': 'success',
'text': 'Click me'
}
)
# In[3]
render_component(
package='@blueprintjs/core',
module='RangeSlider',
props={
'min': 0,
'max': 100,
'stepSize': 5,
'labelStepSize': 25
},
stylesheets=[
'//dev.jspm.io/npm:@blueprintjs/[email protected]/lib/css/blueprint.css',
'//dev.jspm.io/npm:@blueprintjs/[email protected]/lib/css/blueprint-icons.css',
'//dev.jspm.io/npm:[email protected]/normalize.css'
]
) A few notes:
from vdom_react import import_component
range_slider = import_component(package='@blueprintjs/core', module='RangeSlider', stylesheets=[
'//dev.jspm.io/npm:@blueprintjs/[email protected]/lib/css/blueprint.css',
'//dev.jspm.io/npm:@blueprintjs/[email protected]/lib/css/blueprint-icons.css',
'//dev.jspm.io/npm:[email protected]/normalize.css'
])
range_slider(min=0, max=100, steoSize=5, labelStepSize=25) Now, combine that with event support in vdom: def handle_change(event):
slider_value = event['target']['value']
my_slider.update(create_slider(value))
def create_slider(value):
return range_slider(
min=0,
max=100,
stepSize=5,
labelStepSize=25,
onChange=handle_change,
value=value
)
my_slider = create_slider(value=0) |
@gnestor I'm a little too tired to take this in at the moment, but this is definitely interesting! I haven't followed everything that's gone on with |
@rmorshea Understood 👌
|
What if you could load React components that were registered as "plugins" using
vdom
...Assuming you had some sort of global plugin storage mechanism it seems like it would be relatively trivial to identify whether or not the
tagName
was novel or not before grabbing the appropriate plugin and dynamically mounting it.The part I don't know anything about is what that "global plugin storage" would look like, or how users would go about registering their plugin with
nteract
.The text was updated successfully, but these errors were encountered: