Skip to content

Document models have two sources of truth (widget context & widget content)  #88

@dlqqq

Description

@dlqqq

Description

While researching #76 and #93, I found the source code on what sets the dirty state.

Most "top-level" widgets (that get a dedicated tab in JupyterLab) inherit from the DocumentWidget class, which implements this method:

/**
 * Handle the dirty state of the context model.
 */
private _handleDirtyState(): void {
  if (
    this.context.model.dirty &&
    !this.title.className.includes(DIRTY_CLASS)
  ) {
    this.title.className += ` ${DIRTY_CLASS}`;
  } else {
    this.title.className = this.title.className.replace(DIRTY_CLASS, '');
  }
}

The issue is that the document model is stored in two places: this.context.model and this.content.model. We only update this.content.model, but the dirty indicator reads from this.context.model. This is because this.context: DocumentRegistry.IContext does not provide a way to update the document model.

We ought to understand:

  • What is document context, and why does it have a separate reference to the model?
  • How can we stick to a single source of truth for the document model?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions