2016-02-27 10:58:57 +09:00
|
|
|
// const ItemContainer = React.createClass({
|
2016-02-16 15:40:37 +09:00
|
|
|
|
2016-02-27 10:58:57 +09:00
|
|
|
// propTypes: {
|
|
|
|
// collection: React.PropTypes.object.isRequired,
|
|
|
|
// selector: React.PropTypes.object.isRequired,
|
|
|
|
// publication: React.PropTypes.string,
|
|
|
|
// joins: React.PropTypes.array,
|
|
|
|
// loading: React.PropTypes.func
|
|
|
|
// },
|
2016-02-16 15:40:37 +09:00
|
|
|
|
2016-02-27 10:58:57 +09:00
|
|
|
// mixins: [ReactMeteorData],
|
2016-02-16 15:40:37 +09:00
|
|
|
|
2016-02-27 10:58:57 +09:00
|
|
|
// getMeteorData() {
|
2016-02-16 15:40:37 +09:00
|
|
|
|
2016-02-27 10:58:57 +09:00
|
|
|
// // subscribe if necessary
|
|
|
|
// if (this.props.publication) {
|
|
|
|
// const subscription = Meteor.subscribe(this.props.publication, this.props.selector);
|
|
|
|
// }
|
2016-02-23 11:34:40 +09:00
|
|
|
|
2016-02-27 10:58:57 +09:00
|
|
|
// const collection = this.props.collection;
|
|
|
|
// const document = collection.findOne(this.props.selector);
|
2016-02-23 11:34:40 +09:00
|
|
|
|
2016-02-27 10:58:57 +09:00
|
|
|
// // look for any specified joins
|
|
|
|
// if (document && this.props.joins) {
|
|
|
|
|
|
|
|
// // loop over each join
|
|
|
|
// this.props.joins.forEach(join => {
|
|
|
|
|
|
|
|
// // get the property containing the id or ids
|
|
|
|
// const joinProperty = document[join.property];
|
|
|
|
// const collection = Meteor.isClient ? window[join.collection] : global[join.collection];
|
|
|
|
|
|
|
|
// // perform the join
|
|
|
|
// if (Array.isArray(joinProperty)) { // join property is an array of ids
|
|
|
|
// document[join.joinAs] = collection.find({_id: {$in: joinProperty}}).fetch();
|
|
|
|
// } else { // join property is a single id
|
|
|
|
// document[join.joinAs] = collection.findOne({_id: joinProperty});
|
|
|
|
// }
|
2016-02-22 13:23:46 +09:00
|
|
|
|
2016-02-27 10:58:57 +09:00
|
|
|
// });
|
2016-02-16 15:40:37 +09:00
|
|
|
|
2016-02-27 10:58:57 +09:00
|
|
|
// }
|
2016-02-16 15:40:37 +09:00
|
|
|
|
2016-02-27 10:58:57 +09:00
|
|
|
// return {
|
|
|
|
// document: document,
|
|
|
|
// currentUser: Meteor.user()
|
|
|
|
// };
|
|
|
|
// },
|
2016-02-16 15:40:37 +09:00
|
|
|
|
2016-02-27 10:58:57 +09:00
|
|
|
// render() {
|
|
|
|
// const loadingComponent = this.props.loading ? this.props.loading : <p>Loading…</p>
|
|
|
|
// if (this.data.document) {
|
|
|
|
// return React.cloneElement(this.props.children, { ...this.data, collection: this.props.collection });
|
|
|
|
// } else {
|
|
|
|
// return loadingComponent;
|
|
|
|
// }
|
|
|
|
// }
|
2016-02-16 15:40:37 +09:00
|
|
|
|
2016-02-27 10:58:57 +09:00
|
|
|
// });
|
2016-02-16 15:40:37 +09:00
|
|
|
|
2016-02-27 10:58:57 +09:00
|
|
|
// module.exports = ItemContainer;
|