【发布时间】:2016-05-09 20:32:39
【问题描述】:
我正在尝试进行无限滚动,只需增加第一个值即可。但是,我想获取开头之前的新边。如果不强制获取,我该如何做到这一点?
这是我的 RelayContainer,其中 firstLoad 和 afterFirst 使用别名引用具有不同参数的相同连接。 Relay 不会查询之前的任何内容。我还从 graphql 服务器端强制将 hasNextPage 和 hasPreviousPage 设置为 true
relay如何决定是否从服务器获取新的edge
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),
});
}
}
【问题讨论】:
标签: ecmascript-6 relayjs