Storing/Using evaluated result

Hi!

We’re working on a very basic code editor project and are trying to store and use the evaluated result of the Embed in Runkit. So far we’re able to manipulate the source code etc but we’re a bit lost on grabbing the output. Is there a way to do this easily? We’re using React if that makes a difference, and would love to be able to store the evaluated result in state.

Thanks in advance. We’re kinda beginners so the docs can be hard to understand!

Hi @stevefrend,

We currently don’t explicitly support this since its a bit complicated (the results can have circular references, classes that don’t exist in the browser but do exist in Node, etc.). That being said, you could theoretically set the embed up to for example make a request back to your server with the result, and choose whatever serialization format makes sense for what you are doing. For example, image doing something like:

const originalConsoleLog = console.log;
console.log = function (...values)
{
    fetch(YOUR_SERVER_URL, { method: "POST", body: JSON.stringify(values) });
    originalConsoleLog(...values);
}

Then if your example code ends with a console.log, it would send the data back to your server, and you could then fetch that from the webpage and do with it what you please.

I know this is not ideal, but just meant as a hold over until we figure something out. We are trying to figure out a reasonable way to make this data more easily accessible directly, but have to fully account for all these different edge cases.

2 Likes

Very interesting workaround! No worries at all, this was just used for a quick implementation in a project. Love using the plugin!