@reactive-js/disposable
Advanced tools
Comparing version 0.0.18 to 0.0.19
@@ -28,3 +28,10 @@ "use strict"; | ||
for (const d of disposables) { | ||
this.doAdd(d); | ||
if (!this.disposables.includes(d)) { | ||
this.disposables.push(d); | ||
if (!(d instanceof Function)) { | ||
d.add(() => { | ||
this.doRemove(d); | ||
}); | ||
} | ||
} | ||
} | ||
@@ -37,6 +44,7 @@ } | ||
this.isDisposed = true; | ||
for (const disposable of this.disposables) { | ||
let disposable = this.disposables.shift(); | ||
while (disposable !== undefined) { | ||
doDispose(disposable); | ||
disposable = this.disposables.shift(); | ||
} | ||
this.disposables.length = 0; | ||
} | ||
@@ -47,3 +55,5 @@ } | ||
for (const d of disposables) { | ||
this.doRemove(d); | ||
if (this.doRemove(d)) { | ||
doDispose(d); | ||
} | ||
} | ||
@@ -53,13 +63,11 @@ } | ||
} | ||
doAdd(disposable) { | ||
if (!this.disposables.includes(disposable)) { | ||
this.disposables.push(disposable); | ||
} | ||
} | ||
doRemove(disposable) { | ||
const index = this.disposables.indexOf(disposable); | ||
doRemove(d) { | ||
const index = this.disposables.indexOf(d); | ||
if (index > -1) { | ||
const [old] = this.disposables.splice(index, 1); | ||
doDispose(old); | ||
this.disposables.splice(index, 1); | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
@@ -66,0 +74,0 @@ } |
@@ -26,3 +26,10 @@ const doDispose = (disposable) => { | ||
for (const d of disposables) { | ||
this.doAdd(d); | ||
if (!this.disposables.includes(d)) { | ||
this.disposables.push(d); | ||
if (!(d instanceof Function)) { | ||
d.add(() => { | ||
this.doRemove(d); | ||
}); | ||
} | ||
} | ||
} | ||
@@ -35,6 +42,7 @@ } | ||
this.isDisposed = true; | ||
for (const disposable of this.disposables) { | ||
let disposable = this.disposables.shift(); | ||
while (disposable !== undefined) { | ||
doDispose(disposable); | ||
disposable = this.disposables.shift(); | ||
} | ||
this.disposables.length = 0; | ||
} | ||
@@ -45,3 +53,5 @@ } | ||
for (const d of disposables) { | ||
this.doRemove(d); | ||
if (this.doRemove(d)) { | ||
doDispose(d); | ||
} | ||
} | ||
@@ -51,13 +61,11 @@ } | ||
} | ||
doAdd(disposable) { | ||
if (!this.disposables.includes(disposable)) { | ||
this.disposables.push(disposable); | ||
} | ||
} | ||
doRemove(disposable) { | ||
const index = this.disposables.indexOf(disposable); | ||
doRemove(d) { | ||
const index = this.disposables.indexOf(d); | ||
if (index > -1) { | ||
const [old] = this.disposables.splice(index, 1); | ||
doDispose(old); | ||
this.disposables.splice(index, 1); | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
@@ -64,0 +72,0 @@ } |
{ | ||
"name": "@reactive-js/disposable", | ||
"version": "0.0.18", | ||
"version": "0.0.19", | ||
"main": "dist/cjs/index.js", | ||
@@ -65,3 +65,3 @@ "module": "dist/esm5/index.js", | ||
}, | ||
"gitHead": "65fcf45e6866e6aed3c207c90bdd13a09b0961e3" | ||
"gitHead": "fe0fe2eb19f54f103e64a4679266e3aea4c62194" | ||
} |
@@ -65,5 +65,14 @@ export type DisposableOrTeardown = DisposableLike | (() => void); | ||
for (const d of disposables) { | ||
this.doAdd(d); | ||
if (!this.disposables.includes(d)) { | ||
this.disposables.push(d); | ||
if (!(d instanceof Function)) { | ||
d.add(() => { | ||
this.doRemove(d); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
return this; | ||
@@ -76,7 +85,7 @@ } | ||
for (const disposable of this.disposables) { | ||
let disposable = this.disposables.shift(); | ||
while (disposable !== undefined) { | ||
doDispose(disposable); | ||
disposable = this.disposables.shift(); | ||
} | ||
this.disposables.length = 0; | ||
} | ||
@@ -88,3 +97,5 @@ } | ||
for (const d of disposables) { | ||
this.doRemove(d); | ||
if (this.doRemove(d)) { | ||
doDispose(d); | ||
} | ||
} | ||
@@ -95,13 +106,10 @@ } | ||
private doAdd(disposable: DisposableOrTeardown) { | ||
if (!this.disposables.includes(disposable)) { | ||
this.disposables.push(disposable); | ||
} | ||
} | ||
private doRemove(d: DisposableOrTeardown): boolean { | ||
const index = this.disposables.indexOf(d); | ||
private doRemove(disposable: DisposableOrTeardown) { | ||
const index = this.disposables.indexOf(disposable); | ||
if (index > -1) { | ||
const [old] = this.disposables.splice(index, 1); | ||
doDispose(old); | ||
this.disposables.splice(index, 1); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
@@ -151,2 +159,3 @@ } | ||
}; | ||
/** | ||
@@ -153,0 +162,0 @@ * A Disposable container that allows replacing a contained Disposable with another, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
349437
573