Understanding JupyterLabv4/Notebook v7 changes with INotebookTrackers and ActiveCells

I have a couple of extensions that interact with the current notebook that used to work with Labv4 but with recent changes have stopped working (don’t have exact timing but they worked with Labv4 as of the early alpha releases). I am trying understand if this is an interface change or an alpha release problem.

Example 1: Create a new code cell and insert code

# notebooks is an INotebookTracker
notebook = notebooks.currentWidget.content
NotebookActions.insertBelow(notebook)
activeCell=notebook.activeCell
#This last line currently breaks in Labv4 but works in Labv3
activeCell.model.value.text="code goes here"

Example 2: Accessing Notebook Metadata of current notebook (abbreviated)

#In Labv4 toJSON() is not available,  this works in Labv3 
# notebooks is an INotebookTracker
notebook: Notebook;
notebook = notebooks.currentWidget.content;
notebook.model.metadata.toJSON();

I have tried looking through the changelogs of Labv4 so far and not seen anything obvious. Trying to get ahead of the curve on Labv4.

Ok, I have worked around both problems for Labv4/Notebookv7 with the latest Alpha releases
For Example 1 rather than

activeCell.model.value.text="code goes here"

I used this

activeCell.model.sharedModel.source = "code goes here";

For example 2, just removing the .toJSON() would get me what I want, but I am under the impression it is better to use the sharedModel so notebook.model.sharedModel.metadata returns a JSON object

1 Like

As a glide path, I also confirmed that these changes work with JupyterLab 3.6.1 (But do not work with 3.5.0) so just thought I would share that useful tidbit for those looking to get a head start on problems like this.

1 Like