Skip to content

Commit

Permalink
Adds a local dirty property in the DocumentModel (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
hbcarlos authored May 12, 2022
1 parent d62d535 commit d8ee1cb
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/docregistry/src/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export class DocumentModel
this.switchSharedModel(filemodel, true);
this.value.changed.connect(this.triggerContentChange, this);

(this.sharedModel as models.YFile).dirty = false;
this.sharedModel.changed.connect(this._onStateChanged, this);
}

Expand All @@ -52,13 +51,19 @@ export class DocumentModel
* The dirty state of the document.
*/
get dirty(): boolean {
return this.sharedModel.dirty;
return this._dirty;
}
set dirty(newValue: boolean) {
if (newValue === this.dirty) {
const oldValue = this._dirty;
if (newValue === oldValue) {
return;
}
(this.sharedModel as models.YFile).dirty = newValue;
this._dirty = newValue;
this.triggerStateChange({
name: 'dirty',
oldValue,
newValue
});
}

/**
Expand Down Expand Up @@ -158,7 +163,8 @@ export class DocumentModel
): void {
if (changes.stateChange) {
changes.stateChange.forEach(value => {
if (value.name !== 'dirty' || value.oldValue !== value.newValue) {
if (value.name !== 'dirty' || this._dirty !== value.newValue) {
this._dirty = value.newValue;
this.triggerStateChange(value);
}
});
Expand All @@ -170,6 +176,7 @@ export class DocumentModel
*/
readonly sharedModel: models.ISharedFile;
private _defaultLang = '';
private _dirty = false;
private _readOnly = false;
private _contentChanged = new Signal<this, void>(this);
private _stateChanged = new Signal<this, IChangedArgs<any>>(this);
Expand Down

0 comments on commit d8ee1cb

Please sign in to comment.