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

Bound view roots to model roots. #1233

Merged
merged 15 commits into from
Jan 11, 2018
Merged

Bound view roots to model roots. #1233

merged 15 commits into from
Jan 11, 2018

Conversation

oskarwrobel
Copy link
Contributor

@oskarwrobel oskarwrobel commented Jan 10, 2018

Suggested merge commit message (convention)

Fix: Bound collection of view roots to collection of model roots. Closes https://github.com/ckeditor/ckeditor5-core/issues/110.

BREAKING CHANGE: view/Document#roots and model/Document#roots now are Collection instances.
BREAKING CHANGE view/Document#createRoot is removed in favor of roots collections binding.
BREAKING CHANGE: view/Model#hasRoot is removed in favor of view/Model#getRoot.
BREAKING CHANGE: EditingController#createRoot is removed.


Part of: ckeditor/ckeditor5-core#114

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 99.72% when pulling 5e74fb1 on t/ckeditor5-core/110 into 2592bf1 on master.

@@ -31,6 +32,10 @@ import mix from '@ckeditor/ckeditor5-utils/src/mix';
* including selection handling. It also creates {@link ~EditingController#view view document} which build a
* browser-independent virtualization over the DOM elements. Editing controller also attach default converters.
*
* Editing controller binds {@link module:engine/view/document~Document#roots view roots collection} to
Copy link

Choose a reason for hiding this comment

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

I don't think this is essential for the class overview. I believe this is an implementation detail. Even if, right now, this is an important behavior, for the person who wants to learn what EditingController is, binging roots is the least important information. I would move this comment to the place where binding is implemented.

@@ -148,14 +149,18 @@ export default class Document {
/**
* Creates a new top-level root.
*
* **Note**: Creating model root automatically creates corresponding
* {@link module:engine/view/document~Document#roots view root} with the same name. Name of view root
* will be hanged later on when dom root will be {@link module:engine/view/document~Document#attachDomRoot attached}.
Copy link

Choose a reason for hiding this comment

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

I don't think we need to have such information in the model. The model has nothing to do with view and bing. The information in the editing controller and view is enough.

@@ -213,7 +218,7 @@ export default class Document {
* @returns {Boolean}
*/
hasRoot( name ) {
return this.roots.has( name );
return !!this.roots.get( name );
Copy link

Choose a reason for hiding this comment

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

Can we remove hasRoot method and replace its usage with getRoot (which should not throw but return falsy value if there is no such root? I feel that now when the collection does not have has method this code is ridiculous.

/**
* Overrides old element name and sets new one.
* This is needed because name of view root has to be changed as the same as dom root name
* when dom root is attached to view root.
Copy link

Choose a reason for hiding this comment

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

This is needed because view roots are created before they are attached to the DOM. The name of the root element is unknown at this stage. It has to be changed when the view root element is attached to the DOM element.

@@ -40,7 +42,8 @@ describe( 'advanced-converters', () => {

const editing = new EditingController( model );

viewRoot = editing.createRoot( 'div' );
editing.view.attachDomRoot( document.createElement( 'div' ) );
viewRoot = editing.view.getRoot();
Copy link

Choose a reason for hiding this comment

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

Can't you just set the name of the view root element without attaching it to the DOM (with a comment what is going on)? Tests which do not use DOM are usually more stable.

@@ -63,7 +65,7 @@ describe( 'Model converter builder', () => {
modelRoot = modelDoc.createRoot();

controller = new EditingController( model );
controller.createRoot( 'div' );
controller.view.attachDomRoot( document.createElement( 'div' ) );
Copy link

Choose a reason for hiding this comment

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

As above.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 99.72% when pulling 6f1dd9d on t/ckeditor5-core/110 into 2592bf1 on master.

@pjasiun pjasiun merged commit 6c388dd into master Jan 11, 2018
@pjasiun pjasiun deleted the t/ckeditor5-core/110 branch January 11, 2018 09:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants