1
0
mirror of https://github.com/flarum/core.git synced 2025-08-08 17:36:38 +02:00

update: forum/components/Post

- attrs has been renamed to elementAttrs
- As subtree retention is now implemented via onbeforeupdate, view no longer needs to return a retain vnode, and as such, has been significantly simplified
This commit is contained in:
Alexander Skvortsov
2020-08-09 23:02:31 -04:00
committed by Franz Liedke
parent fa2301b5c1
commit 37a690833a

View File

@@ -10,14 +10,16 @@ import ItemList from '../../common/utils/ItemList';
* includes a controls dropdown; subclasses must implement `content` and `attrs` * includes a controls dropdown; subclasses must implement `content` and `attrs`
* methods. * methods.
* *
* ### Props * ### Attrs
* *
* - `post` * - `post`
* *
* @abstract * @abstract
*/ */
export default class Post extends Component { export default class Post extends Component {
init() { oninit(vnode) {
super.oninit(vnode);
this.loading = false; this.loading = false;
/** /**
@@ -27,9 +29,9 @@ export default class Post extends Component {
* @type {SubtreeRetainer} * @type {SubtreeRetainer}
*/ */
this.subtree = new SubtreeRetainer( this.subtree = new SubtreeRetainer(
() => this.props.post.freshness, () => this.attrs.post.freshness,
() => { () => {
const user = this.props.post.user(); const user = this.attrs.post.user();
return user && user.freshness; return user && user.freshness;
}, },
() => this.controlsOpen () => this.controlsOpen
@@ -37,17 +39,14 @@ export default class Post extends Component {
} }
view() { view() {
const attrs = this.attrs(); const attrs = this.elementAttrs();
attrs.className = this.classes(attrs.className).join(' '); attrs.className = this.classes(attrs.className).join(' ');
return ( const controls = PostControls.controls(this.attrs.post, this).toArray();
<article {...attrs}>
{this.subtree.retain() ||
(() => {
const controls = PostControls.controls(this.props.post, this).toArray();
return ( return (
<article {...attrs}>
<div> <div>
{this.content()} {this.content()}
<aside className="Post-actions"> <aside className="Post-actions">
@@ -75,13 +74,17 @@ export default class Post extends Component {
<ul>{listItems(this.footerItems().toArray())}</ul> <ul>{listItems(this.footerItems().toArray())}</ul>
</footer> </footer>
</div> </div>
);
})()}
</article> </article>
); );
} }
config(isInitialized) { onbeforeupdate(vnode) {
super.onbeforeupdate(vnode);
return this.subtree.needsRebuild();
}
onupdate(vnode) {
const $actions = this.$('.Post-actions'); const $actions = this.$('.Post-actions');
const $controls = this.$('.Post-controls'); const $controls = this.$('.Post-controls');
@@ -93,7 +96,7 @@ export default class Post extends Component {
* *
* @return {Object} * @return {Object}
*/ */
attrs() { elementAttrs() {
return {}; return {};
} }
@@ -115,8 +118,8 @@ export default class Post extends Component {
classes(existing) { classes(existing) {
let classes = (existing || '').split(' ').concat(['Post']); let classes = (existing || '').split(' ').concat(['Post']);
const user = this.props.post.user(); const user = this.attrs.post.user();
const discussion = this.props.post.discussion(); const discussion = this.attrs.post.discussion();
if (this.loading) { if (this.loading) {
classes.push('Post--loading'); classes.push('Post--loading');