Skip to content

Commit 0518dc3

Browse files
committed
Inbox and messages
1 parent 0fa2e18 commit 0518dc3

File tree

7 files changed

+375
-25
lines changed

7 files changed

+375
-25
lines changed

README.md

+33-13
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,31 @@ A react component to render a code cell in your app.
2121

2222
#### Props
2323

24-
| Prop | Type | Description |
25-
| ------------- | ---------------------- | ------------------------------------------------------------------ |
26-
| `cellId` | `string` | Unique id for the cell |
27-
| `appName` | `string` | Unique app name |
28-
| `code` | `string` | Initial code for the cell |
29-
| `onAOProcess` | `(pid:string) => void` | Callback function that gets called whenever a process is is loaded |
30-
| `width` | `string` | Width of the cell |
31-
| `height` | `string` | Height of the cell |
32-
| `className` | `string` | Class names for styling |
33-
| `style` | `React.CSSProperties` | Inline styles |
34-
| `devMode` | `boolean` | Boolean to enable dev mode |
24+
| Prop | Type | Description |
25+
| -------------- | ------------------------ | ----------------------------------------------------------------------------- |
26+
| `cellId` | `string` | Unique id for the cell |
27+
| `appName` | `string` | Unique app name |
28+
| `code` | `string` | Initial code for the cell |
29+
| `onAOProcess` | `(pid:string) => void` | Callback function that run whenever a process is is loaded |
30+
| `onNewMessage` | `(msgs: msg[]) => void` | Callback function, runs whenever process gets new messages |
31+
| `onInbox` | `(inbox: msg[]) => void` | Callback function, runs whenever Inbox is received after calling `getInbox()` |
32+
| `width` | `string` | Width of the cell |
33+
| `height` | `string` | Height of the cell |
34+
| `className` | `string` | Class names for styling |
35+
| `style` | `React.CSSProperties` | Inline styles |
36+
| `devMode` | `boolean` | Boolean to enable dev mode |
37+
38+
39+
### `getInbox(...)`
40+
41+
Fetches latest Inbox messages from the process.
42+
43+
#### Arguments
44+
45+
| Argument | Type | Description |
46+
| --------- | --------- | -------------------------- |
47+
| `cellId` | `string` | Unique id of the cell |
48+
| `devMode` | `boolean` | Boolean to enable dev mode |
3549

3650
### `setCellCode(...)`
3751

@@ -66,19 +80,25 @@ import { CodeCell } from '@betteridea/codecell';
6680
cellId="1" // any unique cell id
6781
appName="BetterIDEa-Code-Cell" // Your unique app name
6882
code="print('Portable code cell ftw!')" // initial code (optional)
69-
onAOProcess={(pid) => console.log("using process: ",pid)} // print the process id whenever it loads
83+
onAOProcess={(pid) => console.log("using process: ", pid)} // print the process id whenever it loads
84+
onNewMessage={(msgs) => console.log("new messages: ", msgs)} // print new messages
85+
onInbox={(inbox) => console.log("got inbox: ", inbox)} // print inbox messages
7086
/>
7187
```
7288

7389
To update the cell with a different code snippet, you can use the `setCellCode` function.
7490

7591
```javascript
76-
import { setCellCode } from '@betteridea/codecell';
92+
import { setCellCode, getInbox } from '@betteridea/codecell';
7793

7894
...
7995

8096
// This will update the code in the cell with the id provided
8197
setCellCode("1", "print('Updated code!')");
98+
99+
// This will fetch the latest inbox messages from the process
100+
getInbox("1");
101+
// as soon as the inbox is received, onInbox callback will be called
82102
```
83103

84104
<details>

0 commit comments

Comments
 (0)