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

i/4992: Used the new Collection and View API to add multiple Views at a time #250

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/ui/linkformview.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export default class LinkFormView extends View {
* @returns {module:ui/viewcollection~ViewCollection} of switch buttons.
*/
_createManualDecoratorSwitches( manualDecorators ) {
const switches = this.createCollection();
const switches = [];

for ( const manualDecorator of manualDecorators ) {
const switchButton = new SwitchButtonView( this.locale );
Expand All @@ -279,10 +279,10 @@ export default class LinkFormView extends View {
manualDecorator.set( 'value', !switchButton.isOn );
} );

switches.add( switchButton );
switches.push( switchButton );
}

return switches;
return this.createCollection( switches );
}

/**
Expand All @@ -298,9 +298,7 @@ export default class LinkFormView extends View {
* @returns {module:ui/viewcollection~ViewCollection} The children of link form view.
*/
_createFormChildren( manualDecorators ) {
const children = this.createCollection();

children.add( this.urlInputView );
const children = [ this.urlInputView ];

if ( manualDecorators.length ) {
const additionalButtonsView = new View();
Expand All @@ -325,13 +323,13 @@ export default class LinkFormView extends View {
]
}
} );
children.add( additionalButtonsView );

children.push( additionalButtonsView );
}

children.add( this.saveButtonView );
children.add( this.cancelButtonView );
children.push( this.saveButtonView, this.cancelButtonView );

return children;
return this.createCollection( children );
}
}

Expand Down
48 changes: 25 additions & 23 deletions tests/ui/linkformview.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,29 +196,31 @@ describe( 'LinkFormView', () => {
let view, collection;
beforeEach( () => {
collection = new Collection();
collection.add( new ManualDecorator( {
id: 'decorator1',
label: 'Foo',
attributes: {
foo: 'bar'
}
} ) );
collection.add( new ManualDecorator( {
id: 'decorator2',
label: 'Download',
attributes: {
download: 'download'
}
} ) );
collection.add( new ManualDecorator( {
id: 'decorator3',
label: 'Multi',
attributes: {
class: 'fancy-class',
target: '_blank',
rel: 'noopener noreferrer'
}
} ) );
collection.add(
new ManualDecorator( {
id: 'decorator1',
label: 'Foo',
attributes: {
foo: 'bar'
}
} ),
new ManualDecorator( {
id: 'decorator2',
label: 'Download',
attributes: {
download: 'download'
}
} ),
new ManualDecorator( {
id: 'decorator3',
label: 'Multi',
attributes: {
class: 'fancy-class',
target: '_blank',
rel: 'noopener noreferrer'
}
} )
);

view = new LinkFormView( { t: val => val }, collection );
view.render();
Expand Down