Skip to content

Commit

Permalink
Don't trigger child updates when children unchanged
Browse files Browse the repository at this point in the history
  • Loading branch information
dqnykamp authored and jaltekruse committed Feb 27, 2023
1 parent 4b20665 commit 786bb41
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
4 changes: 3 additions & 1 deletion cypress/e2e/DoenetML/tagSpecific/answer.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18288,7 +18288,7 @@ describe('Answer Tag Tests', function () {
</choiceInput>

</sideBySide>
<copy prop='selectedValue' target='choice1' />
<copy prop='selectedValue' target='choice1' assignNames="sv" />

<answer>
<award><when><copy prop='selectedValue' target='choice1' /> = 4</when></award>
Expand All @@ -18304,6 +18304,7 @@ describe('Answer Tag Tests', function () {

cy.log("Select correct answer")
cy.get('#\\/choice1').select(`4`);
cy.get('#\\/sv').should('have.text', '4');
cy.get('#\\/_answer1_submit').invoke('text').then((text) => {
expect(text.trim().toLowerCase()).equal('check work')
})
Expand All @@ -18319,6 +18320,7 @@ describe('Answer Tag Tests', function () {

cy.log("Select incorrect answer and submit")
cy.get('#\\/choice1').select(`3`);
cy.get('#\\/sv').should('have.text', '3');
cy.get('#\\/_answer1_submit').click();
cy.get('#\\/_answer1_incorrect').invoke('text').then((text) => {
expect(text.trim().toLowerCase()).equal('incorrect')
Expand Down
24 changes: 13 additions & 11 deletions src/Core/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,11 @@ export default class Core {
parent.unexpandedCompositesReady = result.unexpandedCompositesReady;
parent.unexpandedCompositesNotReady = result.unexpandedCompositesNotReady;

let previousActiveChildren;

if (parent.activeChildren) {
previousActiveChildren = parent.activeChildren.map(child => child.componentName ? child.componentName : child);
}

parent.activeChildren = parent.definingChildren.slice(); // shallow copy

Expand Down Expand Up @@ -1575,7 +1580,13 @@ export default class Core {


if (parent.constructor.renderChildren) {
this.componentsWithChangedChildrenToRender.add(parent.componentName);
let childrenUnchanged = previousActiveChildren && previousActiveChildren.length == parent.activeChildren.length
&& parent.activeChildren.every(
(child, ind) => child.componentName ? child.componentName === previousActiveChildren[ind] : child === previousActiveChildren[ind]
);
if (!childrenUnchanged) {
this.componentsWithChangedChildrenToRender.add(parent.componentName);
}
}

return childGroupResults;
Expand Down Expand Up @@ -8407,7 +8418,7 @@ export default class Core {
// as even if changes were prevented, the renderers need to be given that information
// so they can revert if the showed the changes before hearing back from core
if (!canSkipUpdatingRenderer) {
updateInstructions.forEach(comp => this.updateInfo.componentsToUpdateRenderers.add(comp.componentName));
updateInstructions.forEach(comp => { if (comp.componentName) { this.updateInfo.componentsToUpdateRenderers.add(comp.componentName) } });
}

let componentNamesToUpdate = [...this.updateInfo.componentsToUpdateRenderers];
Expand All @@ -8420,15 +8431,6 @@ export default class Core {
});


if (this.updateInfo.componentsToUpdateRenderers.size > 0) {
// remove any names that were just updated
// (which can happen if tried to expand composites while updating renderers)

for (let cName of componentNamesToUpdate) {
this.updateInfo.componentsToUpdateRenderers.delete(cName);
}
}


// updating renderer instructions could trigger more composite updates
// (presumably from deriving child results)
Expand Down

0 comments on commit 786bb41

Please sign in to comment.