Code Cell

Integrating CodeCells with other webapps

We provide a React component which can be used to embed code cells on any webpage. This can be useful on documentation pages or any other webpage where you want to show code snippets and let the user run them without needing to setup anything.

This is possible through the use of the @betteridea/codecell (opens in a new tab) package which provides the CodeCell component and utility functions to run the code cells.

NPM Downloads (opens in a new tab)

<CodeCell .../>

A react component to render a code cell in your app.

Props

PropTypeDescription
cellIdstringUnique id for the cell
appNamestringUnique app name
codestringInitial code for the cell
onAOProcess(pid:string) => voidCallback function that run whenever a process is is loaded
onNewMessage(msgs: msg[]) => voidCallback function, runs whenever process gets new messages
onInbox(inbox: msg[]) => voidCallback function, runs whenever Inbox is received after calling getInbox()
widthstringWidth of the cell
heightstringHeight of the cell
classNamestringClass names for styling
styleReact.CSSPropertiesInline styles
devModebooleanBoolean to enable dev mode

getInbox(...)

Fetches latest Inbox messages from the process.

Arguments

ArgumentTypeDescription
cellIdstringUnique id of the cell
devModebooleanBoolean to enable dev mode

setCellCode(...)

To update the code in a cell, after it has been rendered. It is discouraged to update code by changing the code prop directly, since it re-renders the webview, again this is personal preference.

Arguments

ArgumentTypeDescription
cellIdstringUnique id of the cell
codestringCode to set in the cell
devModebooleanBoolean to enable dev mode

Example

import { CodeCell } from '@betteridea/codecell';
 
// in your react app
<CodeCell
  cellId="C1" 
  appName="BetterIDEa-Code-Cell" 
  code={`Names = {}
 
table.insert(Names, "Ankush")
 
return Names`}
  onAOProcess={(pid)=> console.log("using process: ", pid)}
  onNewMessage={(msgs) => console.log("new messages: ", msgs)}
  onInbox={(inbox) => console.log("got inbox: ", inbox)}
/>

will result in a live code cell like this: