-
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
Promise support #2988
Promise support #2988
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.
core/promise/promise.js
Outdated
if ( window.Promise ) { | ||
CKEDITOR.tools.promise = Promise; | ||
} else { | ||
var script = new CKEDITOR.dom.element( 'script' ); |
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.
You can simplify it by using CKEDITOR.scriptLoader.load( src, callback );
.
if ( window.Promise ) { | ||
assert.areSame( window.Promise, CKEDITOR.tools.promise, 'Native Promise should be enabled' ); | ||
} else { | ||
assert.areSame( window.ES6Promise, CKEDITOR.tools.promise, 'Polyfill Promise should be enabled' ); |
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.
False positive case:
When polyfill library is not loaded test passes, as undefined === undefined
.
core/promise/promise.js
Outdated
* } ); | ||
* ``` | ||
* | ||
* @param {Function} resolver |
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.
Function params can be listed as attributes, like in CKEDITOR.tools.array.forEach
.
I realized the issue here - the whole I still would like to keep Please, see ckeditor/ckeditor4-docs#242 for the error code (you may wanna review this one also). |
}, | ||
|
||
// (#2962) | ||
'test missing promise polyfill': function() { |
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.
This test will fail in built version as CKEDITOR.loader
is absent because all core modules are bundled.
I think it should be reviewed after promise is merged. |
I'm wondering how to fix the test for built version #2988 (review) - maybe it's a hint for poorly written API? tl;dr Options which comes to my mind:
Honestly, I'm feeling like I did some overengineering here and there is no reason for an explicit error message. WDYT? |
Error message is helpful. I'd ignore test under condition: |
That would be a bit difficult to do during a testing phase, although I agree that we maybe could disable test for built version, as it's only testing if an error message occurs, not if a promise has been correctly loaded. |
Missing an error message doesn't really break things, so I'd just check it before merging PR. |
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.
LG2M 👍
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.
I wonder if we could move ES6Promise
js file from vendor
dir to adapters
dir. Well, this is not strictly an adapter, but now we have adapters
with one jquery
file and vendor
dir with one promise.js
file 🤔 (Btw. we cannot rename adapters
to not break backward compatibility).
When it comes to unit test, there are two test promise initialization
and test missing promise polyfill
. Do you think it would make sense to add e.g. one more test to assert how CKEDITOR.tools.promise
behaves? It will be testing native code / polyfill so I'm not sure. OTOH, if this test will start failing it means something changed in the implementation (not sure if it's probable).
I created vendor folder for such 3rd party libs. It seems to be included in a built version and additionally minified, so we can use the full version for debugging.
Is the content of this folder also minified during build?
If you are just worried about the additional folder, don't be - there is no filesystem limit we can exceed with that 😄 To be more serious - you already wrote that it's not adapter and in the future, we may have additional vendor libs with the same problem. It will be easier to keep 2 separate namespaces for that than always close eye for "not strictly adapter" argument. Although it's not something I want to fight for, if you still would like to move all vendor libs to
We are not testing the native Array object nor other types. I would make no exception here and keep it simple.
The Internet would fall with such breaking native API change 😄 I think we will be fine.
It is. |
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.
LGTM 👍
What is the purpose of this pull request?
Does your PR contain necessary tests?
All patches which change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.
This PR contains
What changes did you make?
After some research, it looks like ES6-Promise polyfill should suit our needs. It's pretty lightweight (6.17 KB / 2.4 KB gzipped) and seems to have the same API as native Promise. It's also recommended by MDN Promise docs.
Closes #2962