react-native-meteor
Advanced tools
Comparing version 1.0.0-beta24 to 1.0.0-beta25
{ | ||
"name": "react-native-meteor", | ||
"version": "1.0.0-beta24", | ||
"version": "1.0.0-beta25", | ||
"description": "Full Meteor Client for React Native", | ||
@@ -5,0 +5,0 @@ "main": "src/Meteor.js", |
@@ -43,8 +43,8 @@ # react-native-meteor [](https://www.npmjs.org/package/react-native-meteor) [](http://badge.fury.io/js/react-native-meteor) [](https://david-dm.org/inProgress-team/react-native-meteor) | ||
} | ||
startMeteorSubscriptions() { | ||
Meteor.subscribe('todos'); | ||
getMeteorData() { | ||
const handle = Meteor.subscribe('todos'); | ||
Meteor.subscribe('settings'); | ||
} | ||
getMeteorData() { | ||
return { | ||
todosReady: handle.ready(), | ||
settings: Meteor.collection('settings').findOne() | ||
@@ -59,6 +59,8 @@ }; | ||
render() { | ||
const { settings } = this.data; | ||
const { settings, todosReady } = this.data; | ||
<View> | ||
<Text>{settings.title}</Text> | ||
{!todosReady && <Text>Not ready</Text>} | ||
<MeteorListView | ||
@@ -79,12 +81,12 @@ collection="todos" | ||
## startMeteorSubscriptions | ||
## getMeteorData | ||
Inside this method, you can create subscriptions (see below) when component is mounted. It will automatically unsubscribe if the component is unmounted. | ||
* [Meteor.subscribe](http://docs.meteor.com/#/full/meteor_subscribe) | ||
* [Meteor.subscribe](http://docs.meteor.com/#/full/meteor_subscribe) : returns an handle | ||
## getMeteorData | ||
Inside getMeteorData, you can also access any Meteor reactive data source, which means : | ||
Inside getMeteorData, you can access any Meteor reactive data source, which means : | ||
* Meteor.subscribe handle | ||
* Meteor.collection(collectionName) | ||
@@ -100,2 +102,4 @@ * [.find(selector, options)](http://docs.meteor.com/#/full/find) | ||
These methods (except update) work offline. That means that elements are correctly updated offline, and when you reconnect to ddp, Meteor calls are taken care of. | ||
* Meteor.collection(collectionName) | ||
@@ -102,0 +106,0 @@ * [.insert(doc, callback)](http://docs.meteor.com/#/full/insert) |
@@ -59,3 +59,3 @@ 'use strict'; | ||
return ( | ||
<Image style={styles.hidden} key={item._id} onLoadEnd={()=>console.log('LOADED IMAGE')} source={{uri: item.url()}} /> | ||
<Image style={styles.hidden} key={item._id} source={{uri: item.url()}} /> | ||
); | ||
@@ -62,0 +62,0 @@ })} |
@@ -17,3 +17,3 @@ import Trackr from 'trackr'; | ||
if(this.startMeteorSubscriptions) { | ||
console.warn('startMeteorSubscriptions is deprecated and will be removed soon. Please create your subscriptions in getMeteorData'); | ||
console.warn('startMeteorSubscriptions is deprecated and will be removed soon. Please create your subscriptions in getMeteorData.'); | ||
this._meteorSubscriptionsManager = new MeteorSubscriptionsManager(this); | ||
@@ -20,0 +20,0 @@ this._meteorSubscriptionsManager.getMeteorSubscriptions(); |
@@ -121,3 +121,5 @@ | ||
const sub = Data.subscriptions[i]; | ||
//console.log(sub.name, EJSON.clone(sub.params), sub.subIdRemember); | ||
sub.ready = true; | ||
sub.readyDeps.changed(); | ||
sub.readyCallback && sub.readyCallback(); | ||
} | ||
@@ -195,2 +197,11 @@ | ||
if (callbacks.onReady) { | ||
// If the sub is not already ready, replace any ready callback with the | ||
// one provided now. (It's not really clear what users would expect for | ||
// an onReady callback inside an autorun; the semantics we provide is | ||
// that at the time the sub first becomes ready, we call the last | ||
// onReady callback provided, if any.) | ||
if (!existing.ready) | ||
existing.readyCallback = callbacks.onReady; | ||
} | ||
if (callbacks.onStop) { | ||
@@ -214,2 +225,4 @@ existing.stopCallback = callbacks.onStop; | ||
ready: false, | ||
readyDeps: new Trackr.Dependency, | ||
readyCallback: callbacks.onReady, | ||
stopCallback: callbacks.onStop, | ||
@@ -219,2 +232,3 @@ stop: function() { | ||
delete Data.subscriptions[this.id]; | ||
this.ready && this.readyDeps.changed(); | ||
@@ -237,3 +251,7 @@ if (callbacks.onStop) { | ||
ready: function () { | ||
//TODO | ||
if (!Data.subscriptions[id]) return false; | ||
var record = Data.subscriptions[id]; | ||
record.readyDeps.depend(); | ||
return record.ready; | ||
}, | ||
@@ -240,0 +258,0 @@ subscriptionId: id |
48048
1178
207