Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit c19d9c5

Browse files
Briandeeg
Brian
authored andcommitted
perf(core): Debounce upate
Stops editor update from firing in rapid succession. Was an issue when updating after every character typed. Closes #226
1 parent 69071ee commit c19d9c5

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ We are always looking for the quality contributions and will be happy to accept
3333
* You have accompanying tests and all the tests are passing. See testing below.
3434
* Your PR doesn't break the build; check the Travis-CI build status after opening a PR and push corrective commits if anything goes wrong
3535
* You are using 2 space indentation
36-
* Your commits conform to the conventions established [here](https://github.com/ajoslin/conventional-changelog/blob/master/conventions/angular.md)
36+
* Your commits conform to the conventions established [here](https://github.com/stevemao/conventional-changelog-angular/blob/master/convention.md)
3737

3838

3939
## Testing

src/tinymce.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ angular.module('ui.tinymce', [])
5656

5757
angular.extend(expression, scope.$eval(attrs.uiTinymce));
5858

59+
//Debounce update and save action
60+
var debouncedUpdate = (function(debouncedUpdateDelay) {
61+
var debouncedUpdateTimer;
62+
return function(ed) {
63+
$timeout.cancel(debouncedUpdateTimer);
64+
debouncedUpdateTimer = $timeout(function() {
65+
return (function(ed) {
66+
ed.save();
67+
updateView(ed);
68+
})(ed);
69+
}, debouncedUpdateDelay);
70+
};
71+
})(400);
72+
5973
var setupOptions = {
6074
// Update model when calling setContent
6175
// (such as from the source editor popup)
@@ -75,8 +89,7 @@ angular.module('ui.tinymce', [])
7589
// - the node has changed [NodeChange]
7690
// - an object has been resized (table, image) [ObjectResized]
7791
ed.on('ExecCommand change NodeChange ObjectResized', function() {
78-
ed.save();
79-
updateView(ed);
92+
debouncedUpdate(ed);
8093
});
8194

8295
ed.on('blur', function() {

0 commit comments

Comments
 (0)