fix(blocks): plugin's destroy() method will be called on blocks removing (#1719)

* Plugin's destroy() method on blocks removing

* Add changelog

Co-authored-by: Georgy Berezhnoy <gohabereg@gmail.com>
Co-authored-by: George Berezhnoy <gohabereg@users.noreply.github.com>
This commit is contained in:
Peter Savchenko 2021-07-21 21:50:16 +03:00 committed by GitHub
parent 6f36707f67
commit 9190824b1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 1 deletions

View file

@ -6,6 +6,7 @@
- `Improvement` *Tunes API* - Tunes now can provide sanitize configuration
- `Fix` *Tunes API* - Tune config now passed to constructor under `config` property
- `Fix` *Types* - Add common type for internal and external Tools configuration
- `Fix` — Block's destroy method is called on block deletion
### 2.22.1

View file

@ -439,6 +439,7 @@ export default class BlockManager extends Module {
const blockToRemove = this._blocks[index];
blockToRemove.destroy();
this._blocks.remove(index);
/**

View file

@ -1,3 +1,5 @@
import { isEmpty } from '../utils';
/**
* @class EventDispatcher
*
@ -68,7 +70,7 @@ export default class EventsDispatcher<Events extends string = string> {
* @param {object} data - subscribers get this data when they were fired
*/
public emit(eventName: Events, data?: object): void {
if (!this.subscribers[eventName]) {
if (isEmpty(this.subscribers) || !this.subscribers[eventName]) {
return;
}