Skip to content

There is no way to observe cell ID changes via public API #354

@krassowski

Description

@krassowski

Description

The public API does not expose ymodel nor propagate the cell ID changes.

getId(): string {
return this.ymodel.get('id');
}

this.ymodel.observeDeep(this._modelObserver);

protected getChanges(events: Y.YEvent<any>[]): Partial<CellChange> {
const changes: CellChange = {};
const sourceEvent = events.find(
event => event.target === this.ymodel.get('source')
);
if (sourceEvent) {
changes.sourceChange = sourceEvent.changes.delta as any;
}
const metadataEvents = events.find(
event => event.target === this._ymetadata
);
if (metadataEvents) {
changes.metadataChange = metadataEvents.changes.keys;
metadataEvents.changes.keys.forEach((change, key) => {
switch (change.action) {
case 'add':
this._metadataChanged.emit({
key,
newValue: this._ymetadata.get(key),
type: 'add'
});
break;
case 'delete':
this._metadataChanged.emit({
key,
oldValue: change.oldValue,
type: 'remove'
});
break;
case 'update':
{
const newValue = this._ymetadata.get(key);
const oldValue = change.oldValue;
let equal = true;
if (typeof oldValue == 'object' && typeof newValue == 'object') {
equal = JSONExt.deepEqual(oldValue, newValue);
} else {
equal = oldValue === newValue;
}
if (!equal) {
this._metadataChanged.emit({
key,
type: 'change',
oldValue,
newValue
});
}
}
break;
}
});
}

There is also no way to listen to cell_type changes. If we assume that either or both are immutable then we should document it.

This came up in jupyterlab/jupyterlab#18101.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions