Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Added support for initializing ViewCollection and BodyCollection items using a constructor #545

Merged
merged 16 commits into from
Apr 6, 2020

Conversation

mlewand
Copy link
Contributor

@mlewand mlewand commented Feb 27, 2020

Suggested merge commit message (convention)

Feature: Added support for initializing ViewCollection and BodyCollection items using a constructor. See ckeditor/ckeditor5#6319.

The View.createCollection() method also accepts an iterator of views.

MAJOR BREAKING CHANGE: ViewCollection no longer has the locale property.

MAJOR BREAKING CHANGE: ViewCollection's constructor no longer takes the locale as a parameter.


Additional information

This PR was mostly based on #524 with some notable changes:

  • Back then we could have removed locale from all collections. Today locale is required by one Collection subclass - BodyCollection (it uses it to determine text direction). So it is only BodyCollection that contains this property.
  • ViewCollection / BodyCollection accepts any iterable of views, not just an array.

This PR requires a PR from utils to be working: ckeditor/ckeditor5-utils#326

After it's done, the master branch should be merged into #524 PR so that the diff there is much smaller and easier to review/finish it.

@mlewand
Copy link
Contributor Author

mlewand commented Feb 27, 2020

Not sure what's up with the code coverage as I'm having 100% CC both, when running UI module alone and all the tests (here technically it's 99.9% due to ckeditor/ckeditor5#6326):

UI module:

Chrome 80.0.3987 (Windows 10.0.0): Executed 868 of 868 SUCCESS (10.824 secs / 1.831 secs)

=============================== Coverage summary ===============================
Statements   : 100% ( 1575/1575 )
Branches     : 100% ( 604/604 )
Functions    : 100% ( 450/450 )
Lines        : 100% ( 1549/1549 )
================================================================================

all:

Chrome 80.0.3987 (Windows 10.0.0): Executed 13317 of 13339 (skipped 22) SUCCESS (6 mins 4.766 secs / 2 mins 5.142 secs)

=============================== Coverage summary ===============================
Statements   : 100% ( 18726/18726 )
Branches     : 99.99% ( 9621/9622 )
Functions    : 100% ( 4190/4190 )
Lines        : 100% ( 18447/18447 )
================================================================================

@coveralls
Copy link

coveralls commented Feb 27, 2020

Coverage Status

Coverage remained the same at 100.0% when pulling bd93bd0 on i/6319 into b30bdd9 on master.

@oleq oleq self-assigned this Mar 25, 2020
* @returns {module:ui/viewcollection~ViewCollection} A new collection of view instances.
*/
createCollection() {
const collection = new ViewCollection();
createCollection( views ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docs for the usage with views.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in e470ac5.

*
* @member {module:utils/locale~Locale}
*/
this.locale = locale;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it really obsolete? Because it does not feel like the scope of the PR. OTOH it makes the arguments discovery harder in the constructor(), that's why I'm asking.

Copy link
Contributor Author

@mlewand mlewand Apr 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you pointed out back in #524 - locale in ViewCollection has no usage in our codebase. However sine then BodyColleciton subclass has been introduced which does use it.

More on that in the PR main description:

Back then we could have removed locale from all collections. Today locale is required by one Collection subclass - BodyCollection (it uses it to determine text direction). So it is only BodyCollection that contains this property.

Because it does not feel like the scope of the PR

I do agree on the fact that it goes outside of the scope, I'm fine with extracting this - let me know if clarification are good enough or you'd prefer to extract it to a separate issue.

view.render();
}

if ( view.element && this._parentElement ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can a View have no #element if it's been just rendered in :204?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's unmodified original code from the master branch, it has just been extracted to a named method - and it wasn't really my intention to tackle issues not related with the issue.

Giving it a quick look the element could be unavailable if the view has no template sounds like an edge case, bot something that might happen? Eventually this refactoring might be extracted to a follow up in order not to block this PR.

* @param {Iterable.<module:ui/view~View>} [initialItems] The initial items of the collection.
*/
constructor( locale, initialItems = [] ) {
super( initialItems );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no test that verifies that initialItems is passed to the ViewCollection#constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in c71c323

@oleq
Copy link
Member

oleq commented Mar 27, 2020

Also, we should review all places that do createCollection or new ViewCollection and use the new API if possible. This may require some understanding of what's going on there, though.

@mlewand
Copy link
Contributor Author

mlewand commented Apr 3, 2020

Also, we should review all places that do createCollection or new ViewCollection and use the new API if possible. This may require some understanding of what's going on there, though.

There will be quite a few of these and indeed it will involve checking surrounding code, so I'd like to do that once there are no other remaining points for this PR.

@mlewand mlewand requested a review from oleq April 3, 2020 11:21
@oleq oleq merged commit 6cd15de into master Apr 6, 2020
@oleq oleq deleted the i/6319 branch April 6, 2020 13:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants