-
-
Notifications
You must be signed in to change notification settings - Fork 325
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
[Draft] A Better Custom JS Interface #1001
Comments
Let's schedule a meeting to talk through this interface and run some simulated development scenarios. |
I think I've been going about this from the wrong angle. If implementing the custom JS component interface is going to require that you import some utilities from import { createBinding } from "@reactpy/client";
const binding = createBinding();
binding.add( function SomeComponent(props) { ... } )
binding.add( function AnotherComponent(props) { ... } )
export binding; |
We forgot to talk about how this bind API will play into the build system |
Good |
This library seems perfect for what we're trying to do: https://github.com/samwillis/nodejs-pypi |
Not only that, but the nodsjs-bin PyPi package seems perfect for us to use for ReactPy Build. |
Is there a good way that js side could call the python component? For example export const App = () => {
return (
<main>
<PythonComponent id='Counter'/>
</main>
)
} @component
def Counter():
number, set_number = use_state(0)
def handle_click(event):
set_number(number + 1)
set_number(number + 1)
set_number(number + 1)
return html.div(
html.h1(number),
html.button({"on_click": handle_click}, "Increment"),
) will be into <main>
<h1>0</h1>
<button>increment</button>
</main> |
@himself65 That feature currently doesn't exist. If we developed some sort of compiling step, is it technically possible that feature could exist in the future. Especially since we've already proven ReactPy can run client-side via this prototype implementation. If you wish to discuss this further, please create a post in GitHub discussions. |
Current Situation
There are a couple problems with the current JS interface:
The last piece is a fairly significant blocker for allowing ReactPy to work seamlessly with JS since users may want to combine components from several different libraries together.
Proposed Actions
The new interface should allow custom JS modules to be implemented in the following way:
In typescript the module would conform to the following spec:
This seems simpler to understand than the current
bind()
function that returns an object with the methods:create(type, props, children)
render(component)
unmount()
.Where components are constructed with
create
and then passed torender
.With that said, the simpler interface comes at the cost of requiring more effort to implement. This comes down to the fact that, ReactPy wouldn't do any work to help render the
model
. Presently,ReactPy
will renderprops
passed to thecreate
function which has the benefit that,model.eventHandlers
will have already been turned into usable callbacks.The new interface would basically make infeasible to write simple examples like the "super simple chart" seen in the docs today without importing some utilities from
@reactpy/client
. On way to remedy that could be to allImportSourceBinding
to have arenderSimple
function that is mutually exclusive withrenderVdom
. TherenderSimple
function could look something like this:Where, as is the case currently,
prop
would contain realized callbacks that were rendered frommodel.eventHandlers
. Import sources that have arenderSimple
function instead of arenderVdom
function would not support component children.The text was updated successfully, but these errors were encountered: