fixed some race conditions.
This commit is contained in:
parent
bb9c3ec396
commit
648876c06b
@ -117,11 +117,14 @@ export class DiagramManager {
|
||||
this._diagramObjects.delete(event.entity.id);
|
||||
break;
|
||||
case DiagramEventType.MODIFY:
|
||||
console.log(event);
|
||||
this._logger.debug(event);
|
||||
//diagramObject = this._diagramObjects.get(event.entity.id);
|
||||
if (diagramObject && event.entity.text) {
|
||||
if (diagramObject && event.entity.text && event.entity.text != diagramObject.text) {
|
||||
diagramObject.text = event.entity.text;
|
||||
} else {
|
||||
this._logger.warn('Skipping text update for', event);
|
||||
}
|
||||
|
||||
if (event.entity.position) {
|
||||
//diagramObject.position = event.entity.position;
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ export class DiagramMenuManager {
|
||||
private readonly _inputTextView: InputTextView;
|
||||
private readonly _scene: Scene;
|
||||
private _cameraMenu: CameraMenu;
|
||||
private logger = log.getLogger('DiagramMenuManager');
|
||||
private _logger = log.getLogger('DiagramMenuManager');
|
||||
private _connectionPreview: ConnectionPreview;
|
||||
|
||||
constructor(notifier: Observable<DiagramEvent>, controllers: Controllers, config: AppConfig) {
|
||||
@ -35,7 +35,8 @@ export class DiagramMenuManager {
|
||||
this.configMenu = new ConfigMenu(config);
|
||||
|
||||
this._inputTextView.onTextObservable.add((evt) => {
|
||||
this.notifyAll({type: DiagramEventType.MODIFY, entity: {id: evt.id, text: evt.text}});
|
||||
const event = {type: DiagramEventType.MODIFY, entity: {id: evt.id, text: evt.text}}
|
||||
this._notifier.notifyObservers(event, DiagramEventObserverMask.FROM_DB);
|
||||
});
|
||||
this.toolbox = new Toolbox();
|
||||
this.scaleMenu = new ScaleMenu2(this._notifier);
|
||||
@ -90,7 +91,7 @@ export class DiagramMenuManager {
|
||||
public createClickMenu(mesh: AbstractMesh, input: WebXRInputSource): ClickMenu {
|
||||
const clickMenu = new ClickMenu(mesh);
|
||||
clickMenu.onClickMenuObservable.add((evt: ActionEvent) => {
|
||||
console.log(evt);
|
||||
this._logger.debug(evt);
|
||||
switch (evt.source.id) {
|
||||
case "remove":
|
||||
this.notifyAll({type: DiagramEventType.REMOVE, entity: {id: clickMenu.mesh.id}});
|
||||
@ -108,7 +109,7 @@ export class DiagramMenuManager {
|
||||
this.scaleMenu.hide();
|
||||
break;
|
||||
}
|
||||
console.log(evt);
|
||||
this._logger.debug(evt);
|
||||
|
||||
}, -1, false, this, false);
|
||||
|
||||
|
||||
@ -35,6 +35,7 @@ export class DiagramObject {
|
||||
private _label: AbstractMesh;
|
||||
private _meshesPresent: boolean = false;
|
||||
private _positionHash: string;
|
||||
private _disposed: boolean = false;
|
||||
private _fromMesh: AbstractMesh;
|
||||
private _toMesh: AbstractMesh;
|
||||
private _meshRemovedObserver: Observer<AbstractMesh>;
|
||||
@ -110,9 +111,18 @@ export class DiagramObject {
|
||||
if (this._label) {
|
||||
this._label.dispose();
|
||||
}
|
||||
if (this._diagramEntity.text != value) {
|
||||
this._eventObservable.notifyObservers({
|
||||
type: DiagramEventType.MODIFY,
|
||||
entity: this._diagramEntity
|
||||
}, DiagramEventObserverMask.TO_DB);
|
||||
}
|
||||
this._diagramEntity.text = value;
|
||||
this._label = createLabel(value);
|
||||
this._label.parent = this._baseTransform;
|
||||
this.updateLabelPosition();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public updateLabelPosition() {
|
||||
@ -255,20 +265,25 @@ export class DiagramObject {
|
||||
}
|
||||
|
||||
public dispose() {
|
||||
if (this._disposed) {
|
||||
this._logger.warn('DiagramObject dispose called for ', this._diagramEntity?.id, ' but it is already disposed');
|
||||
return;
|
||||
}
|
||||
this._logger.debug('DiagramObject dispose called for ', this._diagramEntity?.id)
|
||||
this._scene?.onAfterRenderObservable.remove(this._sceneObserver);
|
||||
this._sceneObserver = null;
|
||||
this._mesh?.setParent(null);
|
||||
this._mesh?.dispose(true, false);
|
||||
this._mesh = null;
|
||||
this._label?.dispose();
|
||||
this._label?.dispose(false, true);
|
||||
this._label = null;
|
||||
this._baseTransform?.dispose();
|
||||
this._baseTransform?.dispose(false);
|
||||
this._diagramEntity = null;
|
||||
this._scene = null;
|
||||
this._fromMesh = null;
|
||||
this._toMesh = null;
|
||||
this._scene?.onMeshRemovedObservable.remove(this._meshRemovedObserver);
|
||||
this._disposed = true;
|
||||
}
|
||||
|
||||
private updateConnection() {
|
||||
|
||||
@ -3,6 +3,7 @@ import {DiagramEntity} from "../../diagram/types/diagramEntity";
|
||||
import {Observable} from "@babylonjs/core";
|
||||
import {UserModelType} from "../../users/userTypes";
|
||||
import {Encryption} from "../encryption";
|
||||
import {DiagramEventObserverMask} from "../../diagram/types/diagramEventObserverMask";
|
||||
|
||||
export async function syncDoc(info: any, onDBRemoveObservable: Observable<DiagramEntity>, onDBUpdateObservable: Observable<DiagramEntity>,
|
||||
onUserObservable: Observable<UserModelType>,
|
||||
@ -26,9 +27,12 @@ export async function syncDoc(info: any, onDBRemoveObservable: Observable<Diagra
|
||||
logger.debug(decrypted);
|
||||
if (doc._deleted) {
|
||||
logger.debug('Delete', doc);
|
||||
onDBRemoveObservable.notifyObservers({id: doc._id, template: decrypted.template}, 1);
|
||||
onDBRemoveObservable.notifyObservers({
|
||||
id: doc._id,
|
||||
template: decrypted.template
|
||||
}, DiagramEventObserverMask.FROM_DB);
|
||||
} else {
|
||||
onDBUpdateObservable.notifyObservers(decrypted, 1);
|
||||
onDBUpdateObservable.notifyObservers(decrypted, DiagramEventObserverMask.FROM_DB);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -38,9 +42,12 @@ export async function syncDoc(info: any, onDBRemoveObservable: Observable<Diagra
|
||||
logger.debug(doc);
|
||||
if (doc._deleted) {
|
||||
logger.debug('Delete', doc);
|
||||
onDBRemoveObservable.notifyObservers({id: doc._id, template: doc.template}, 1);
|
||||
onDBRemoveObservable.notifyObservers({
|
||||
id: doc._id,
|
||||
template: doc.template
|
||||
}, DiagramEventObserverMask.FROM_DB);
|
||||
} else {
|
||||
onDBUpdateObservable.notifyObservers(doc, 1);
|
||||
onDBUpdateObservable.notifyObservers(doc, DiagramEventObserverMask.FROM_DB);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,9 +109,11 @@ export class PouchdbPersistenceManager {
|
||||
await this._encryption.setPassword(this._encKey);
|
||||
}
|
||||
try {
|
||||
const doc = await this.db.get(entity.id);
|
||||
const doc = await this.db.get(entity.id, {conflicts: true, include_docs: true});
|
||||
if (doc && doc._conflicts) {
|
||||
this._logger.warn('CONFLICTS!', doc._conflicts);
|
||||
}
|
||||
if (this._encKey) {
|
||||
|
||||
await this._encryption.encryptObject(entity);
|
||||
const newDoc = {
|
||||
_id: doc._id,
|
||||
@ -121,8 +123,10 @@ export class PouchdbPersistenceManager {
|
||||
this.db.put(newDoc)
|
||||
} else {
|
||||
if (doc) {
|
||||
const newDoc = {...doc, ...entity};
|
||||
const newDoc = {_id: doc._id, _rev: doc._rev, ...entity};
|
||||
this.db.put(newDoc);
|
||||
} else {
|
||||
this.db.put({_id: entity.id, ...entity});
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,7 +141,7 @@ export class PouchdbPersistenceManager {
|
||||
}
|
||||
this.db.put(newDoc);
|
||||
} else {
|
||||
const newEntity = {...entity, _id: entity.id};
|
||||
const newEntity = {_id: entity.id, ...entity};
|
||||
this.db.put(newEntity);
|
||||
}
|
||||
} catch (err2) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user