From cd5aba24e3f21f729692bf0bd0eb885b80c9ac49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?The=CC=81o=20mathieu?= Date: Sun, 20 Mar 2016 10:21:19 -0400 Subject: [PATCH] Fix #32 --- README.md | 2 +- package.json | 2 +- src/Data.js | 10 ++++++++++ src/components/Mixin.js | 23 +++++++++++++---------- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index bbd8ed4..f7b4ba1 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ # react-native-meteor -Meteor-like methods for React Native. **Currently in v1.0.0-beta17** ! For old docs, see [v0.6.2 documentation](https://github.com/inProgress-team/react-native-meteor/tree/0.6.2) (classic ddp interface). +Meteor-like methods for React Native. **Currently in v1.0.0-beta18** ! For old docs, see [v0.6.2 documentation](https://github.com/inProgress-team/react-native-meteor/tree/0.6.2) (classic ddp interface). ## What is it for ? diff --git a/package.json b/package.json index 9140682..d57157d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-meteor", - "version": "1.0.0-beta17", + "version": "1.0.0-beta18", "description": "DDP React-native Client", "main": "src/Meteor.js", "scripts": { diff --git a/src/Data.js b/src/Data.js index 33b9293..a20cbd2 100644 --- a/src/Data.js +++ b/src/Data.js @@ -14,6 +14,16 @@ export default { return this._endpoint.substring(0, this._endpoint.indexOf('/websocket')); }, + waitDdpReady(cb) { + if(this.ddp) { + cb(); + } else { + setTimeout(()=>{ + this.waitDdpReady(cb); + }, 10); + } + }, + _cbs: [], onChange(cb) { this.db.on('change', cb); diff --git a/src/components/Mixin.js b/src/components/Mixin.js index ea4fa4b..7019157 100644 --- a/src/components/Mixin.js +++ b/src/components/Mixin.js @@ -5,17 +5,20 @@ import Data from '../Data'; export default { componentWillMount() { - if(this.getMeteorData) { - this.data = {}; - this._meteorDataManager = new MeteorDataManager(this); - const newData = this._meteorDataManager.calculateData(); - this._meteorDataManager.updateData(newData); - } + Data.waitDdpReady(()=>{ + if(this.getMeteorData) { + this.data = {}; + this._meteorDataManager = new MeteorDataManager(this); + const newData = this._meteorDataManager.calculateData(); + this._meteorDataManager.updateData(newData); + } + + if(this.startMeteorSubscriptions) { + this._meteorSubscriptionsManager = new MeteorSubscriptionsManager(this); + this._meteorSubscriptionsManager.getMeteorSubscriptions(); + } + }); - if(this.startMeteorSubscriptions) { - this._meteorSubscriptionsManager = new MeteorSubscriptionsManager(this); - this._meteorSubscriptionsManager.getMeteorSubscriptions(); - } }, componentWillUpdate(nextProps, nextState) {