2020-07-30 03:49:41 +08:00
|
|
|
|
|
|
|
function disposeOne(disposable) {
|
|
|
|
if (disposable && 'function' === typeof disposable.dispose) {
|
|
|
|
disposable.dispose();
|
|
|
|
}
|
|
|
|
}
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
export class AbstractModel {
|
2016-09-10 06:38:16 +08:00
|
|
|
sModelName = '';
|
|
|
|
disposables = [];
|
|
|
|
|
2016-07-07 05:03:30 +08:00
|
|
|
/**
|
2016-09-10 06:38:16 +08:00
|
|
|
* @param {string} modelName = ''
|
2016-07-07 05:03:30 +08:00
|
|
|
*/
|
2019-07-05 03:19:24 +08:00
|
|
|
constructor(modelName = '') {
|
2016-07-07 05:03:30 +08:00
|
|
|
this.sModelName = modelName || '';
|
|
|
|
}
|
|
|
|
|
|
|
|
regDisposables(value) {
|
2020-07-30 03:49:41 +08:00
|
|
|
if (Array.isArray(value)) {
|
2020-10-02 18:40:33 +08:00
|
|
|
value.forEach(item => this.disposables.push(item));
|
2019-07-05 03:19:24 +08:00
|
|
|
} else if (value) {
|
2016-07-07 05:03:30 +08:00
|
|
|
this.disposables.push(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
onDestroy() {
|
2020-07-30 03:49:41 +08:00
|
|
|
if (Array.isArray(this.disposables)) {
|
|
|
|
this.disposables.forEach(disposeOne);
|
|
|
|
}
|
|
|
|
Object.values(this).forEach(disposeOne);
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
}
|