Open Manuel-S opened 8 years ago
I don't think this adds any editor.getContent()
avoidance after implementing the caching. Care to elaborate on the necessity of this functionality?
The caching takes care of not calling editor.getContent() when a change is inbound from the viewmodel that was just writting to it previously. This is actually a change in behaviour (and hence optional), that will not update the viewmodel more often than once every x milliseconds specified in the additional handler.
To clarify, before this change, every keyup-event will trigger an editor.getContent() which will then be written to the ko.observable. after this change, all keyup-events in the timespan of x seconds will result in only one call to editor.getContent() and write to the ko.observable.
And a note: the throttle function I use is only available on tinymce 4.x, that's why I put a guard around the call and default to the normal behaviour if the function is not available.
adds a "throttleValueUpdate" optional binding which will throttle the updates to the ko viewmodel by the number of ms specified in the binding.
This is pulled into the binding instead of just extending the observable because otherwise every keystroke will invoke editor.getContent() which is a non-trivial call and may take a while, depending on the content.
Usage:
data-bind="tinymce: val, throttleValueUpdate: 500"
note: this pull request also includes the proposed changes from https://github.com/immense/knockout-tinymce/pull/7 but I wanted to open another pull request since this is an addition to the api.