@reactive-js/disposable
Advanced tools
Comparing version 0.0.11 to 0.0.12
export declare type DisposableOrTeardown = DisposableLike | (() => void); | ||
export interface DisposableLike { | ||
readonly isDisposed: boolean; | ||
add(disposable: DisposableOrTeardown, ...disposables: DisposableOrTeardown[]): void; | ||
add(disposable: DisposableOrTeardown, ...disposables: DisposableOrTeardown[]): this; | ||
dispose(): void; | ||
remove(disposable: DisposableOrTeardown, ...disposables: DisposableOrTeardown[]): void; | ||
remove(disposable: DisposableOrTeardown, ...disposables: DisposableOrTeardown[]): this; | ||
} | ||
export declare const createDisposable: () => DisposableLike; | ||
export declare const createDisposable: (onDispose?: (() => void) | undefined) => DisposableLike; | ||
export declare const disposed: DisposableLike; | ||
@@ -10,0 +10,0 @@ export declare const throwIfDisposed: (disposable: DisposableLike) => void; |
@@ -34,2 +34,3 @@ "use strict"; | ||
} | ||
return this; | ||
} | ||
@@ -51,2 +52,3 @@ dispose() { | ||
} | ||
return this; | ||
} | ||
@@ -66,3 +68,9 @@ doAdd(disposable) { | ||
} | ||
exports.createDisposable = () => new DisposableImpl(); | ||
exports.createDisposable = (onDispose) => { | ||
const disposable = new DisposableImpl(); | ||
if (onDispose !== undefined) { | ||
disposable.add(onDispose); | ||
} | ||
return disposable; | ||
}; | ||
const _disposed = { | ||
@@ -73,6 +81,9 @@ add(...disposables) { | ||
} | ||
return _disposed; | ||
}, | ||
isDisposed: true, | ||
dispose() { }, | ||
remove(..._) { }, | ||
remove(..._) { | ||
return _disposed; | ||
}, | ||
}; | ||
@@ -101,4 +112,3 @@ exports.disposed = _disposed; | ||
if (oldDisposable !== newDisposable) { | ||
this.add(newDisposable); | ||
this.remove(oldDisposable); | ||
this.add(newDisposable).remove(oldDisposable); | ||
} | ||
@@ -105,0 +115,0 @@ } |
export declare type DisposableOrTeardown = DisposableLike | (() => void); | ||
export interface DisposableLike { | ||
readonly isDisposed: boolean; | ||
add(disposable: DisposableOrTeardown, ...disposables: DisposableOrTeardown[]): void; | ||
add(disposable: DisposableOrTeardown, ...disposables: DisposableOrTeardown[]): this; | ||
dispose(): void; | ||
remove(disposable: DisposableOrTeardown, ...disposables: DisposableOrTeardown[]): void; | ||
remove(disposable: DisposableOrTeardown, ...disposables: DisposableOrTeardown[]): this; | ||
} | ||
export declare const createDisposable: () => DisposableLike; | ||
export declare const createDisposable: (onDispose?: (() => void) | undefined) => DisposableLike; | ||
export declare const disposed: DisposableLike; | ||
@@ -10,0 +10,0 @@ export declare const throwIfDisposed: (disposable: DisposableLike) => void; |
@@ -32,2 +32,3 @@ const doDispose = (disposable) => { | ||
} | ||
return this; | ||
} | ||
@@ -49,2 +50,3 @@ dispose() { | ||
} | ||
return this; | ||
} | ||
@@ -64,3 +66,9 @@ doAdd(disposable) { | ||
} | ||
export const createDisposable = () => new DisposableImpl(); | ||
export const createDisposable = (onDispose) => { | ||
const disposable = new DisposableImpl(); | ||
if (onDispose !== undefined) { | ||
disposable.add(onDispose); | ||
} | ||
return disposable; | ||
}; | ||
const _disposed = { | ||
@@ -71,6 +79,9 @@ add(...disposables) { | ||
} | ||
return _disposed; | ||
}, | ||
isDisposed: true, | ||
dispose() { }, | ||
remove(..._) { }, | ||
remove(..._) { | ||
return _disposed; | ||
}, | ||
}; | ||
@@ -99,4 +110,3 @@ export const disposed = _disposed; | ||
if (oldDisposable !== newDisposable) { | ||
this.add(newDisposable); | ||
this.remove(oldDisposable); | ||
this.add(newDisposable).remove(oldDisposable); | ||
} | ||
@@ -103,0 +113,0 @@ } |
export declare type DisposableOrTeardown = DisposableLike | (() => void); | ||
export interface DisposableLike { | ||
readonly isDisposed: boolean; | ||
add(disposable: DisposableOrTeardown, ...disposables: DisposableOrTeardown[]): void; | ||
add(disposable: DisposableOrTeardown, ...disposables: DisposableOrTeardown[]): this; | ||
dispose(): void; | ||
remove(disposable: DisposableOrTeardown, ...disposables: DisposableOrTeardown[]): void; | ||
remove(disposable: DisposableOrTeardown, ...disposables: DisposableOrTeardown[]): this; | ||
} | ||
export declare const createDisposable: () => DisposableLike; | ||
export declare const createDisposable: (onDispose?: (() => void) | undefined) => DisposableLike; | ||
export declare const disposed: DisposableLike; | ||
@@ -10,0 +10,0 @@ export declare const throwIfDisposed: (disposable: DisposableLike) => void; |
@@ -36,3 +36,3 @@ | ||
▸ **add**(`disposable`: [DisposableOrTeardown](../README.md#disposableorteardown), ...`disposables`: [DisposableOrTeardown](../README.md#disposableorteardown)[]): *void* | ||
▸ **add**(`disposable`: [DisposableOrTeardown](../README.md#disposableorteardown), ...`disposables`: [DisposableOrTeardown](../README.md#disposableorteardown)[]): *this* | ||
@@ -48,3 +48,3 @@ Adds the given disposables to this container or disposes them if the container has been disposed. | ||
**Returns:** *void* | ||
**Returns:** *this* | ||
@@ -65,3 +65,3 @@ ___ | ||
▸ **remove**(`disposable`: [DisposableOrTeardown](../README.md#disposableorteardown), ...`disposables`: [DisposableOrTeardown](../README.md#disposableorteardown)[]): *void* | ||
▸ **remove**(`disposable`: [DisposableOrTeardown](../README.md#disposableorteardown), ...`disposables`: [DisposableOrTeardown](../README.md#disposableorteardown)[]): *this* | ||
@@ -77,2 +77,2 @@ Removes and disposes the given disposables if they are part of this container. | ||
**Returns:** *void* | ||
**Returns:** *this* |
@@ -43,6 +43,12 @@ | ||
▸ **createDisposable**(): *[DisposableLike](interfaces/disposablelike.md)* | ||
▸ **createDisposable**(`onDispose?`: undefined | function): *[DisposableLike](interfaces/disposablelike.md)* | ||
Creates an empty DisposableLike instance. | ||
**Parameters:** | ||
Name | Type | | ||
------ | ------ | | ||
`onDispose?` | undefined | function | | ||
**Returns:** *[DisposableLike](interfaces/disposablelike.md)* | ||
@@ -49,0 +55,0 @@ |
{ | ||
"name": "@reactive-js/disposable", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"main": "dist/cjs/index.js", | ||
@@ -65,3 +65,3 @@ "module": "dist/esm5/index.js", | ||
}, | ||
"gitHead": "894e4863ea037c317967555ebc27ab66167cfc59" | ||
"gitHead": "66ee9bfeeb79e01c9770dc09829bedf292674ff0" | ||
} |
@@ -21,3 +21,3 @@ export type DisposableOrTeardown = DisposableLike | (() => void); | ||
...disposables: DisposableOrTeardown[] | ||
): void; | ||
): this; | ||
@@ -38,3 +38,3 @@ /** | ||
...disposables: DisposableOrTeardown[] | ||
): void; | ||
): this; | ||
} | ||
@@ -74,2 +74,3 @@ | ||
} | ||
return this; | ||
} | ||
@@ -95,2 +96,3 @@ | ||
} | ||
return this; | ||
} | ||
@@ -116,3 +118,9 @@ | ||
*/ | ||
export const createDisposable = (): DisposableLike => new DisposableImpl(); | ||
export const createDisposable = (onDispose?: () => void): DisposableLike => { | ||
const disposable = new DisposableImpl(); | ||
if (onDispose !== undefined) { | ||
disposable.add(onDispose); | ||
} | ||
return disposable; | ||
}; | ||
@@ -124,6 +132,9 @@ const _disposed: DisposableLike = { | ||
} | ||
return _disposed; | ||
}, | ||
isDisposed: true, | ||
dispose() {}, | ||
remove(..._: DisposableOrTeardown[]) {}, | ||
remove(..._: DisposableOrTeardown[]) { | ||
return _disposed; | ||
}, | ||
}; | ||
@@ -173,4 +184,3 @@ | ||
if (oldDisposable !== newDisposable) { | ||
this.add(newDisposable); | ||
this.remove(oldDisposable); | ||
this.add(newDisposable).remove(oldDisposable); | ||
} | ||
@@ -177,0 +187,0 @@ } |
@@ -53,4 +53,3 @@ import { | ||
disposable.add(child); | ||
disposable.remove(child); | ||
disposable.add(child).remove(child); | ||
expect(child.isDisposed).toBeTruthy(); | ||
@@ -64,4 +63,3 @@ }); | ||
test("dispose when teardown throws an exception", () => { | ||
const disposable = createDisposable(); | ||
disposable.add(() => { | ||
const disposable = createDisposable(() => { | ||
throw new Error(); | ||
@@ -68,0 +66,0 @@ }); |
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
346057
559