Skip to content

Commit

Permalink
Fix properties update works incorrectly when sync and async updates a…
Browse files Browse the repository at this point in the history
…re present
  • Loading branch information
dk981234 committed Apr 22, 2024
1 parent a4210eb commit 85aa2a6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/question_paneldynamic.ts
Expand Up @@ -599,12 +599,14 @@ export class QuestionPanelDynamicModel extends Question
}

public set renderedPanels(val: Array<PanelModel>) {
const oldAnimationAllowed = this.animationAllowed;
if(this.renderedPanels.length == 0 || val.length == 0) {
this._renderedPanels = val;
this.animationAllowed = false;
} else {
this.isPanelsAnimationRunning = true;
this.panelsAnimation.sync(val);
}
this.panelsAnimation.sync(val);
this.animationAllowed = oldAnimationAllowed;
}

public get renderedPanels(): Array<PanelModel> {
Expand Down
1 change: 1 addition & 0 deletions src/utils/animation.ts
Expand Up @@ -204,6 +204,7 @@ export abstract class AnimationProperty<T, S extends Array<any> = []> {
if(this.animationOptions.isAnimationEnabled()) {
this._debouncedSync.run(newValue);
} else {
this.cancel();
this.update(newValue);
}
}
Expand Down
41 changes: 41 additions & 0 deletions tests/utilstests.ts
Expand Up @@ -824,4 +824,45 @@ QUnit.test("Check onNextRender and cancel", (assert) => {

window.requestAnimationFrame = oldRequestAnimationFrame;
window.cancelAnimationFrame = oldCancelAnimationFrame;
});

QUnit.test("Test animation property: check latest update persists", (assert) => {
const done = assert.async();
let value: boolean = false;
let animationEnabled = false;
const animation = new AnimationBoolean({
getEnterOptions: () => {
return {
cssClass: "enter",
};
},
isAnimationEnabled: () => {
return animationEnabled;
},
getAnimatedElement: () => {
return undefined as any;
},
getLeaveOptions: () => {
return {
cssClass: "leave"
};
}
}, (val: boolean) => {
value = val;
}, () => value);
animationEnabled = true;
animation.sync(true);
animationEnabled = false;
animation.sync(false);
setTimeout(() => {
assert.notOk(value);
animationEnabled = false;
animation.sync(true);
assert.ok(value);
animation.sync(false);
setTimeout(() => {
assert.notOk(value);
done();
});
});
});

0 comments on commit 85aa2a6

Please sign in to comment.