Skip to content
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

#1053 Introduce CKEDITOR.tools.object.merge #1055

Merged
merged 10 commits into from
Oct 17, 2017
Merged

#1053 Introduce CKEDITOR.tools.object.merge #1055

merged 10 commits into from
Oct 17, 2017

Conversation

Comandeer
Copy link
Member

What is the purpose of this pull request?

New feature

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

  • Unit tests
  • Manual tests

What changes did you make?

Introduce CKEDITOR.tools.object.merge, which merges two objects.

Closes #1053.

@Comandeer Comandeer requested a review from f1ames October 16, 2017 11:22
Copy link
Contributor

@mlewand mlewand left a comment

Choose a reason for hiding this comment

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

Just few comments.

core/tools.js Outdated

tools.array.forEach( tools.objectKeys( copy2 ), function( key ) {
if ( typeof copy2[ key ] === 'object' && typeof copy1[ key ] === 'object' ) {
copy1[ key ] = merge( copy1[ key ], copy2[ key ] );
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we use simply tools.merge? merge is defined in a hacky way, very uncommon to our code base.

core/tools.js Outdated
*/
merge: function merge( obj1, obj2 ) {
var copy1 = CKEDITOR.tools.clone( obj1 ),
copy2 = CKEDITOR.tools.clone( obj2 ),
Copy link
Contributor

Choose a reason for hiding this comment

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

both members could reuse tools that was defined just a line below.

},

/**
* Merges two objects and returns new one.
Copy link
Contributor

Choose a reason for hiding this comment

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

An example would on how it actually merges would be a brilliant idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good if example would also illustrate what happens if both objects have properties with the same name/key.

Copy link
Contributor

@f1ames f1ames left a comment

Choose a reason for hiding this comment

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

Just small changes suggested in comments.

@Comandeer do you think the merge function should do some type checking (if passed objects are really an objects, not array, null, etc) to prevent misuse?

},

/**
* Merges two objects and returns new one.
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good if example would also illustrate what happens if both objects have properties with the same name/key.

for ( var name in expected ) {
if ( expected.hasOwnProperty( name ) ) {
if ( expected[ name ] && typeof expected[ name ] === 'object' ) {
areDeepEqual( expected[ name ], actual[ name ] );
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as https://github.com/ckeditor/ckeditor-dev/pull/1055/files#r144820711, couldn't it be just bender.objectAssert.areDeepEqual( ... );

@Comandeer
Copy link
Member Author

do you think the merge function should do some type checking (if passed objects are really an objects, not array, null, etc) to prevent misuse?

There are no such checkings in other CKEDITOR.tools method. Method's name IMO is clear enough to allow us to skip them.

Copy link
Contributor

@f1ames f1ames left a comment

Choose a reason for hiding this comment

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

Only one tiny, but important detail to fix in docs.

core/tools.js Outdated
* }
*
* @param {Object} obj1 A base object.
* @param {Object} obj2 An object, which properties will be merged to the base one.
Copy link
Contributor

Choose a reason for hiding this comment

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

An object, which properties will be merged to the base one.

I think this is a little misleading, as properties are not merged to the base object, but to its copy, so the base object is not modified. And it is also inconsistent with method description which suggest the new object is created (Merges two objects and returns new one).

ATM I don't have any clear idea how it could be described. I checked in other libs/docs how it is described there:

but still not sure. Maybe you could come up with something reasonable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe something like that?

obj1 Source object, which will be used to create a new base object.

And then obj2 description is already good :D WDYT @f1ames?

Copy link
Contributor

Choose a reason for hiding this comment

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

@Comandeer works for me 👍

@Comandeer Comandeer requested a review from f1ames October 17, 2017 08:34
Copy link
Contributor

@f1ames f1ames left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@f1ames f1ames merged commit 19e23a4 into major Oct 17, 2017
@f1ames f1ames deleted the t/1053 branch October 17, 2017 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants