Skip to content

Commit 0207e50

Browse files
committed
Updated embedded code snippets in readme
1 parent 8696ce5 commit 0207e50

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

advanced/kernel-messaging/README.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ Jupyterlab provides a class `SessionContext`
3636
that manages a single kernel session. Here is the code to initialize such session:
3737

3838
```ts
39-
// src/panel.ts#L33-L37
39+
// src/panel.ts#L41-L45
4040

4141
this._sessionContext = new SessionContext({
4242
sessionManager: manager.sessions,
4343
specsManager: manager.kernelspecs,
44-
name: 'Extension Examples'
44+
name: 'Extension Examples',
4545
});
4646
```
4747

4848
<!-- prettier-ignore-start -->
49-
<!-- embedme src/panel.ts#L43-L54 -->
49+
<!-- embedme src/panel.ts#L51-L62 -->
5050

5151
```ts
5252
void this._sessionContext
@@ -68,7 +68,7 @@ The session manager object is
6868
provided directly by the JupyterLab application:
6969

7070
```ts
71-
// src/index.ts#L48-L48
71+
// src/index.ts#L52-L52
7272

7373
const manager = app.serviceManager;
7474
```
@@ -81,20 +81,22 @@ to free the kernel session resources if the panel is closed. The whole adapted
8181
panel class looks like this:
8282

8383
```ts
84-
// src/panel.ts#L25-L74
84+
// src/panel.ts#L31-L85
8585

8686
export class ExamplePanel extends StackedPanel {
87-
constructor(manager: ServiceManager.IManager) {
87+
constructor(manager: ServiceManager.IManager, translator?: ITranslator) {
8888
super();
89+
this._translator = translator || nullTranslator;
90+
this._trans = this._translator.load('jupyterlab');
8991
this.addClass(PANEL_CLASS);
9092
this.id = 'kernel-messaging-panel';
91-
this.title.label = 'Kernel Messaging Example View';
93+
this.title.label = this._trans.__('Kernel Messaging Example View');
9294
this.title.closable = true;
9395

9496
this._sessionContext = new SessionContext({
9597
sessionManager: manager.sessions,
9698
specsManager: manager.kernelspecs,
97-
name: 'Extension Examples'
99+
name: 'Extension Examples',
98100
});
99101

100102
this._model = new KernelModel(this._sessionContext);
@@ -103,12 +105,12 @@ export class ExamplePanel extends StackedPanel {
103105
this.addWidget(this._example);
104106
void this._sessionContext
105107
.initialize()
106-
.then(async value => {
108+
.then(async (value) => {
107109
if (value) {
108110
await sessionContextDialogs.selectKernel(this._sessionContext);
109111
}
110112
})
111-
.catch(reason => {
113+
.catch((reason) => {
112114
console.error(
113115
`Failed to initialize the session in ExamplePanel.\n${reason}`
114116
);
@@ -132,6 +134,9 @@ export class ExamplePanel extends StackedPanel {
132134
private _model: KernelModel;
133135
private _sessionContext: SessionContext;
134136
private _example: KernelView;
137+
138+
private _translator: ITranslator;
139+
private _trans: TranslationBundle;
135140
}
136141
```
137142

@@ -143,7 +148,7 @@ Once a kernel is initialized and ready, code can be executed with the following
143148
// src/model.ts#L46-L48
144149

145150
this.future = this._sessionContext.session?.kernel?.requestExecute({
146-
code
151+
code,
147152
});
148153
```
149154

@@ -200,7 +205,7 @@ export class KernelModel {
200205
return;
201206
}
202207
this.future = this._sessionContext.session?.kernel?.requestExecute({
203-
code
208+
code,
204209
});
205210
}
206211

advanced/kernel-messaging/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@
4242
"watch:src": "tsc -w"
4343
},
4444
"dependencies": {
45-
"@jupyterlab/application": "~3.0.0-beta.4",
46-
"@jupyterlab/launcher": "~3.0.0-beta.4",
47-
"@jupyterlab/mainmenu": "~3.0.0-beta.4",
48-
"@jupyterlab/nbformat": "~3.0.0-beta.4",
45+
"@jupyterlab/application": "^3.0.0-beta.8",
46+
"@jupyterlab/launcher": "^3.0.0-beta.8",
47+
"@jupyterlab/mainmenu": "^3.0.0-beta.8",
48+
"@jupyterlab/nbformat": "^3.0.0-beta.8",
49+
"@jupyterlab/translation": "^3.0.0-beta.8",
4950
"@lumino/algorithm": "^1.3.3",
5051
"@lumino/coreutils": "^1.5.3",
5152
"@lumino/datagrid": "^0.5.2",

advanced/kernel-messaging/src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
JupyterFrontEnd,
3-
JupyterFrontEndPlugin
3+
JupyterFrontEndPlugin,
44
} from '@jupyterlab/application';
55

66
import { ICommandPalette } from '@jupyterlab/apputils';
@@ -30,7 +30,7 @@ const extension: JupyterFrontEndPlugin<void> = {
3030
autoStart: true,
3131
optional: [ILauncher],
3232
requires: [ICommandPalette, IMainMenu, ITranslator],
33-
activate: activate
33+
activate: activate,
3434
};
3535

3636
/**
@@ -46,8 +46,8 @@ function activate(
4646
app: JupyterFrontEnd,
4747
palette: ICommandPalette,
4848
mainMenu: IMainMenu,
49-
launcher: ILauncher | null,
50-
translator: ITranslator
49+
translator: ITranslator,
50+
launcher: ILauncher | null
5151
): void {
5252
const manager = app.serviceManager;
5353
const { commands, shell } = app;
@@ -58,7 +58,7 @@ function activate(
5858
if (launcher) {
5959
launcher.add({
6060
command: CommandIDs.create,
61-
category: category
61+
category: category,
6262
});
6363
}
6464

@@ -82,7 +82,7 @@ function activate(
8282
commands.addCommand(CommandIDs.create, {
8383
label: trans.__('Open the Kernel Messaging Panel'),
8484
caption: trans.__('Open the Kernel Messaging Panel'),
85-
execute: createPanel
85+
execute: createPanel,
8686
});
8787

8888
// add items in command palette and menu

0 commit comments

Comments
 (0)