Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throttle update #8

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Throttle update #8

wants to merge 5 commits into from

Conversation

Manuel-S
Copy link
Contributor

@Manuel-S Manuel-S commented Jul 5, 2016

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 #7 but I wanted to open another pull request since this is an addition to the api.

Manuel-S added 5 commits June 29, 2016 16:27
Implemented the way the standard knockout bindings update values, which also updates plain properties if they're not observable.

This is needed to use the binding with knockout-es5 properties.
Since it is not exported (yet? knockout/knockout#2088 ), we use our own version of writeValueToProperty.
We also use _twoWayBindings as it is the exported collection.
improve the performance by caching the last "write" from the binding to the viewmodel and not trying to update tinymce if it is the same value that was just written.
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"`
@cmbankester
Copy link
Contributor

I don't think this adds any editor.getContent() avoidance after implementing the caching. Care to elaborate on the necessity of this functionality?

@Manuel-S
Copy link
Contributor Author

Manuel-S commented Jul 6, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants