-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add isSupportedEnvironment virtual member #2693
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact this method should probably be bound to the plugin's namespace, not instance, as it's done in tableselection
plugin.
If we add such method, lets refactor plugins at once. There are several plugins, that can use isSupportedEnvironment
function:
tableselection
(for now there is property, not method)easyimage
balloontoolbar
copyformatting
uploadwidget
- etc.
core/plugindefinition.js
Outdated
@@ -175,3 +175,28 @@ | |||
* @since 4.2 | |||
* @property {Boolean} hidpi | |||
*/ | |||
|
|||
/** | |||
* A virtual function which should be implemented if a plugin is not supported on every |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not virtual, it's very real 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://en.wikipedia.org/wiki/Virtual_function
However, taking into account that this function is not implemented by default, abstract
may better define its purpose.
Actually, I see that the whole pluginDefinition is marked as virtual
, so I will just skip modifier to not repeat it needlessly.
core/plugindefinition.js
Outdated
* } ); | ||
* ``` | ||
* | ||
* @since 4.11.2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably it would be better to introduce such change in next major release, 4.12.0, not in 4.11.2.
It would be nice to refactor all the plugins which has limited environment support. We need to ignore tests once |
I'm not sure if this member should be attached into plugin namespace. In that case, we are unable to unify this function among the plugins. AFAIK we don't have any recommendation nor abstract interface how to write a plugin namespace, so we will be unable to define it in our docs easily, which can be done with Also, if I have a simple plugin like CKEDITOR.plugins.autolink = {
isSupportedEnvironment: fn
};
CKEDITOR.plugins.add( autolink, {
init: function() { // init stuff }
} ); seems less coder friendly for me than just: CKEDITOR.plugins.add( autolink, {
init: function() { // init stuff },
isSupportedEnvironment: fn
} ); Currently, our options are:
|
I'd go with first option. I have one suggestion. If this method is optional, then maybe it should have default value if ( plugin.isSupportedEnvironment ) {
bender.ignore(); // or assert.ignore();
} |
I was also thinking about it. It also fixes the issue when you have to manually check if if ( plugin.isSupportedEnvironment && plugin.isSupportedEnvironment()) {
// do stuff
} |
I'm late to the party, but agree with @engineering-this on adding virtual method to |
It seems like it makes sense to pass an optional editor instance as an argument. It will complicate refactoring a bit, although some plugins require information about editor state. As an example, // Example for docprops
pluginDef.isSupportedEnvironment = function( editor ) {
return !editor.editable().isInline() && editor.config.fullPage;
} We could even extend this feature to automatically detect unsupported plugins and prevent executing initialization methods. |
I refactored Please, take a look if you are fine with the current changes and if so, I will continue refactoring/implementing support sniffing methods. |
Taking over review of this PR. |
Rebased on the latest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good 👍
I have one suggestion/idea. What if bender.tools.ignoreUnsupportedEnvironment()
method could be called automatically by bender without a need to add it in every test suite? You could just create a plugin with proper isSupportedEnvironment()
function and create tests without really thinking about correct ignoreUnsupportedEnvironment()
calls (tests may also have other plugins which can have env restriction and then one would have to check them, or just add all used plugins to ignoreUnsupportedEnvironment()
call).
From what I see the proper place to add such automatic call could be bender extensions where under tests
var you have current test suit (and can modify setUp calls
) and under bender.plugins
a list of plugins loaded for this test suite. WDYT? (Btw. This code is rn only for unit tests, so manual ones will need different place to hook in).
core/editor.js
Outdated
// Plugin is supported by default (#2692). | ||
plugin.isSupportedEnvironment = plugin.isSupportedEnvironment || function() { | ||
return true; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there any particular reason why this code was added here and not in plugin.js
, somewhere near: https://github.com/ckeditor/ckeditor-dev/blob/680bdd9f66dfa21e0822a1154573ddda743a1a75/core/plugins.js#L71 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onLoad
method may not be provided, but yeah it makes more sense to attach default method implementation inside core/plugins.js
file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onLoad
method may not be provided.
Yes, I meant the line above. It shouldn't depend on presence of onLoad
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the safest place is https://github.com/ckeditor/ckeditor-dev/blob/14e3bab99f1d4b968dd44e9b4e5b408e97b26758/core/plugins.js#L37 because it makes sure that the function won't be attached multiple times.
As we already talked F2F, there are some popular use cases where we cannot simply automate ignoring tests, like:
I updated an additional list of plugins. Please, tell if you still see some plugins requiring covering. |
Co-Authored-By: Krzysztof Krztoń <[email protected]>
What is the purpose of this pull request?
Task
Closes #2692