From f220288be4408585fd9a34d34614de4e6a3074db Mon Sep 17 00:00:00 2001 From: Sebastien Jourdain Date: Tue, 2 Jan 2018 08:58:55 -0700 Subject: [PATCH] fix(QueryDataModel): Fix destroy method --- .eslintrc.js | 1 + src/IO/Core/QueryDataModel/index.js | 11 +++++++++-- .../Core/QueryDataModel/tests/testQueryDataModel.js | 11 +++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index d5a9983391..be0ef8d3b3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -21,6 +21,7 @@ module.exports = { 'react/no-unused-prop-types': 0, // Not for us ;-) + 'no-plusplus': 0, 'jsx-a11y/label-has-for': 0, 'no-console': 0, 'import/no-named-as-default-member': 0, diff --git a/src/IO/Core/QueryDataModel/index.js b/src/IO/Core/QueryDataModel/index.js index 7cb7396c3d..85b2da637a 100644 --- a/src/IO/Core/QueryDataModel/index.js +++ b/src/IO/Core/QueryDataModel/index.js @@ -83,6 +83,7 @@ export default class QueryDataModel { this.mouseListener = null; this.dataMetadata = {}; this.lazyFetchRequest = null; + this.registeredURLs = []; this.playNext = () => { if (this.keepAnimating) { @@ -224,6 +225,7 @@ export default class QueryDataModel { // Register data handler + listener dataManager.registerURL(dataId, (dataEntry.absolute ? '' : basepath) + dataEntry.pattern, dataEntry.type, dataEntry.mimeType); + this.registeredURLs.push(dataId); dataManager.on(dataId, dataHandler); this.dataCount[dataId] = 0; }); @@ -637,10 +639,15 @@ export default class QueryDataModel { } destroy() { - this.off(); - this.explorationSubscription.unsubscribe(); this.explorationSubscription = null; + + // Remove links to dataManager + while (this.registeredURLs.length) { + dataManager.unregisterURL(this.registeredURLs.pop()); + } + + this.off(); } // Data exploration ----------------------------------------------------------- diff --git a/src/IO/Core/QueryDataModel/tests/testQueryDataModel.js b/src/IO/Core/QueryDataModel/tests/testQueryDataModel.js index f1057ba8bd..94243a1a63 100644 --- a/src/IO/Core/QueryDataModel/tests/testQueryDataModel.js +++ b/src/IO/Core/QueryDataModel/tests/testQueryDataModel.js @@ -4,7 +4,7 @@ import QueryDataModel from '..'; // ---------------------------------------------------------------------------- -test('Query Data Model - Fetch/Notification', t => { +test('Query Data Model - Fetch/Notification', (t) => { const dataDescription = { type: ['tonic-query-data-model', 'slice-prober'], arguments: { @@ -59,12 +59,15 @@ test('Query Data Model - Fetch/Notification', t => { let notificationCount = 0; queryDataModel.onDataChange((data, envelope) => { - notificationCount++; + notificationCount += 1; t.ok(data && !data.error, `callback ${notificationCount}`); // Finish test if (numberOfRequests === notificationCount) { // console.log('Fetch/Notification: done with success'); + // Make sure we can destroy the queryDataModel + queryDataModel.destroy(); + t.ok(true, 'QueryDataModel deleted'); t.end(); } }); @@ -73,7 +76,7 @@ test('Query Data Model - Fetch/Notification', t => { let count = numberOfRequests; while (count--) { - fetchCount++; + fetchCount += 1; t.comment(`fetch ${fetchCount}`); queryDataModel.fetchData(); } @@ -81,7 +84,7 @@ test('Query Data Model - Fetch/Notification', t => { // ---------------------------------------------------------------------------- -test('Query Data Model - API/Query/Validation', t => { +test('Query Data Model - API/Query/Validation', (t) => { const dataDescription = { type: ['tonic-query-data-model'], arguments: {