发布数据并从React Native Client订阅后,大约需要一分钟才能准备好订阅。如果我更新collection,则又需要大约一分钟来获取数据并触发componentWillReceiveProps(newProps)方法。Collection只有很少的文档。
流星服务器代码:
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import { ArtWorks } from './database/artworks';
import { Gallerys } from './database/gallerys';
import { PlayerData } from './database/playerdata';
import { Questions } from './database/questions';
import { Relics } from './database/relics';
import { RelicsOnMap } from './database/relicsonmap';
Meteor.startup(() => {
});
Meteor.publish('getRelicsOnMap', function getRelicsOnMap (){
console.log("publishing...")
return RelicsOnMap.find({});
});
RelicsOnMap集合:
import { Mongo } from 'meteor/mongo';
export const RelicsOnMap = new Mongo.Collection('relicsonmap');
客户:
import React, { Component } from 'react';
import { View } from 'react-native';
import {
Container,
Header,
Title,
Content,
Button,
Item,
Input,
Body,
Left,
Right,
Icon,
Form,
Text,
Spinner,
Toast
} from "native-base";
import Meteor,{withTracker} from 'react-native-meteor';
class ProfileScreen extends Component {
constructor(props) {
super(props);
this.userData;
this.state = {
};
}
componentDidMount(){
console.log(this.props)
}
componentWillReceiveProps(newProps){
console.log(newProps)
}
render() {
return (
<Container>
<Text>This is Profile screen</Text>
<Text>This is Profile screen</Text>
</Container>
);
}
}
export default withTracker(params => {
Meteor.subscribe('getRelicsOnMap');
return {
relicsOnMap: Meteor.collection('relicsonmap').find({})
};
})(ProfileScreen);
我在另一个组件中执行Meteor.connect并且成功。 这里有一个小视频演示了这个问题: http://sendvid.com/v5fqlurh
答案 0 :(得分:0)
我发现反应本地远程调试器会导致此问题。当我未连接到我的本地网络以通过Google chrome进行调试时,一切都很好。我想这是一个错误。