-
Notifications
You must be signed in to change notification settings - Fork 117
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
Saving environment across the full course #24
Comments
Thanks for opening this as a separate issue – I missed that other comment! Are your code cells spread out across multiple exercises? And does it make a difference if you try it with two code blocks in the same exercise? If it does work within the same exercise, that'd indicate that the problem is the component mounting/unmounting. When the If this is the case, one solution could be to store the kernel object outside of the component, maybe via React Context? The idea would be that the const [kernel, setKernel] = useState(null) This is the source of truth that gets passed down to all code cells (and gets updated after it connects or if the kernel happens to die in between). Using context here means that we don't have to pass it to every code celll as a prop. In export const KernelContext = React.createContext(null); And then wrapp the whole app in render() {
// etc.
return (
<KernelContext.Consumer>
{({ kernel, setKernel }) => /* rest of the CodeBlock component, starting with <StaticQuery> etc. */}
</KernelContext.Consumer>
)
} We can then add two more props to the Even as code blocks mount and unmount, the kernel will stay available, as it's state stored on the app. I haven't actually tried this and it's possible that I'm wrong about something here... but I thought I'd write down my ideas in case you want to give it a go (since I probably won't have time to look at it in detail this week) 🙂 |
Hi @ines,
Yes but ....
When I test with 2 code cells in the same exercise, my variables and packages still don't get recognized. I am not sure if that will change your suggestion but I'll still give it a go! Developing is something that I am still learning so i'll see if I can play around without burning my course 😂. |
Ahhhhh, so I think I came to a wrong conclusion here, but thinking about it some more, the issue here is probably still what I thought it might be and related to how React renders the components. In my standalone Juniper code, only one instance of However, in this implementation here, the code block components are created with their own instance of Juniper, each with its own kernel object instance (
Sure and please don't feel any pressure to implement any of this 😅 I just thought I'd share my idea, in case it works and you (or someone else) want to try it out. If you do end up playing with it and haven't used that React context stuff before, this post has a nice explanation. Basically, the problem it solves is that there are many code blocks that are created programmatically and that are several levels down the component tree. But they all need that |
Sorry @ines for referencing this again,
I tried changing
isolateCells: true
insrc/components/juniper.js
and I am still not having follow up cells retaining the variables in the previous cell's environment.Is there anywhere I should look to debug this? I think this feature could be really useful especially for importing modules and data.
Originally posted by @hfboyce in #13 (comment)
The text was updated successfully, but these errors were encountered: