React-native-meteor package subscription handle not ready

て烟熏妆下的殇ゞ 提交于 2019-12-14 03:19:10

问题


I'm trying to combine react-native and meteor using the react-native-meteor package. Meteor successfully publishes a 'dos' collection, which I have been able to subscribe to on the web client. However, after following the documentation of the react-native-meteor package (using createContainer) I am unable to subscribe; the handle is 'never ready'. When using the autopublish package from Meteor the data does load.

Versions

Meteor 1.3.4.1

react-native: 0.28.0

react-native-meteor: 1.0.0-rc14

index.ios.js

// @flow
'use strict'

import React, { Component } from 'react'
import {
  AppRegistry,
  StyleSheet,
  View,
  NavigatorIOS,
  StatusBar,
  Text,
} from 'react-native'
import Meteor, {
  createContainer,
  MeteorListView,
 } from 'react-native-meteor'

Meteor.connect('ws://localhost:3000/websocket')

import GeoLocation from './app/GeoLocation'
import ConnectionInfoSubscription from './app/NetInfo'
import GridLayout from './app/GridLayout'

class DoCHANGE_0 extends Component {

  renderRow(Do){
    return(
      <Text>{Do.joke}</Text>
    )
  }

  render() {

    const { doList, } = this.props

    return (
      <View style={styles.container}>
      <StatusBar
        barStyle="light-content"
        />
      <NavigatorIOS
        style = {styles.container}
        barTintColor='#556270'
        titleTextColor='#fff'
        tintColor='#fff'
        initialRoute={{
          title: 'DoCHANGE',
          component: GridLayout
        }}/>

        {!doList && <Text>Not ready with subscription</Text>}
        <MeteorListView
        collection="dos"
        renderRow={this.renderRow}
        enableEmptySections={true}
        />

      </View>
    )
  }

}

const styles = StyleSheet.create({
  container: {
    flex:1,
  }
});

export default createContainer(params=>{
  const handle = Meteor.subscribe('dos')
  return {
    doList: handle.ready(),
  };
}, DoCHANGE_0)

AppRegistry.registerComponent('DoCHANGE_0', () => DoCHANGE_0);

I have found similar examples but they often don't utilise the react-native-meteor package but use the ddpclient package instead. Am I missing something obvious here? Any insights is much appreciated!

Edit:

(Meteor) /server/publish.js

 Meteor.publish("dos", function() {
   //console.log(Dos.find().fetch())
   return Dos.find();
 })

(Meteor) /both/collections.js

Dos = new Mongo.Collection('dos');

Screenshot when using autopublish from Meteor. doList handle is still not ready. But the MeteorList gets populated correctly.

Screenshot iOS autopublish on


回答1:


You only included client side code in your question, but it sounds like you are missing the Meteor.publish() call on the server, if it works using autopublish but not without it!




回答2:


I upgraded to newer versions of react-native, meteor, and react-native-meteor but that didn't solve the issue. However, when renaming the renderRow function to renderItem it started working.

renderRow={this.renderRow}

renderRow={this.renderItem}


来源:https://stackoverflow.com/questions/38170550/react-native-meteor-package-subscription-handle-not-ready

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!