Hi,
Very odd behaviour which I’m not sure how to troubleshoot.
Have a container as below
import { composeAll, composeWithTracker } from 'react-komposer';
import { Loading } from '../components/layout/loading.js';
import { Meteor } from 'meteor/meteor';
import { Entities } from '../../api/entities/entities.js';
import { Groups } from '../../api/groups/groups.js';
import { LocalAdmin } from '../components/localAdmin/localAdmin.js';
const composerUser = (params, onData) => {
onData(null, { user: Meteor.user() });
};
const composerEntities = (params, onData) => {
const subscription = Meteor.subscribe('entities.localAdmin');
if (subscription.ready()) {
const entities = Entities.find().fetch();
onData(null, { entities });
}
};
const composerGroups = (params, onData) => {
const subscription = Meteor.subscribe('groups.localAdmin');
if (subscription.ready()) {
const groups = Groups.find().fetch();
onData(null, { groups });
}
};
export default composeAll(
composeWithTracker(composerUser, Loading, null, { pure: false }),
composeWithTracker(composerEntities, Loading, null, { pure: false }),
composeWithTracker(composerGroups, Loading, null, { pure: false }),
)(LocalAdmin);
The two publications look like below:
Meteor.publish('entities.localAdmin', function() {
let tempEntities = [];
// The idea is work out the original entity id and add to array.
// Then also add in any entities which are linked to the original.
if (Entities.find({ entityUsers: this.userId }, { _id: 1 }, { limit: 1 }).fetch().length) {
const entity = Entities.findOne({ entityUsers: this.userId });
tempEntities.push(entity._id);
entity.entityLinkages.map((x) => (
tempEntities.push(x)
));
}
// Publish the lot, the $in parses for entities in our dynamic array
return Entities.find({ _id: { $in: tempEntities } });
});
And…
Meteor.publish('groups.localAdmin', function() {
let groups = [];
// The idea is work out the original entity id
// Then check what groups it has and make up list of same..
if (Entities.find({ entityUsers: this.userId }, { _id: 1 }, { limit: 1 }).fetch().length) {
const entity = Entities.findOne({ entityUsers: this.userId });
entity.entityGroups.map((x) => (
groups.push(x)
));
}
// Publish the lot, the $in parses for groups in our dynamic array
return Groups.find({ _id: { $in: groups } });
});
If I take out the composerGroups from my container, the entities publications works perfectly. If I leave it in, the entities publication seems to break and provide me with more information than needed.
Inside my UI component LocalAdmin
, in the componentWillMount() I have three consoles…
componentWillMount() {
console.log(this.props.user);
console.log(this.props.entities);
console.log(this.props.groups);
}
Output
(1) Leave the composerGroups out… ignore the proptype warning, its just I had isRequired on the props… Note that the localAdmin.js:20 has “2/two” objects
warning.js:44 Warning: Failed prop type: Required prop `groups` was not specified in `LocalAdmin`.
localAdmin.js:19 Object {_id: "MJF2P9JW6Y2bXAqtp", emails: Array[1], profile: Object, roles: Object}
localAdmin.js:20 [Object, Object]
localAdmin.js:21 undefined
(2) Keep the composerGroups in… Note that the localAdmin.js:20 has “4/four” objects
localAdmin.js:19 Object {_id: "MJF2P9JW6Y2bXAqtp", emails: Array[1], profile: Object, roles: Object}
localAdmin.js:20 [Object, Object, Object, Object]
localAdmin.js:21 [Object, Object, Object, Object]
That is the problem. The correct functioning of the publish should have 2 objects only. Somehow the publications are getting confused.
To clarify, as far as I can tell the publications themselves are fine. But when the get into the container together, they seem to shit themselves.
How do i troubleshoot this? Thanks so much.
Tat