Skip to content

Commit

Permalink
Fix unnecessary view rendering when returning to the discovery page
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Sep 21, 2024
1 parent ee92022 commit c20b3c4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## next

- Fixed unnecessary view rendering when returning to the discovery page

## 1.0.0-beta.85 (15-09-2024)

- Changed `Widget#scheduleRender()` to schedule render for all subjects when no subject is specified (invoked without parameters)
Expand Down
29 changes: 17 additions & 12 deletions src/pages/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,22 @@ export default function(host) {
};
}

function acceptChanges(data) {
function actionQueryAcceptChanges(data) {
return data === lastPerformData;
}

function actionQuerySubquery(query, rootData) {
if (actionQueryAcceptChanges(rootData)) {
get().queryEditor.createSubquery(query);
}
}

function actionQueryAppend(query, rootData) {
if (actionQueryAcceptChanges(rootData)) {
get().queryEditor.appendToQuery(query);
}
}

let refs = null;
let lastRequest = null;
let lastPerformData = NaN; // used NaN to mismatch with any value
Expand All @@ -57,17 +69,10 @@ export default function(host) {
if (lastPageId !== host.pageId) {
if (host.pageId === host.discoveryPageId) {
// enter discovery page
host.action.define('queryAcceptChanges', acceptChanges);
host.action.define('querySubquery', (query, rootData) => {
if (acceptChanges(rootData)) {
get().queryEditor.createSubquery(query);
}
});
host.action.define('queryAppend', (query, rootData) => {
if (acceptChanges(rootData)) {
get().queryEditor.appendToQuery(query);
}
});
// Note: Don't define action functions in place to ensure context comparison works
host.action.define('queryAcceptChanges', actionQueryAcceptChanges);
host.action.define('querySubquery', actionQuerySubquery);
host.action.define('queryAppend', actionQueryAppend);
} else {
// leave discovery page
host.action.revoke('queryAcceptChanges');
Expand Down
4 changes: 0 additions & 4 deletions src/pages/discovery/editor-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,10 +661,6 @@ export default function(host, updateHostParams) {

scheduledCompute = null;

// while (Date.now() - startTime < 500) {
// //
// }

try {
computation.computed = host.query(computation.query, computation.data, computation.context);
computation.state = 'successful';
Expand Down
11 changes: 6 additions & 5 deletions src/pages/discovery/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ function filterDecodedParams(params) {
));
}

function isEqual(a, b, skipKey) {
function isEqual(a, b, ...skipKeys) {
for (const key of Object.keys(a)) {
if (key !== skipKey && a[key] !== b[key]) {
if (a[key] !== b[key] && !skipKeys.includes(key)) {
return false;
}
}

for (const key of Object.keys(b)) {
if (key !== skipKey && a[key] !== b[key]) {
if (a[key] !== b[key] && !skipKeys.includes(key)) {
return false;
}
}
Expand All @@ -97,8 +97,9 @@ export function contextWithoutEditorParams(newContext, currentContext = {}) {
params: filterDecodedParams(newContext.params)
};

if (!isEqual(currentContext, stableNewContext, 'params') ||
!isEqual(currentContext.params, stableNewContext.params)) {
if (!isEqual(currentContext, stableNewContext, 'params', 'actions') ||
!isEqual(currentContext.params, stableNewContext.params) ||
!isEqual(currentContext.actions, stableNewContext.actions)) {
return stableNewContext;
}

Expand Down

0 comments on commit c20b3c4

Please sign in to comment.