From 35323a095afccd49ba548b88b97e07b701ccf53a Mon Sep 17 00:00:00 2001 From: Fabian Stamm Date: Thu, 11 Jun 2020 20:49:44 +0200 Subject: [PATCH] Fixing MemoryLeak --- package.json | 2 +- src/observable.ts | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index d9d7069..8a2381a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hibas123/utils", - "version": "2.2.4", + "version": "2.2.5", "description": "Different Utilities, that are not worth own packages", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/observable.ts b/src/observable.ts index dd77080..b6e8dcb 100755 --- a/src/observable.ts +++ b/src/observable.ts @@ -96,15 +96,17 @@ export default class Observable { console.error(err); } }); - this.events.push(data); - if (!this.timeout && this.subscriberCollect.length > 0) { - this.timeout = setTimeout(() => { - this.subscriberCollect.forEach((cb) => { - cb(this.events); - }); - this.events = []; - this.timeout = undefined; - }, this.collect_intervall); + if (this.subscribeCollect.length > 0) { + this.events.push(data); + if (!this.timeout) { + this.timeout = setTimeout(() => { + this.subscriberCollect.forEach((cb) => { + cb(this.events); + }); + this.events = []; + this.timeout = undefined; + }, this.collect_intervall); + } } }