How do we iterate over an ObservableUndoableList?

For example, NotebookPanel#model.cells is a ObservableUndoableList, however it apparently doesn’t have a [Symbol.iterator], hence it doesn’t seem to work with for of. I am able to iterate over it with an ordinary for loop, but it seems like there might be another way.

Searching ObservableUndoableList in the jlab codebase leads to the implementation at jupyterlab/undoablelist.ts at b4db7f03d2ad0b91a9c8c252c56ae5e4a9408fbb · jupyterlab/jupyterlab · GitHub, which leads to exploring the parent class ObservableList in jupyterlab/observablelist.ts at b4db7f03d2ad0b91a9c8c252c56ae5e4a9408fbb · jupyterlab/jupyterlab · GitHub. That shows that the class has an iter method, which produced a Lumino iterator and allows the Lumino iteration functionality to be used: see algorithm/src | @lumino.

For example, each iterates over each item.

I think it would be good to add a [Symbol.iterator] field to the observable list class to allow natural js iteration too, for simplicity.

1 Like

I will put it on my To-do list.