-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
What is the best way to block observable propertie's value? #4964
Comments
More I think about it, more I feel that changing the observable value in I propose to define some of the observable properties to be
Such properties will not fire one, but two events. The first one will be fired before the change happens, will contain the new value in
In such solution both new and old values are available: new as if Note that only some properties should be
We should not overuse this mechanism. |
I would call it |
Yeah. AFAIR Something similar is in Backbone ( |
On a plus side of having it for every property is that it would make the code a little easier extendable. Of course, it adds overhead, but I don't think a lot of it. I'd go with having this for every property. This is the easiest solution too. |
Feature: Introduced `beforeChange:{property}` event in `ObservableMixin`. Closes #171.
Internal: Used `beforeChange` instead of `change` to force disabling commands in read-only mode. Closes https://github.com/ckeditor/ckeditor5-utils/issues/171.
This is a common practice e.g. when one feature wants to control a state of another feature's command.
See https://github.com/ckeditor/ckeditor5-core/blob/4d768dff3facd329b881859a4b831d2dd6a3e3f4/tests/command.js#L118-L135
It overrides some property and then ensures that no one changes it back.
In that test I used a high priority listener and stopped the event so the change of the property value is not visible to the normal listeners.
However, this breaks bindings because they rely on normal priority listeners.
So another option is to listen with a low priority listener and to not stop the event. This will fix the bindings but it means that the change event is visible twice. It's hard to predict implications of that. Infinite loops or blinking UI are possible.
So, what's the best way to achieve:
The text was updated successfully, but these errors were encountered: