-
Notifications
You must be signed in to change notification settings - Fork 12
I/4992: Added support for creating a Collection
with initial items
#309
base: master
Are you sure you want to change the base?
Conversation
…ing multiple items to Collection#add().
…dded to the Collection.
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.
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 ) ) { |
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.
Unnecessary parentheses.
|
||
if ( typeof itemId != 'string' ) { | ||
/** | ||
* This item's id should be a string. |
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 item's id should be a string. | |
* This item's id must be a string. |
} ); | ||
} | ||
} else { | ||
item[ idProperty ] = itemId = uid(); |
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'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. |
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.
* @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 ) { |
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'd like to see constructor accepting more generic, Iterable
compliant values. This would allow using Set
s too.
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.
Me too :D
…ion. Ported changes from ckeditor/ckeditor5-utils#309 (1aac49db1ca9ea914f9fc44f00e295474faf3ed2). Note this breaks BodyCollection integration, so there's more work to be done.
…ion. Ported changes from ckeditor/ckeditor5-utils#309 (1aac49db1ca9ea914f9fc44f00e295474faf3ed2). Note this breaks BodyCollection integration, so there's more work to be done.
…ion. Ported changes from ckeditor/ckeditor5-utils#309 (1aac49db1ca9ea914f9fc44f00e295474faf3ed2). Note this breaks BodyCollection integration, so there's more work to be done.
Suggested merge commit message (convention)
Feature: Added support for creating a
Collection
with initial items and supplying multiple items toCollection#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.