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

I/4992: Added support for creating a Collection with initial items #309

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

oleq
Copy link
Member

@oleq oleq commented Oct 16, 2019

Suggested merge commit message (convention)

Feature: Added support for creating a Collection with initial items and supplying multiple items to Collection#add() (see ckeditor/ckeditor5#4992).


Other PRs:


CI


Couldn't find more use–cases but perhaps there are some that could benefit from the new API.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.001%) to 99.835% when pulling 28b9017 on i/4992 into 875d5a4 on master.

@oleq oleq marked this pull request as ready for review October 21, 2019 10:12
@jodator jodator self-assigned this Oct 29, 2019
@jodator jodator self-requested a review October 29, 2019 11:14
Copy link
Contributor

@jodator jodator left a comment

Choose a reason for hiding this comment

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

Minor R- because of code style and wording.

Also, I'd remove double assignment in _getItemIdBeforeAdding() but TBH it's not a big deal.

const idProperty = this._idProperty;
let itemId;

if ( ( idProperty in item ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary parentheses.


if ( typeof itemId != 'string' ) {
/**
* This item's id should be a string.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* This item's id should be a string.
* This item's id must be a string.

} );
}
} else {
item[ idProperty ] = itemId = uid();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fan of double assignments. Maybe move the itemId to the first if and always return item[ idProperty ]?

* @param {Object} item
* @param {Number} [index] The position of the item in the collection. The item
* is pushed to the collection when `index` not specified.
* @param {...(Object)} items Item or items to be added to the collection.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @param {...(Object)} items Item or items to be added to the collection.
* @param {...Object} items Item or items to be added to the collection.

constructor( initialItemsOrOptions = {}, options = {} ) {
let initialItems = [];

if ( initialItemsOrOptions instanceof Array ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to see constructor accepting more generic, Iterable compliant values. This would allow using Sets too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Me too :D

mlewand added a commit to ckeditor/ckeditor5-ui that referenced this pull request Feb 19, 2020
…ion.

Ported changes from ckeditor/ckeditor5-utils#309 (1aac49db1ca9ea914f9fc44f00e295474faf3ed2).

Note this breaks BodyCollection integration, so there's more work to be done.
mlewand added a commit that referenced this pull request Feb 19, 2020
panr pushed a commit to ckeditor/ckeditor5-ui that referenced this pull request Apr 7, 2020
…ion.

Ported changes from ckeditor/ckeditor5-utils#309 (1aac49db1ca9ea914f9fc44f00e295474faf3ed2).

Note this breaks BodyCollection integration, so there's more work to be done.
mlewand added a commit to ckeditor/ckeditor5 that referenced this pull request May 1, 2020
…ion.

Ported changes from ckeditor/ckeditor5-utils#309 (1aac49db1ca9ea914f9fc44f00e295474faf3ed2).

Note this breaks BodyCollection integration, so there's more work to be done.
@jodator jodator removed their assignment May 12, 2020
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.

4 participants