From 77e8cc8d4546d2e773cdac25be17237a86963bef Mon Sep 17 00:00:00 2001 From: igoradamenko Date: Tue, 13 Feb 2018 01:13:58 +0200 Subject: [PATCH] subscribe comments in root component state to store updates --- web/app/components/root/root.jsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/web/app/components/root/root.jsx b/web/app/components/root/root.jsx index 59884ceb..dc1531f9 100644 --- a/web/app/components/root/root.jsx +++ b/web/app/components/root/root.jsx @@ -8,6 +8,9 @@ import Comment from 'components/comment'; import Input from 'components/input'; import Thread from 'components/thread'; +// api.getConfig().then(console.log.bind(console)) +// api.getUser().then(console.log.bind(console)) + export default class Root extends Component { constructor(props) { super(props); @@ -19,16 +22,17 @@ export default class Root extends Component { this.addComment = this.addComment.bind(this); } + componentWillMount() { + store.onUpdate('comments', comments => this.setState({ comments })); + } + componentDidMount() { api.getUser() .then(data => store.set('user', data)) .catch(() => store.set('user', {})) .finally(() => { api.find({ url }) - .then(({ comments } = {}) => { - store.set('comments', comments); - this.setState({ comments }); - }) + .then(({ comments } = {}) => store.set('comments', comments)) .finally(() => this.setState({ loaded: true })); }); } @@ -58,7 +62,10 @@ export default class Root extends Component { return (
- + { !!pinnedComments.length && (