Commit a5efa30b authored by Igor Kulikov's avatar Igor Kulikov

Minor performance improvements

parent 6250d3b3
...@@ -414,7 +414,7 @@ ...@@ -414,7 +414,7 @@
} }
return BaseError; return BaseError;
}()); }());
BaseError.prototype = new Error(); Object.defineProperty(BaseError, 'prototype', new Error());
var ModelvalidationError = /** @class */ (function (_super) { var ModelvalidationError = /** @class */ (function (_super) {
__extends(ModelvalidationError, _super); __extends(ModelvalidationError, _super);
function ModelvalidationError(message) { function ModelvalidationError(message) {
...@@ -547,7 +547,7 @@ ...@@ -547,7 +547,7 @@
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/ */
var FcModelService = /** @class */ (function () { var FcModelService = /** @class */ (function () {
function FcModelService(modelValidation, model, modelChanged, cd, selectedObjects, dropNode, createEdge, edgeAddedCallback, nodeRemovedCallback, edgeRemovedCallback, canvasHtmlElement, svgHtmlElement) { function FcModelService(modelValidation, model, modelChanged, detectChangesSubject, selectedObjects, dropNode, createEdge, edgeAddedCallback, nodeRemovedCallback, edgeRemovedCallback, canvasHtmlElement, svgHtmlElement) {
var _this = this; var _this = this;
this.connectorsHtmlElements = {}; this.connectorsHtmlElements = {};
this.nodesHtmlElements = {}; this.nodesHtmlElements = {};
...@@ -558,7 +558,7 @@ ...@@ -558,7 +558,7 @@
this.modelValidation = modelValidation; this.modelValidation = modelValidation;
this.model = model; this.model = model;
this.modelChanged = modelChanged; this.modelChanged = modelChanged;
this.cd = cd; this.detectChangesSubject = detectChangesSubject;
this.canvasHtmlElement = canvasHtmlElement; this.canvasHtmlElement = canvasHtmlElement;
this.svgHtmlElement = svgHtmlElement; this.svgHtmlElement = svgHtmlElement;
this.modelValidation.validateModel(this.model); this.modelValidation.validateModel(this.model);
...@@ -616,7 +616,7 @@ ...@@ -616,7 +616,7 @@
* @return {?} * @return {?}
*/ */
function () { function () {
_this.cd.detectChanges(); _this.detectChangesSubject.next();
}), 0); }), 0);
}; };
/** /**
...@@ -943,23 +943,6 @@ ...@@ -943,23 +943,6 @@
} }
return this.dragImage; return this.dragImage;
}; };
/**
* @param {?} edgeAddedCallback
* @param {?} nodeRemovedCallback
* @param {?} edgeRemovedCallback
* @return {?}
*/
FcModelService.prototype.registerCallbacks = /**
* @param {?} edgeAddedCallback
* @param {?} nodeRemovedCallback
* @param {?} edgeRemovedCallback
* @return {?}
*/
function (edgeAddedCallback, nodeRemovedCallback, edgeRemovedCallback) {
this.edgeAddedCallback = edgeAddedCallback;
this.nodeRemovedCallback = nodeRemovedCallback;
this.edgeRemovedCallback = edgeRemovedCallback;
};
return FcModelService; return FcModelService;
}()); }());
if (false) { if (false) {
...@@ -967,8 +950,11 @@ ...@@ -967,8 +950,11 @@
FcModelService.prototype.modelValidation; FcModelService.prototype.modelValidation;
/** @type {?} */ /** @type {?} */
FcModelService.prototype.model; FcModelService.prototype.model;
/** @type {?} */ /**
FcModelService.prototype.cd; * @type {?}
* @private
*/
FcModelService.prototype.detectChangesSubject;
/** @type {?} */ /** @type {?} */
FcModelService.prototype.selectedObjects; FcModelService.prototype.selectedObjects;
/** @type {?} */ /** @type {?} */
...@@ -3311,6 +3297,7 @@ ...@@ -3311,6 +3297,7 @@
*/ */
var NgxFlowchartComponent = /** @class */ (function () { var NgxFlowchartComponent = /** @class */ (function () {
function NgxFlowchartComponent(elementRef, differs, modelValidation, edgeDrawingService, cd, zone) { function NgxFlowchartComponent(elementRef, differs, modelValidation, edgeDrawingService, cd, zone) {
var _this = this;
this.elementRef = elementRef; this.elementRef = elementRef;
this.differs = differs; this.differs = differs;
this.modelValidation = modelValidation; this.modelValidation = modelValidation;
...@@ -3336,8 +3323,15 @@ ...@@ -3336,8 +3323,15 @@
function (index, item) { function (index, item) {
return item; return item;
})); }));
this.detectChangesSubject = new rxjs.Subject();
this.arrowDefId = 'arrow-' + Math.random(); this.arrowDefId = 'arrow-' + Math.random();
this.arrowDefIdSelected = this.arrowDefId + '-selected'; this.arrowDefIdSelected = this.arrowDefId + '-selected';
this.detectChangesSubject
.pipe(operators.debounceTime(50))
.subscribe((/**
* @return {?}
*/
function () { return _this.cd.detectChanges(); }));
} }
Object.defineProperty(NgxFlowchartComponent.prototype, "canvasClass", { Object.defineProperty(NgxFlowchartComponent.prototype, "canvasClass", {
get: /** get: /**
...@@ -3403,7 +3397,7 @@ ...@@ -3403,7 +3397,7 @@
this.userNodeCallbacks = this.userCallbacks.nodeCallbacks; this.userNodeCallbacks = this.userCallbacks.nodeCallbacks;
/** @type {?} */ /** @type {?} */
var element = $(this.elementRef.nativeElement); var element = $(this.elementRef.nativeElement);
this.modelService = new FcModelService(this.modelValidation, this.model, this.modelChanged, this.cd, this.selectedObjects, this.userCallbacks.dropNode, this.userCallbacks.createEdge, this.userCallbacks.edgeAdded, this.userCallbacks.nodeRemoved, this.userCallbacks.edgeRemoved, element[0], element[0].querySelector('svg')); this.modelService = new FcModelService(this.modelValidation, this.model, this.modelChanged, this.detectChangesSubject, this.selectedObjects, this.userCallbacks.dropNode, this.userCallbacks.createEdge, this.userCallbacks.edgeAdded, this.userCallbacks.nodeRemoved, this.userCallbacks.edgeRemoved, element[0], element[0].querySelector('svg'));
if (this.dropTargetId) { if (this.dropTargetId) {
this.modelService.dropTargetId = this.dropTargetId; this.modelService.dropTargetId = this.dropTargetId;
} }
...@@ -3487,7 +3481,7 @@ ...@@ -3487,7 +3481,7 @@
this.adjustCanvasSize(this.fitModelSizeByDefault); this.adjustCanvasSize(this.fitModelSizeByDefault);
} }
if (nodesChanged_1 || edgesChanged_1) { if (nodesChanged_1 || edgesChanged_1) {
this.cd.detectChanges(); this.detectChangesSubject.next();
} }
} }
}; };
...@@ -3820,6 +3814,11 @@ ...@@ -3820,6 +3814,11 @@
* @private * @private
*/ */
NgxFlowchartComponent.prototype.edgesDiffer; NgxFlowchartComponent.prototype.edgesDiffer;
/**
* @type {?}
* @private
*/
NgxFlowchartComponent.prototype.detectChangesSubject;
/** /**
* @type {?} * @type {?}
* @private * @private
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -216,7 +216,7 @@ class BaseError { ...@@ -216,7 +216,7 @@ class BaseError {
Error.apply(this, arguments); Error.apply(this, arguments);
} }
} }
BaseError.prototype = new Error(); Object.defineProperty(BaseError, 'prototype', new Error());
class ModelvalidationError extends BaseError { class ModelvalidationError extends BaseError {
/** /**
* @param {?} message * @param {?} message
...@@ -332,7 +332,7 @@ class FcModelService { ...@@ -332,7 +332,7 @@ class FcModelService {
* @param {?} modelValidation * @param {?} modelValidation
* @param {?} model * @param {?} model
* @param {?} modelChanged * @param {?} modelChanged
* @param {?} cd * @param {?} detectChangesSubject
* @param {?} selectedObjects * @param {?} selectedObjects
* @param {?} dropNode * @param {?} dropNode
* @param {?} createEdge * @param {?} createEdge
...@@ -342,7 +342,7 @@ class FcModelService { ...@@ -342,7 +342,7 @@ class FcModelService {
* @param {?} canvasHtmlElement * @param {?} canvasHtmlElement
* @param {?} svgHtmlElement * @param {?} svgHtmlElement
*/ */
constructor(modelValidation, model, modelChanged, cd, selectedObjects, dropNode, createEdge, edgeAddedCallback, nodeRemovedCallback, edgeRemovedCallback, canvasHtmlElement, svgHtmlElement) { constructor(modelValidation, model, modelChanged, detectChangesSubject, selectedObjects, dropNode, createEdge, edgeAddedCallback, nodeRemovedCallback, edgeRemovedCallback, canvasHtmlElement, svgHtmlElement) {
this.connectorsHtmlElements = {}; this.connectorsHtmlElements = {};
this.nodesHtmlElements = {}; this.nodesHtmlElements = {};
this.canvasHtmlElement = null; this.canvasHtmlElement = null;
...@@ -352,7 +352,7 @@ class FcModelService { ...@@ -352,7 +352,7 @@ class FcModelService {
this.modelValidation = modelValidation; this.modelValidation = modelValidation;
this.model = model; this.model = model;
this.modelChanged = modelChanged; this.modelChanged = modelChanged;
this.cd = cd; this.detectChangesSubject = detectChangesSubject;
this.canvasHtmlElement = canvasHtmlElement; this.canvasHtmlElement = canvasHtmlElement;
this.svgHtmlElement = svgHtmlElement; this.svgHtmlElement = svgHtmlElement;
this.modelValidation.validateModel(this.model); this.modelValidation.validateModel(this.model);
...@@ -403,7 +403,7 @@ class FcModelService { ...@@ -403,7 +403,7 @@ class FcModelService {
* @return {?} * @return {?}
*/ */
() => { () => {
this.cd.detectChanges(); this.detectChangesSubject.next();
}), 0); }), 0);
} }
/** /**
...@@ -652,25 +652,17 @@ class FcModelService { ...@@ -652,25 +652,17 @@ class FcModelService {
} }
return this.dragImage; return this.dragImage;
} }
/**
* @param {?} edgeAddedCallback
* @param {?} nodeRemovedCallback
* @param {?} edgeRemovedCallback
* @return {?}
*/
registerCallbacks(edgeAddedCallback, nodeRemovedCallback, edgeRemovedCallback) {
this.edgeAddedCallback = edgeAddedCallback;
this.nodeRemovedCallback = nodeRemovedCallback;
this.edgeRemovedCallback = edgeRemovedCallback;
}
} }
if (false) { if (false) {
/** @type {?} */ /** @type {?} */
FcModelService.prototype.modelValidation; FcModelService.prototype.modelValidation;
/** @type {?} */ /** @type {?} */
FcModelService.prototype.model; FcModelService.prototype.model;
/** @type {?} */ /**
FcModelService.prototype.cd; * @type {?}
* @private
*/
FcModelService.prototype.detectChangesSubject;
/** @type {?} */ /** @type {?} */
FcModelService.prototype.selectedObjects; FcModelService.prototype.selectedObjects;
/** @type {?} */ /** @type {?} */
...@@ -2646,8 +2638,15 @@ class NgxFlowchartComponent { ...@@ -2646,8 +2638,15 @@ class NgxFlowchartComponent {
(index, item) => { (index, item) => {
return item; return item;
})); }));
this.detectChangesSubject = new Subject();
this.arrowDefId = 'arrow-' + Math.random(); this.arrowDefId = 'arrow-' + Math.random();
this.arrowDefIdSelected = this.arrowDefId + '-selected'; this.arrowDefIdSelected = this.arrowDefId + '-selected';
this.detectChangesSubject
.pipe(debounceTime(50))
.subscribe((/**
* @return {?}
*/
() => this.cd.detectChanges()));
} }
/** /**
* @return {?} * @return {?}
...@@ -2690,7 +2689,7 @@ class NgxFlowchartComponent { ...@@ -2690,7 +2689,7 @@ class NgxFlowchartComponent {
this.userNodeCallbacks = this.userCallbacks.nodeCallbacks; this.userNodeCallbacks = this.userCallbacks.nodeCallbacks;
/** @type {?} */ /** @type {?} */
const element = $(this.elementRef.nativeElement); const element = $(this.elementRef.nativeElement);
this.modelService = new FcModelService(this.modelValidation, this.model, this.modelChanged, this.cd, this.selectedObjects, this.userCallbacks.dropNode, this.userCallbacks.createEdge, this.userCallbacks.edgeAdded, this.userCallbacks.nodeRemoved, this.userCallbacks.edgeRemoved, element[0], element[0].querySelector('svg')); this.modelService = new FcModelService(this.modelValidation, this.model, this.modelChanged, this.detectChangesSubject, this.selectedObjects, this.userCallbacks.dropNode, this.userCallbacks.createEdge, this.userCallbacks.edgeAdded, this.userCallbacks.nodeRemoved, this.userCallbacks.edgeRemoved, element[0], element[0].querySelector('svg'));
if (this.dropTargetId) { if (this.dropTargetId) {
this.modelService.dropTargetId = this.dropTargetId; this.modelService.dropTargetId = this.dropTargetId;
} }
...@@ -2771,7 +2770,7 @@ class NgxFlowchartComponent { ...@@ -2771,7 +2770,7 @@ class NgxFlowchartComponent {
this.adjustCanvasSize(this.fitModelSizeByDefault); this.adjustCanvasSize(this.fitModelSizeByDefault);
} }
if (nodesChanged || edgesChanged) { if (nodesChanged || edgesChanged) {
this.cd.detectChanges(); this.detectChangesSubject.next();
} }
} }
} }
...@@ -3030,6 +3029,11 @@ if (false) { ...@@ -3030,6 +3029,11 @@ if (false) {
* @private * @private
*/ */
NgxFlowchartComponent.prototype.edgesDiffer; NgxFlowchartComponent.prototype.edgesDiffer;
/**
* @type {?}
* @private
*/
NgxFlowchartComponent.prototype.detectChangesSubject;
/** /**
* @type {?} * @type {?}
* @private * @private
......
...@@ -218,7 +218,7 @@ var BaseError = /** @class */ (function () { ...@@ -218,7 +218,7 @@ var BaseError = /** @class */ (function () {
} }
return BaseError; return BaseError;
}()); }());
BaseError.prototype = new Error(); Object.defineProperty(BaseError, 'prototype', new Error());
var ModelvalidationError = /** @class */ (function (_super) { var ModelvalidationError = /** @class */ (function (_super) {
__extends(ModelvalidationError, _super); __extends(ModelvalidationError, _super);
function ModelvalidationError(message) { function ModelvalidationError(message) {
...@@ -351,7 +351,7 @@ function fcTopSort(graph) { ...@@ -351,7 +351,7 @@ function fcTopSort(graph) {
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/ */
var FcModelService = /** @class */ (function () { var FcModelService = /** @class */ (function () {
function FcModelService(modelValidation, model, modelChanged, cd, selectedObjects, dropNode, createEdge, edgeAddedCallback, nodeRemovedCallback, edgeRemovedCallback, canvasHtmlElement, svgHtmlElement) { function FcModelService(modelValidation, model, modelChanged, detectChangesSubject, selectedObjects, dropNode, createEdge, edgeAddedCallback, nodeRemovedCallback, edgeRemovedCallback, canvasHtmlElement, svgHtmlElement) {
var _this = this; var _this = this;
this.connectorsHtmlElements = {}; this.connectorsHtmlElements = {};
this.nodesHtmlElements = {}; this.nodesHtmlElements = {};
...@@ -362,7 +362,7 @@ var FcModelService = /** @class */ (function () { ...@@ -362,7 +362,7 @@ var FcModelService = /** @class */ (function () {
this.modelValidation = modelValidation; this.modelValidation = modelValidation;
this.model = model; this.model = model;
this.modelChanged = modelChanged; this.modelChanged = modelChanged;
this.cd = cd; this.detectChangesSubject = detectChangesSubject;
this.canvasHtmlElement = canvasHtmlElement; this.canvasHtmlElement = canvasHtmlElement;
this.svgHtmlElement = svgHtmlElement; this.svgHtmlElement = svgHtmlElement;
this.modelValidation.validateModel(this.model); this.modelValidation.validateModel(this.model);
...@@ -420,7 +420,7 @@ var FcModelService = /** @class */ (function () { ...@@ -420,7 +420,7 @@ var FcModelService = /** @class */ (function () {
* @return {?} * @return {?}
*/ */
function () { function () {
_this.cd.detectChanges(); _this.detectChangesSubject.next();
}), 0); }), 0);
}; };
/** /**
...@@ -747,23 +747,6 @@ var FcModelService = /** @class */ (function () { ...@@ -747,23 +747,6 @@ var FcModelService = /** @class */ (function () {
} }
return this.dragImage; return this.dragImage;
}; };
/**
* @param {?} edgeAddedCallback
* @param {?} nodeRemovedCallback
* @param {?} edgeRemovedCallback
* @return {?}
*/
FcModelService.prototype.registerCallbacks = /**
* @param {?} edgeAddedCallback
* @param {?} nodeRemovedCallback
* @param {?} edgeRemovedCallback
* @return {?}
*/
function (edgeAddedCallback, nodeRemovedCallback, edgeRemovedCallback) {
this.edgeAddedCallback = edgeAddedCallback;
this.nodeRemovedCallback = nodeRemovedCallback;
this.edgeRemovedCallback = edgeRemovedCallback;
};
return FcModelService; return FcModelService;
}()); }());
if (false) { if (false) {
...@@ -771,8 +754,11 @@ if (false) { ...@@ -771,8 +754,11 @@ if (false) {
FcModelService.prototype.modelValidation; FcModelService.prototype.modelValidation;
/** @type {?} */ /** @type {?} */
FcModelService.prototype.model; FcModelService.prototype.model;
/** @type {?} */ /**
FcModelService.prototype.cd; * @type {?}
* @private
*/
FcModelService.prototype.detectChangesSubject;
/** @type {?} */ /** @type {?} */
FcModelService.prototype.selectedObjects; FcModelService.prototype.selectedObjects;
/** @type {?} */ /** @type {?} */
...@@ -3115,6 +3101,7 @@ if (false) { ...@@ -3115,6 +3101,7 @@ if (false) {
*/ */
var NgxFlowchartComponent = /** @class */ (function () { var NgxFlowchartComponent = /** @class */ (function () {
function NgxFlowchartComponent(elementRef, differs, modelValidation, edgeDrawingService, cd, zone) { function NgxFlowchartComponent(elementRef, differs, modelValidation, edgeDrawingService, cd, zone) {
var _this = this;
this.elementRef = elementRef; this.elementRef = elementRef;
this.differs = differs; this.differs = differs;
this.modelValidation = modelValidation; this.modelValidation = modelValidation;
...@@ -3140,8 +3127,15 @@ var NgxFlowchartComponent = /** @class */ (function () { ...@@ -3140,8 +3127,15 @@ var NgxFlowchartComponent = /** @class */ (function () {
function (index, item) { function (index, item) {
return item; return item;
})); }));
this.detectChangesSubject = new Subject();
this.arrowDefId = 'arrow-' + Math.random(); this.arrowDefId = 'arrow-' + Math.random();
this.arrowDefIdSelected = this.arrowDefId + '-selected'; this.arrowDefIdSelected = this.arrowDefId + '-selected';
this.detectChangesSubject
.pipe(debounceTime(50))
.subscribe((/**
* @return {?}
*/
function () { return _this.cd.detectChanges(); }));
} }
Object.defineProperty(NgxFlowchartComponent.prototype, "canvasClass", { Object.defineProperty(NgxFlowchartComponent.prototype, "canvasClass", {
get: /** get: /**
...@@ -3207,7 +3201,7 @@ var NgxFlowchartComponent = /** @class */ (function () { ...@@ -3207,7 +3201,7 @@ var NgxFlowchartComponent = /** @class */ (function () {
this.userNodeCallbacks = this.userCallbacks.nodeCallbacks; this.userNodeCallbacks = this.userCallbacks.nodeCallbacks;
/** @type {?} */ /** @type {?} */
var element = $(this.elementRef.nativeElement); var element = $(this.elementRef.nativeElement);
this.modelService = new FcModelService(this.modelValidation, this.model, this.modelChanged, this.cd, this.selectedObjects, this.userCallbacks.dropNode, this.userCallbacks.createEdge, this.userCallbacks.edgeAdded, this.userCallbacks.nodeRemoved, this.userCallbacks.edgeRemoved, element[0], element[0].querySelector('svg')); this.modelService = new FcModelService(this.modelValidation, this.model, this.modelChanged, this.detectChangesSubject, this.selectedObjects, this.userCallbacks.dropNode, this.userCallbacks.createEdge, this.userCallbacks.edgeAdded, this.userCallbacks.nodeRemoved, this.userCallbacks.edgeRemoved, element[0], element[0].querySelector('svg'));
if (this.dropTargetId) { if (this.dropTargetId) {
this.modelService.dropTargetId = this.dropTargetId; this.modelService.dropTargetId = this.dropTargetId;
} }
...@@ -3291,7 +3285,7 @@ var NgxFlowchartComponent = /** @class */ (function () { ...@@ -3291,7 +3285,7 @@ var NgxFlowchartComponent = /** @class */ (function () {
this.adjustCanvasSize(this.fitModelSizeByDefault); this.adjustCanvasSize(this.fitModelSizeByDefault);
} }
if (nodesChanged_1 || edgesChanged_1) { if (nodesChanged_1 || edgesChanged_1) {
this.cd.detectChanges(); this.detectChangesSubject.next();
} }
} }
}; };
...@@ -3624,6 +3618,11 @@ if (false) { ...@@ -3624,6 +3618,11 @@ if (false) {
* @private * @private
*/ */
NgxFlowchartComponent.prototype.edgesDiffer; NgxFlowchartComponent.prototype.edgesDiffer;
/**
* @type {?}
* @private
*/
NgxFlowchartComponent.prototype.detectChangesSubject;
/** /**
* @type {?} * @type {?}
* @private * @private
......
import { FcModelValidationService } from './modelvalidation.service'; import { FcModelValidationService } from './modelvalidation.service';
import { FcConnector, FcCoords, FcEdge, FcItemInfo, FcModel, FcNode, FcRectBox } from './ngx-flowchart.models'; import { FcConnector, FcCoords, FcEdge, FcItemInfo, FcModel, FcNode, FcRectBox } from './ngx-flowchart.models';
import { Observable } from 'rxjs'; import { Observable, Subject } from 'rxjs';
import { ChangeDetectorRef, EventEmitter } from '@angular/core'; import { EventEmitter } from '@angular/core';
export declare class FcModelService { export declare class FcModelService {
modelValidation: FcModelValidationService; modelValidation: FcModelValidationService;
model: FcModel; model: FcModel;
cd: ChangeDetectorRef; private readonly detectChangesSubject;
selectedObjects: any[]; selectedObjects: any[];
connectorsHtmlElements: HtmlElementMap; connectorsHtmlElements: HtmlElementMap;
nodesHtmlElements: HtmlElementMap; nodesHtmlElements: HtmlElementMap;
...@@ -23,7 +23,7 @@ export declare class FcModelService { ...@@ -23,7 +23,7 @@ export declare class FcModelService {
connectors: ConnectorsModel; connectors: ConnectorsModel;
nodes: NodesModel; nodes: NodesModel;
edges: EdgesModel; edges: EdgesModel;
constructor(modelValidation: FcModelValidationService, model: FcModel, modelChanged: EventEmitter<any>, cd: ChangeDetectorRef, selectedObjects: any[], dropNode: (event: Event, node: FcNode) => void, createEdge: (event: Event, edge: FcEdge) => Observable<FcEdge>, edgeAddedCallback: (edge: FcEdge) => void, nodeRemovedCallback: (node: FcNode) => void, edgeRemovedCallback: (edge: FcEdge) => void, canvasHtmlElement: HTMLElement, svgHtmlElement: SVGElement); constructor(modelValidation: FcModelValidationService, model: FcModel, modelChanged: EventEmitter<any>, detectChangesSubject: Subject<any>, selectedObjects: any[], dropNode: (event: Event, node: FcNode) => void, createEdge: (event: Event, edge: FcEdge) => Observable<FcEdge>, edgeAddedCallback: (edge: FcEdge) => void, nodeRemovedCallback: (node: FcNode) => void, edgeRemovedCallback: (edge: FcEdge) => void, canvasHtmlElement: HTMLElement, svgHtmlElement: SVGElement);
notifyModelChanged(): void; notifyModelChanged(): void;
detectChanges(): void; detectChanges(): void;
selectObject(object: any): void; selectObject(object: any): void;
...@@ -42,7 +42,6 @@ export declare class FcModelService { ...@@ -42,7 +42,6 @@ export declare class FcModelService {
isEditable(): boolean; isEditable(): boolean;
isDropSource(): boolean; isDropSource(): boolean;
getDragImage(): HTMLImageElement; getDragImage(): HTMLImageElement;
registerCallbacks(edgeAddedCallback: (edge: FcEdge) => void, nodeRemovedCallback: (node: FcNode) => void, edgeRemovedCallback: (edge: FcEdge) => void): void;
} }
interface HtmlElementMap { interface HtmlElementMap {
[id: string]: HTMLElement; [id: string]: HTMLElement;
......
...@@ -63,6 +63,7 @@ export declare class NgxFlowchartComponent implements OnInit, DoCheck { ...@@ -63,6 +63,7 @@ export declare class NgxFlowchartComponent implements OnInit, DoCheck {
}; };
private nodesDiffer; private nodesDiffer;
private edgesDiffer; private edgesDiffer;
private readonly detectChangesSubject;
constructor(elementRef: ElementRef<HTMLElement>, differs: IterableDiffers, modelValidation: FcModelValidationService, edgeDrawingService: FcEdgeDrawingService, cd: ChangeDetectorRef, zone: NgZone); constructor(elementRef: ElementRef<HTMLElement>, differs: IterableDiffers, modelValidation: FcModelValidationService, edgeDrawingService: FcEdgeDrawingService, cd: ChangeDetectorRef, zone: NgZone);
ngOnInit(): void; ngOnInit(): void;
ngDoCheck(): void; ngDoCheck(): void;
......
...@@ -8,7 +8,7 @@ export class FcModelService { ...@@ -8,7 +8,7 @@ export class FcModelService {
modelValidation: FcModelValidationService; modelValidation: FcModelValidationService;
model: FcModel; model: FcModel;
cd: ChangeDetectorRef; private readonly detectChangesSubject: Subject<any>;
selectedObjects: any[]; selectedObjects: any[];
connectorsHtmlElements: HtmlElementMap = {}; connectorsHtmlElements: HtmlElementMap = {};
...@@ -35,7 +35,7 @@ export class FcModelService { ...@@ -35,7 +35,7 @@ export class FcModelService {
constructor(modelValidation: FcModelValidationService, constructor(modelValidation: FcModelValidationService,
model: FcModel, model: FcModel,
modelChanged: EventEmitter<any>, modelChanged: EventEmitter<any>,
cd: ChangeDetectorRef, detectChangesSubject: Subject<any>,
selectedObjects: any[], selectedObjects: any[],
dropNode: (event: Event, node: FcNode) => void, dropNode: (event: Event, node: FcNode) => void,
createEdge: (event: Event, edge: FcEdge) => Observable<FcEdge>, createEdge: (event: Event, edge: FcEdge) => Observable<FcEdge>,
...@@ -48,7 +48,7 @@ export class FcModelService { ...@@ -48,7 +48,7 @@ export class FcModelService {
this.modelValidation = modelValidation; this.modelValidation = modelValidation;
this.model = model; this.model = model;
this.modelChanged = modelChanged; this.modelChanged = modelChanged;
this.cd = cd; this.detectChangesSubject = detectChangesSubject;
this.canvasHtmlElement = canvasHtmlElement; this.canvasHtmlElement = canvasHtmlElement;
this.svgHtmlElement = svgHtmlElement; this.svgHtmlElement = svgHtmlElement;
this.modelValidation.validateModel(this.model); this.modelValidation.validateModel(this.model);
...@@ -75,7 +75,7 @@ export class FcModelService { ...@@ -75,7 +75,7 @@ export class FcModelService {
public detectChanges() { public detectChanges() {
setTimeout(() => { setTimeout(() => {
this.cd.detectChanges(); this.detectChangesSubject.next();
}, 0); }, 0);
} }
...@@ -231,15 +231,6 @@ export class FcModelService { ...@@ -231,15 +231,6 @@ export class FcModelService {
} }
return this.dragImage; return this.dragImage;
} }
public registerCallbacks(edgeAddedCallback: (edge: FcEdge) => void,
nodeRemovedCallback: (node: FcNode) => void,
edgeRemovedCallback: (edge: FcEdge) => void) {
this.edgeAddedCallback = edgeAddedCallback;
this.nodeRemovedCallback = nodeRemovedCallback;
this.edgeRemovedCallback = edgeRemovedCallback;
}
} }
interface HtmlElementMap { [id: string]: HTMLElement; } interface HtmlElementMap { [id: string]: HTMLElement; }
......
...@@ -20,6 +20,8 @@ import { FcEdgeDraggingService } from './edge-dragging.service'; ...@@ -20,6 +20,8 @@ import { FcEdgeDraggingService } from './edge-dragging.service';
import { FcMouseOverService } from './mouseover.service'; import { FcMouseOverService } from './mouseover.service';
import { FcRectangleSelectService } from './rectangleselect.service'; import { FcRectangleSelectService } from './rectangleselect.service';
import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { Subject } from 'rxjs';
import { debounceTime } from 'rxjs/operators';
@Component({ @Component({
selector: 'fc-canvas', selector: 'fc-canvas',
...@@ -96,6 +98,8 @@ export class NgxFlowchartComponent implements OnInit, DoCheck { ...@@ -96,6 +98,8 @@ export class NgxFlowchartComponent implements OnInit, DoCheck {
return item; return item;
}); });
private readonly detectChangesSubject = new Subject<any>();
constructor(private elementRef: ElementRef<HTMLElement>, constructor(private elementRef: ElementRef<HTMLElement>,
private differs: IterableDiffers, private differs: IterableDiffers,
private modelValidation: FcModelValidationService, private modelValidation: FcModelValidationService,
...@@ -104,6 +108,9 @@ export class NgxFlowchartComponent implements OnInit, DoCheck { ...@@ -104,6 +108,9 @@ export class NgxFlowchartComponent implements OnInit, DoCheck {
private zone: NgZone) { private zone: NgZone) {
this.arrowDefId = 'arrow-' + Math.random(); this.arrowDefId = 'arrow-' + Math.random();
this.arrowDefIdSelected = this.arrowDefId + '-selected'; this.arrowDefIdSelected = this.arrowDefId + '-selected';
this.detectChangesSubject
.pipe(debounceTime(50))
.subscribe(() => this.cd.detectChanges());
} }
ngOnInit() { ngOnInit() {
...@@ -127,7 +134,8 @@ export class NgxFlowchartComponent implements OnInit, DoCheck { ...@@ -127,7 +134,8 @@ export class NgxFlowchartComponent implements OnInit, DoCheck {
const element = $(this.elementRef.nativeElement); const element = $(this.elementRef.nativeElement);
this.modelService = new FcModelService(this.modelValidation, this.model, this.modelChanged, this.cd, this.selectedObjects, this.modelService = new FcModelService(this.modelValidation, this.model, this.modelChanged,
this.detectChangesSubject, this.selectedObjects,
this.userCallbacks.dropNode, this.userCallbacks.createEdge, this.userCallbacks.edgeAdded, this.userCallbacks.nodeRemoved, this.userCallbacks.dropNode, this.userCallbacks.createEdge, this.userCallbacks.edgeAdded, this.userCallbacks.nodeRemoved,
this.userCallbacks.edgeRemoved, element[0], element[0].querySelector('svg')); this.userCallbacks.edgeRemoved, element[0], element[0].querySelector('svg'));
...@@ -197,7 +205,7 @@ export class NgxFlowchartComponent implements OnInit, DoCheck { ...@@ -197,7 +205,7 @@ export class NgxFlowchartComponent implements OnInit, DoCheck {
this.adjustCanvasSize(this.fitModelSizeByDefault); this.adjustCanvasSize(this.fitModelSizeByDefault);
} }
if (nodesChanged || edgesChanged) { if (nodesChanged || edgesChanged) {
this.cd.detectChanges(); this.detectChangesSubject.next();
} }
} }
} }
......
...@@ -131,7 +131,7 @@ class BaseError { ...@@ -131,7 +131,7 @@ class BaseError {
} }
} }
BaseError.prototype = new Error(); Object.defineProperty(BaseError, 'prototype', new Error());
export class ModelvalidationError extends BaseError { export class ModelvalidationError extends BaseError {
constructor(public message: string) { constructor(public message: string) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment