I’m noticing an issue with pub/sub in Meteor. Maybe I’m doing something wrong. Here’s what’s happening:
I’m subscribing to notifications
, but only ones that are meant for me:
Meteor.publish('notifications', function () {
return Notifications.find({
toUserIds: this.userId,
dismissedBy: { $ne: this.userId },
});
});
In NotificationCenterContainer.js
, I subscribe to the publication:
import { Meteor } from 'meteor/meteor';
import { createContainer } from 'meteor/react-meteor-data';
import { connect } from 'react-redux';
import { Notification } from '../../../collections/notifications';
import NotificationCenter from './NotificationCenter';
export default connect()(createContainer(() => {
const handle = Meteor.subscribe('notifications');
return {
isDataReady: handle.ready(),
notifications: Notification.find({}, { sort: { createdAt: -1 } }).fetch(),
userId: Meteor.userId(),
}
}, NotificationCenter))
So, I generate a notification that’s sent to another user, and I see this in the Chrome console: (logged from the componentWillReceiveProps
method)
componentWillReceiveProps(nextProps) {
console.log('old props:', this.props.notifications,
'new props:', nextProps.notifications);
}
Is this normal, for Meteor data to be available for a split second to the client? I’ve never noticed this until now.