From abedeed32389d8eee1d654d7a828bbe94d5dd945 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Mon, 14 Aug 2023 19:12:48 +0400 Subject: [PATCH] Update CanvasSpots events --- src/canvas/index.ts | 5 +---- src/canvas/model/CanvasSpots.ts | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/canvas/index.ts b/src/canvas/index.ts index 2dc8a476b..846934545 100644 --- a/src/canvas/index.ts +++ b/src/canvas/index.ts @@ -751,7 +751,6 @@ export default class CanvasModule extends Module { this.spots.add(spot, opts); return spot; - // 'canvas:spot' } getSpots(spotProps: Partial = {}) { @@ -760,13 +759,11 @@ export default class CanvasModule extends Module { removeSpot(spotProps: Partial = {}) { const spots = this.getSpots(spotProps); - console.log('removeSpot', { + console.log('removeSpot4', { spotProps, spots, }); return this.spots.remove(spots); - // 'canvas:spot:remove' - // 'canvas:spot' // remove all spots: canvas.getSpots().forEach(spot => canvas.removeSpot(spot)) } } diff --git a/src/canvas/model/CanvasSpots.ts b/src/canvas/model/CanvasSpots.ts index d5814bb28..bae72fd6c 100644 --- a/src/canvas/model/CanvasSpots.ts +++ b/src/canvas/model/CanvasSpots.ts @@ -1,5 +1,6 @@ import CanvasModule from '..'; import { ModuleCollection } from '../../abstract'; +import { ObjectAny } from '../../common'; import CanvasSpot, { CanvasSpotProps } from './CanvasSpot'; export default class CanvasSpots extends ModuleCollection { @@ -7,17 +8,29 @@ export default class CanvasSpots extends ModuleCollection { super(module, models, CanvasSpot); this.on('add', this.onAdd); this.on('change', this.onChange); + this.on('remove', this.onRemove); + } + + __trgEvent(event: string, props: ObjectAny) { + const { module, events } = this; + const { em } = module; + em.trigger(event, props); + em.trigger(events.spot); + } + + get events() { + return this.module.events; } onAdd(spot: CanvasSpot) { - const { module } = this; - const { em, events } = module; - em.trigger(events.spotAdd, { spot }); + this.__trgEvent(this.events.spotAdd, { spot }); } onChange(spot: CanvasSpot) { - const { module } = this; - const { em, events } = module; - em.trigger(events.spotUpdate, { spot }); + this.__trgEvent(this.events.spotUpdate, { spot }); + } + + onRemove(spot: CanvasSpot) { + this.__trgEvent(this.events.spotRemove, { spot }); } }