Ecmascript 6 如何使用轮询方法获取新边缘?
我正在尝试无限滚动,只需增加第一个值即可。但是,我想从一开始就获取新的边。如果没有强制抓取,我如何才能做到这一点 这是我的RelayContainer,其中firstLoad和afterFirst使用别名引用具有不同参数的相同连接。中继之前不查询任何内容。我还从graphql服务器端将hasNextPage和hasPreviousPage强制设置为true 中继如何决定是否从服务器获取新边缘Ecmascript 6 如何使用轮询方法获取新边缘?,ecmascript-6,relayjs,Ecmascript 6,Relayjs,我正在尝试无限滚动,只需增加第一个值即可。但是,我想从一开始就获取新的边。如果没有强制抓取,我如何才能做到这一点 这是我的RelayContainer,其中firstLoad和afterFirst使用别名引用具有不同参数的相同连接。中继之前不查询任何内容。我还从graphql服务器端将hasNextPage和hasPreviousPage强制设置为true 中继如何决定是否从服务器获取新边缘 constructor(props) { super(props); if (!pr
constructor(props) {
super(props);
if (!props.viewer) {
this.handleLogout();
console.log('Access expired.');
return;
}
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => {
return r1.cursor !== r2.cursor;
}});
this.state = {
dataSource: ds.cloneWithRows(props.viewer.firstLoad.edges),
};
}
componentWillMount() {
// Set up to query for newly received messages
const {edges} = this.props.viewer.firstLoad;
this.props.relay.setVariables({
last: edges.length,
before: edges[edges.length - 1].cursor,
});
}
componentDidMount() {
this._interval = setInterval(() => {
this.props.relay.setVariables({
last: this.props.relay.variables.last + 10,
});
}, 2000);
}
componentWillReceiveProps(nextProps) {
const {edges} = nextProps.viewer.afterFirst;
if (edges) {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(edges),
});
}
}
我已经成功地解决了我的需求,创建了一个新字段,在光标/时间戳之后返回新项目,并手动维护一个用于显示的数据数组,该数组由来自中继的数据填充 一个关键的方法是用一些随机数据连接变量,这样setVariables将向服务器而不是缓存发出请求
startPolling(){
这个。_timer=setTimeout(()=>{
this.props.relay.setVariables({
lastCreatedAt:`${this.\u lastCreatedAt}:${new Date().getTime()}`,
});
这个。startPolling();
}, 5000);
}