UNPKG

vzcode

Version:
21 lines (20 loc) 712 B
import { generateRunId } from '@vizhub/viz-utils'; /** * Creates a runCode function that triggers code execution by changing the `runId` in the content. * This works for both client-side (with submitOperation) and server-side (with ShareDB document). */ export const createRunCodeFunction = (submitOperation) => () => { submitOperation((content) => ({ ...content, runId: generateRunId(), })); }; /** * Creates a runCodeRef object compatible with React refs. * This is useful for maintaining compatibility with existing code that expects a ref. */ export const createRunCodeRef = (submitOperation) => { return { current: createRunCodeFunction(submitOperation), }; };