From 1b5d839b6eb7c4d62653441d573b3cf7ef3c5cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?The=CC=81o=20mathieu?= Date: Thu, 24 Mar 2016 22:39:38 -0400 Subject: [PATCH] Fix issue 41 --- src/components/ComplexListView.js | 9 +++++++++ src/components/ListView.js | 19 ++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/components/ComplexListView.js b/src/components/ComplexListView.js index 3953ad7..2b1c6a0 100644 --- a/src/components/ComplexListView.js +++ b/src/components/ComplexListView.js @@ -24,6 +24,15 @@ export default class MeteorListView extends Component { }) }; } + componentWillReceiveProps(props) { + const { elements } = props; + + const elems = elements(); + this.setState({ + ds: this.state.ds.cloneWithRows(elems) + }); + + } componentWillMount() { const { elements } = this.props; diff --git a/src/components/ListView.js b/src/components/ListView.js index e0c7734..6cef67f 100644 --- a/src/components/ListView.js +++ b/src/components/ListView.js @@ -29,9 +29,22 @@ export default class MeteorListView extends Component { }) }; } + componentWillReceiveProps(props) { + const { collection, selector, options } = props; + + this.update(Data.db[collection].find(selector, options)); + } componentWillMount() { const { collection, selector, options } = this.props; + + this.update = results=>{ + this.setState({ + ds: this.state.ds.cloneWithRows(results) + }); + }; + + if(!Data.db[collection]) { Data.db.addCollection(collection) } @@ -40,11 +53,7 @@ export default class MeteorListView extends Component { return Data.db[collection].find(selector, options); }); - this.items.subscribe(results=>{ - this.setState({ - ds: this.state.ds.cloneWithRows(results) - }); - }); + this.items.subscribe(this.update); } componentWillUnmount() { this.items.dispose();