Skip to content

Commit 76691e1

Browse files
Added interval for compiling component preview on changes.
This fixes the issue where components like match that have many parts slowed down noticeably when a lot of text were inputted. Before, the preview was updating with each change. The interval acts like a debounce. #2949
1 parent fca14e4 commit 76691e1

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/main/webapp/wise5/authoringTool/components/preview-component/previewComponent.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { ProjectService } from '../../../services/projectService';
44
class PreviewComponentController {
55
componentContent: any;
66
componentId: string;
7+
isDirty: boolean;
78
nodeId: string;
9+
updateInterval: any;
810

911
static $inject = ['$scope', '$compile', '$element', 'NodeService', 'ProjectService'];
1012

@@ -23,19 +25,30 @@ class PreviewComponentController {
2325
);
2426
this.$scope.nodeId = this.nodeId;
2527
this.$scope.type = this.componentContent.type;
28+
this.compileComponent();
2629
this.$scope.$watch(
2730
() => {
2831
return this.componentContent;
2932
},
3033
() => {
31-
this.$scope.componentContent = this.ProjectService.injectAssetPaths(this.componentContent);
32-
this.compileComponent();
34+
this.isDirty = true;
3335
},
3436
true
3537
);
38+
this.updateInterval = setInterval(() => {
39+
if (this.isDirty) {
40+
this.compileComponent();
41+
this.isDirty = false;
42+
}
43+
}, 3000);
44+
}
45+
46+
$onDestroy() {
47+
clearInterval(this.updateInterval);
3648
}
3749

3850
compileComponent() {
51+
this.$scope.componentContent = this.ProjectService.injectAssetPaths(this.componentContent);
3952
const componentHTML = `<div class="component__wrapper">
4053
<div ng-include="::componentTemplatePath" class="component__content component__content--{{::type}}"></div>
4154
</div>`;

0 commit comments

Comments
 (0)