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

Commit

Permalink
Internal: Restored locale support for BodyCollection to work correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
mlewand committed Feb 19, 2020
1 parent bfe8744 commit 8843250
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/viewcollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
import Collection from '@ckeditor/ckeditor5-utils/src/collection';
import Locale from '@ckeditor/ckeditor5-utils/src/locale';

/**
* Collects {@link module:ui/view~View} instances.
Expand Down Expand Up @@ -53,8 +54,11 @@ export default class ViewCollection extends Collection {
*
* @param {Array.<module:ui/view~View>} [initialItems] The initial items of the collection.
*/
constructor( initialItems = [] ) {
super( initialItems, {
constructor( itemsOrLocale = [] ) {
const locale = itemsOrLocale instanceof Locale ? itemsOrLocale : new Locale();
const items = itemsOrLocale instanceof Locale ? [] : itemsOrLocale;

super( items, {
// An #id Number attribute should be legal and not break the `ViewCollection` instance.
// https://github.com/ckeditor/ckeditor5-ui/issues/93
idProperty: 'viewUid'
Expand All @@ -72,6 +76,14 @@ export default class ViewCollection extends Collection {
}
} );

/**
* The {@link module:core/editor/editor~Editor#locale editor's locale} instance.
* See the view {@link module:ui/view~View#locale locale} property.
*
* @member {module:utils/locale~Locale}
*/
this.locale = locale;

/**
* A parent element within which child views are rendered and managed in DOM.
*
Expand Down
3 changes: 2 additions & 1 deletion tests/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Collection from '@ckeditor/ckeditor5-utils/src/collection';
import ViewCollection from '../src/viewcollection';
import normalizeHtml from '@ckeditor/ckeditor5-utils/tests/_utils/normalizehtml';
import { assertCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
import Locale from '@ckeditor/ckeditor5-utils/src/locale';

let TestView, view, childA, childB;

Expand Down Expand Up @@ -63,7 +64,7 @@ describe( 'View', () => {
const collection = new ViewCollection();

expect( view.locale ).to.equal( locale );
expect( collection.locale ).to.be.undefined;
expect( collection.locale ).to.be.an.instanceOf( Locale );

view._viewCollections.add( collection );
expect( collection.locale ).to.equal( view.locale );
Expand Down

0 comments on commit 8843250

Please sign in to comment.