mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-11-15 20:24:51 +08:00
ea48f5060b
isUnd(*) to native undefined === * isFunc to native typeof * === 'function' isObject to native typeof * === 'object' microtime() to native Date().getTime(); noop to native ()=>{} noopFalse to native ()=>false noopTrue to native ()=>true boolToAjax to native *?'1':'0' Underscore.js to native
35 lines
648 B
JavaScript
35 lines
648 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);
|
|
}
|
|
}
|