-
Notifications
You must be signed in to change notification settings - Fork 18
Added support for initializing ViewCollection and BodyCollection items using a constructor #545
Conversation
…ion. Ported changes from ckeditor/ckeditor5-utils#309 (1aac49db1ca9ea914f9fc44f00e295474faf3ed2). Note this breaks BodyCollection integration, so there's more work to be done.
…is is where it is added. Next commit will remove locale handling from the ViewCollection class.
…correctly." This reverts commit 8843250.
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:
all:
|
* @returns {module:ui/viewcollection~ViewCollection} A new collection of view instances. | ||
*/ | ||
createCollection() { | ||
const collection = new ViewCollection(); | ||
createCollection( views ) { |
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.
Missing docs for the usage with views
.
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.
Addressed in e470ac5.
* | ||
* @member {module:utils/locale~Locale} | ||
*/ | ||
this.locale = locale; |
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 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.
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.
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 ) { |
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.
How can a View
have no #element
if it's been just rendered in :204?
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.
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 ); |
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 see no test that verifies that initialItems
is passed to the ViewCollection#constructor
.
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.
Addressed in c71c323
Also, we should review all places that do |
…roperly handling preinitialized collection items.
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. |
Suggested merge commit message (convention)
Feature: Added support for initializing
ViewCollection
andBodyCollection
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 thelocale
property.MAJOR BREAKING CHANGE:
ViewCollection
's constructor no longer takes thelocale
as a parameter.Additional information
This PR was mostly based on #524 with some notable changes:
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.