mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-08 07:48:02 +08:00
33 lines
634 B
JavaScript
33 lines
634 B
JavaScript
|
|
function disposeOne(disposable) {
|
|
if (disposable && 'function' === typeof disposable.dispose) {
|
|
disposable.dispose();
|
|
}
|
|
}
|
|
|
|
export class AbstractModel {
|
|
sModelName = '';
|
|
disposables = [];
|
|
|
|
/**
|
|
* @param {string} modelName = ''
|
|
*/
|
|
constructor(modelName = '') {
|
|
this.sModelName = modelName || '';
|
|
}
|
|
|
|
regDisposables(value) {
|
|
if (Array.isArray(value)) {
|
|
value.forEach(item => this.disposables.push(item));
|
|
} else if (value) {
|
|
this.disposables.push(value);
|
|
}
|
|
}
|
|
|
|
onDestroy() {
|
|
if (Array.isArray(this.disposables)) {
|
|
this.disposables.forEach(disposeOne);
|
|
}
|
|
Object.values(this).forEach(disposeOne);
|
|
}
|
|
}
|