-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Investigating JavaScript prime number widget implementation. #15
base: master
Are you sure you want to change the base?
Conversation
This is not a real pr, the purpose is more for talking about the ipyreact pattern. In the first widget, I use a Now I want to do the same thing, but make the calculations in JavaScript. @paddymul : would you be interested in investigating how the
pattern can be used in a way that |
I think you want to use the setter for So
Should be something like
I don't think the above will work though, because it will result in a loop. I'm not sure I have a good answer. |
Thanks for your suggestion. import ipyreact
from traitlets import Any , Int
class PrimeJavaScriptWidget(ipyreact.ReactWidget):
prime_message = Any("Click the Button").tag(sync=True) # <- TODO: this message does not show up because prime_message is overwritten
count = Int(0).tag(sync=True)
_esm = """
import * as React from "react";
function isPrimeNumber(n) {
for (let i = 2; i < n; i++) {
if (n % i === 0) {
return "No 🌐🧊🧊🧊";
}
}
return "Yes 🌐✅✅✅";
}
export const MyUpdater = ({ count, prime_message}) => {
return <span> {prime_message} </span>;
};
export default function ({ on_count, count, prime_message, on_prime_message}) {
on_prime_message(isPrimeNumber(count));
return (
<div>
<button onClick={() => on_count(count + 1)}>{count} times clicked</button>
<br />
<MyUpdater count={count} prime_message = {prime_message}/>
</div>
);
}
"""
primejs = PrimeJavaScriptWidget()
primejs.prime_message = "Hello World" # <- TODO
primejs |
885d994
to
511a7ba
Compare
No description provided.