Repository: tradingview/lightweight-charts (ts)

Issue:
`Delegate.unsubscribeAll` method works in opposite way
### Discussed in https://github.com/tradingview/lightweight-charts/discussions/994

<div type='discussions-op-text'>

<sup>Originally posted by **zaleGZL** January 31, 2022</sup>
https://github.com/tradingview/lightweight-charts/blob/1d49f27ce7aa130ae0579dfdbb4ee2b7494c6c4e/src/helpers/delegate.ts#L30

should listener.linkedObject !== linkedObject  ?</div>

Pull request description:
fix: Delegate.unsubscribeAll method works in opposite way #995
**Type of PR:** bugfix

Fixes #995



Patch:
diff --git a/src/helpers/delegate.ts b/src/helpers/delegate.ts
index 0f3384c42..e0953dded 100644
--- a/src/helpers/delegate.ts
+++ b/src/helpers/delegate.ts
@@ -27,7 +27,7 @@ export class Delegate<T1 = void, T2 = void> implements ISubscription<T1, T2> {
 	}
 
 	public unsubscribeAll(linkedObject: unknown): void {
-		this._listeners = this._listeners.filter((listener: Listener<T1, T2>) => listener.linkedObject === linkedObject);
+		this._listeners = this._listeners.filter((listener: Listener<T1, T2>) => listener.linkedObject !== linkedObject);
 	}
 
 	public fire(param1: T1, param2: T2): void {


Test patch:
diff --git a/tests/unittests/delegate.spec.ts b/tests/unittests/delegate.spec.ts
new file mode 100644
index 000000000..46fb4a912
--- /dev/null
+++ b/tests/unittests/delegate.spec.ts
@@ -0,0 +1,21 @@
+import { expect } from 'chai';
+import { describe, it } from 'mocha';
+
+import { Delegate } from '../../src/helpers/delegate';
+
+describe('Delegate', () => {
+	it('unsubscribeAll', () => {
+		const linkedObjectOne = {};
+		const linkedObjectTwo = {};
+		const eventDelegate: Delegate = new Delegate();
+		eventDelegate.subscribe(() => {}, linkedObjectOne);
+
+		expect(eventDelegate.hasListeners()).to.be.equal(true);
+
+		eventDelegate.unsubscribeAll(linkedObjectTwo);
+		expect(eventDelegate.hasListeners()).to.be.equal(true);
+
+		eventDelegate.unsubscribeAll(linkedObjectOne);
+		expect(eventDelegate.hasListeners()).to.be.equal(false);
+	});
+});