2016-02-15 22:33:44 +09:00
|
|
|
// import {composeWithTracker} from 'react-komposer';
|
|
|
|
|
|
|
|
// const composer = (props, onData) => {
|
|
|
|
|
|
|
|
// console.log(props)
|
|
|
|
|
|
|
|
// var terms = props;
|
|
|
|
// // const terms = {...props, limit: this.state.limit};
|
|
|
|
// const parameters = Posts.parameters.get(terms);
|
|
|
|
// const find = parameters.find;
|
|
|
|
// const options = parameters.options;
|
|
|
|
// // options.limit = this.state.limit;
|
|
|
|
|
|
|
|
|
|
|
|
// Meteor.subscribe('postList', terms, () => {
|
|
|
|
// console.log(find, options)
|
|
|
|
// const posts = Posts.find(find, options).fetch();
|
|
|
|
// console.log(Posts.find().count())
|
|
|
|
// console.log(posts)
|
|
|
|
// onData(null, {posts});
|
|
|
|
// });
|
|
|
|
|
|
|
|
// // support latency compensation
|
|
|
|
// // we don't need to invalidate tracker because of the
|
|
|
|
// // data fetching from the cache.
|
|
|
|
// // const postFromCache = Tracker.nonreactive(() => {
|
|
|
|
// // return Posts.find(find, options);
|
|
|
|
// // });
|
|
|
|
|
|
|
|
// // if (postFromCache) {
|
|
|
|
// // onData(null, {post: postFromCache});
|
|
|
|
// // } else {
|
|
|
|
// // onData();
|
|
|
|
// // }
|
|
|
|
// };
|
|
|
|
|
|
|
|
// PostListContainer = composeWithTracker(composer)(PostList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 12:27:20 +09:00
|
|
|
// import React from 'react';
|
|
|
|
|
2016-02-16 15:08:30 +09:00
|
|
|
const PostListContainer = React.createClass({
|
2016-02-14 12:27:20 +09:00
|
|
|
|
|
|
|
// propTypes: {
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
2016-02-15 22:33:44 +09:00
|
|
|
getInitialState() {
|
|
|
|
|
|
|
|
return {
|
|
|
|
limit: 5
|
|
|
|
};
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2016-02-14 12:27:20 +09:00
|
|
|
mixins: [ReactMeteorData],
|
|
|
|
|
|
|
|
getMeteorData() {
|
2016-02-16 15:08:30 +09:00
|
|
|
const terms = {...this.props.terms, limit: this.state.limit};
|
2016-02-15 22:33:44 +09:00
|
|
|
const parameters = Posts.parameters.get(terms);
|
|
|
|
const find = parameters.find;
|
|
|
|
const options = parameters.options;
|
|
|
|
options.limit = this.state.limit;
|
|
|
|
|
|
|
|
// var cursor = Posts.find(find, options);
|
|
|
|
// var sm = SmartQuery.create("posts", cursor);
|
|
|
|
|
|
|
|
// console.log(terms)
|
|
|
|
|
2016-02-16 15:08:30 +09:00
|
|
|
const subscription = Meteor.subscribe('posts.list', terms);
|
2016-02-15 22:33:44 +09:00
|
|
|
|
2016-02-16 15:08:30 +09:00
|
|
|
const totalCount = Counts.get('posts.list');
|
2016-02-15 22:33:44 +09:00
|
|
|
|
|
|
|
const cursor = Posts.find(find, options);
|
|
|
|
|
2016-02-14 12:27:20 +09:00
|
|
|
return {
|
2016-02-15 22:33:44 +09:00
|
|
|
posts: cursor.fetch(),
|
|
|
|
ready: subscription.ready(),
|
|
|
|
count: cursor.count(),
|
|
|
|
totalCount: totalCount,
|
|
|
|
hasMore: cursor.count() < totalCount
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
loadMore(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.setState({
|
|
|
|
limit: this.state.limit+5
|
|
|
|
});
|
2016-02-14 12:27:20 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
2016-02-16 15:08:30 +09:00
|
|
|
const PostListComponent = Telescope.getComponent(this.props.component);
|
2016-02-14 12:27:20 +09:00
|
|
|
return (
|
2016-02-16 15:08:30 +09:00
|
|
|
<PostListComponent {...this.data} loadMore={this.loadMore}/>
|
2016-02-14 12:27:20 +09:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2016-02-16 15:08:30 +09:00
|
|
|
// export default PostListContainer;
|
|
|
|
|
|
|
|
module.exports = PostListContainer;
|