Skip to content

Commit

Permalink
Merge pull request #152 from devexperts/add-update-dynamic-object-method
Browse files Browse the repository at this point in the history
enhancement: add "updateObject" method to the dynamic objects model
  • Loading branch information
KirillBobkov authored Mar 5, 2024
2 parents 8b0cbbd + c57d86f commit 3b76dd7
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/chart/components/dynamic-objects/dynamic-objects.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ export class DynamicObjectsModel extends ChartBaseElement {
private _objects: BehaviorSubject<Record<PaneId, LinkedList<DynamicObject>>>;
private modelIdToObjectMap: Map<DynamicObjectId, DynamicObject> = new Map();

constructor(
private canvasModel: CanvasModel,
) {
constructor(private canvasModel: CanvasModel) {
super();
this._objects = new BehaviorSubject({});
}
Expand Down Expand Up @@ -68,7 +66,6 @@ export class DynamicObjectsModel extends ChartBaseElement {
/**
* Adds an object from outside chart-core into model
* @param obj
* @param paneId
*/
addObject(obj: DynamicObject) {
const paneId = obj.paneId;
Expand All @@ -84,8 +81,7 @@ export class DynamicObjectsModel extends ChartBaseElement {

/**
* Removes an object from model
* @param model
* @param paneId
* @param id
*/
removeObject(id: DynamicObjectId) {
const objInfo = this.getObjectInfoById(id);
Expand All @@ -105,6 +101,22 @@ export class DynamicObjectsModel extends ChartBaseElement {
this.setDynamicObjects(this.objects);
}

/**
* Updates an object
* @param obj
*/
updateObject(obj: DynamicObject) {
const objInfo = this.getObjectInfoById(obj.id);

if (!objInfo) {
return;
}

const [oldObj] = objInfo;
this.removeObject(oldObj.id);
this.addObject(obj);
}

/**
* Moves the object inside the associated LinkedList to the specified position
*/
Expand Down

0 comments on commit 3b76dd7

Please sign in to comment.