Skip to content

Commit

Permalink
Merge pull request #414 from Kitware/fix-query-datamodel-destroy
Browse files Browse the repository at this point in the history
fix(QueryDataModel): Fix destroy method
  • Loading branch information
jourdain authored Jan 2, 2018
2 parents 09a2010 + f220288 commit ed43866
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions src/IO/Core/QueryDataModel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export default class QueryDataModel {
this.mouseListener = null;
this.dataMetadata = {};
this.lazyFetchRequest = null;
this.registeredURLs = [];

this.playNext = () => {
if (this.keepAnimating) {
Expand Down Expand Up @@ -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;
});
Expand Down Expand Up @@ -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 -----------------------------------------------------------
Expand Down
11 changes: 7 additions & 4 deletions src/IO/Core/QueryDataModel/tests/testQueryDataModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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();
}
});
Expand All @@ -73,15 +76,15 @@ test('Query Data Model - Fetch/Notification', t => {

let count = numberOfRequests;
while (count--) {
fetchCount++;
fetchCount += 1;
t.comment(`fetch ${fetchCount}`);
queryDataModel.fetchData();
}
});

// ----------------------------------------------------------------------------

test('Query Data Model - API/Query/Validation', t => {
test('Query Data Model - API/Query/Validation', (t) => {
const dataDescription = {
type: ['tonic-query-data-model'],
arguments: {
Expand Down

0 comments on commit ed43866

Please sign in to comment.