1
0
mirror of https://github.com/flarum/core.git synced 2025-08-08 01:16:52 +02:00

Create new objects with spread when modifying vnode children instead of directly setting children when possible.

This commit is contained in:
Alexander Skvortsov
2020-08-15 19:07:13 -04:00
committed by Franz Liedke
parent 32e9fa1f0b
commit 015cedb29d
8 changed files with 26 additions and 47 deletions

View File

@@ -11,10 +11,6 @@ import LinkButton from '../../common/components/LinkButton';
export default class AdminLinkButton extends LinkButton { export default class AdminLinkButton extends LinkButton {
getButtonContent(children) { getButtonContent(children) {
const content = super.getButtonContent(children); return [...super.getButtonContent(children), <div className="AdminLinkButton-description">{this.attrs.description}</div>];
content.push(<div className="AdminLinkButton-description">{this.attrs.description}</div>);
return content;
} }
} }

View File

@@ -28,18 +28,8 @@ export default class AppearancePage extends Page {
<div className="helpText">{app.translator.trans('core.admin.appearance.colors_text')}</div> <div className="helpText">{app.translator.trans('core.admin.appearance.colors_text')}</div>
<div className="AppearancePage-colors-input"> <div className="AppearancePage-colors-input">
<input <input className="FormControl" type="text" placeholder="#aaaaaa" bidi={this.primaryColor} />
className="FormControl" <input className="FormControl" type="text" placeholder="#aaaaaa" bidi={this.secondaryColor} />
type="text"
placeholder="#aaaaaa"
bidi={this.primaryColor}
/>
<input
className="FormControl"
type="text"
placeholder="#aaaaaa"
bidi={this.secondaryColor}
/>
</div> </div>
{Switch.component( {Switch.component(

View File

@@ -40,7 +40,7 @@ export default class PermissionDropdown extends Dropdown {
} }
view(vnode) { view(vnode) {
vnode.children = []; const children = [];
let groupIds = app.data.permissions[this.attrs.permission] || []; let groupIds = app.data.permissions[this.attrs.permission] || [];
@@ -60,7 +60,7 @@ export default class PermissionDropdown extends Dropdown {
if (this.showing) { if (this.showing) {
if (this.attrs.allowGuest) { if (this.attrs.allowGuest) {
vnode.children.push( children.push(
Button.component( Button.component(
{ {
icon: everyone ? 'fas fa-check' : true, icon: everyone ? 'fas fa-check' : true,
@@ -72,7 +72,7 @@ export default class PermissionDropdown extends Dropdown {
); );
} }
vnode.children.push( children.push(
Button.component( Button.component(
{ {
icon: members ? 'fas fa-check' : true, icon: members ? 'fas fa-check' : true,
@@ -98,7 +98,7 @@ export default class PermissionDropdown extends Dropdown {
); );
[].push.apply( [].push.apply(
vnode.children, children,
app.store app.store
.all('groups') .all('groups')
.filter((group) => [Group.ADMINISTRATOR_ID, Group.GUEST_ID, Group.MEMBER_ID].indexOf(group.id()) === -1) .filter((group) => [Group.ADMINISTRATOR_ID, Group.GUEST_ID, Group.MEMBER_ID].indexOf(group.id()) === -1)
@@ -118,7 +118,7 @@ export default class PermissionDropdown extends Dropdown {
); );
} }
return super.view(vnode); return super.view({ ...vnode, children });
} }
save(groupIds) { save(groupIds) {

View File

@@ -18,9 +18,7 @@ export default class SessionDropdown extends Dropdown {
} }
view(vnode) { view(vnode) {
vnode.children = this.items().toArray(); return super.view({ ...vnode, children: this.items().toArray() });
return super.view(vnode);
} }
getButtonContent() { getButtonContent() {

View File

@@ -13,19 +13,20 @@ export default class SettingDropdown extends SelectDropdown {
} }
view(vnode) { view(vnode) {
vnode.children = this.attrs.options.map(({ value, label }) => { return super.view({
const active = app.data.settings[this.attrs.key] === value; ...vnode,
children: this.attrs.options.map(({ value, label }) => {
const active = app.data.settings[this.attrs.key] === value;
return Button.component( return Button.component(
{ {
icon: active ? 'fas fa-check' : true, icon: active ? 'fas fa-check' : true,
onclick: saveSettings.bind(this, { [this.attrs.key]: value }), onclick: saveSettings.bind(this, { [this.attrs.key]: value }),
active, active,
}, },
label label
); );
}),
}); });
return super.view(vnode);
} }
} }

View File

@@ -9,22 +9,20 @@ export default class UploadImageButton extends Button {
if (app.data.settings[this.attrs.name + '_path']) { if (app.data.settings[this.attrs.name + '_path']) {
this.attrs.onclick = this.remove.bind(this); this.attrs.onclick = this.remove.bind(this);
vnode.children = app.translator.trans('core.admin.upload_image.remove_button');
return ( return (
<div> <div>
<p> <p>
<img src={app.forum.attribute(this.attrs.name + 'Url')} alt="" /> <img src={app.forum.attribute(this.attrs.name + 'Url')} alt="" />
</p> </p>
<p>{super.view(vnode)}</p> <p>{super.view({ ...vnode, children: app.translator.trans('core.admin.upload_image.remove_button') })}</p>
</div> </div>
); );
} else { } else {
this.attrs.onclick = this.upload.bind(this); this.attrs.onclick = this.upload.bind(this);
vnode.children = app.translator.trans('core.admin.upload_image.upload_button');
} }
return super.view(vnode); return super.view({ ...vnode, children: app.translator.trans('core.admin.upload_image.upload_button')});
} }
/** /**

View File

@@ -20,9 +20,7 @@ export default class SessionDropdown extends Dropdown {
} }
view(vnode) { view(vnode) {
vnode.children = this.items().toArray(); return super.view({ ...vnode, children: this.items().toArray() });
return super.view(vnode);
} }
getButtonContent() { getButtonContent() {

View File

@@ -57,9 +57,7 @@ export default function alertEmailConfirmation(app) {
view(vnode) { view(vnode) {
const vdom = super.view(vnode); const vdom = super.view(vnode);
vdom.children = [<div className="container">{vdom.children}</div>]; return { ...vdom, children: [<div className="container">{vdom.children}</div>]};
return vdom;
} }
} }