arunoda / react-komposer

Feed data into React components by composing containers.
MIT License
732 stars 70 forks source link

When changing parameters from one subscription, other subscription from same collection is updated #156

Closed KyneSilverhide closed 7 years ago

KyneSilverhide commented 7 years ago

Hello, I have this one strange bug I can't really understand..

My components are like this

<DevPage>
   <TeamDevList/>
   <Modal>
      <AllDevList/>
    </Modal>
</DevPage>

DevPage is the root page, TeamDevList is a component that displays all the developers in a collection that are assigned to the selected team, AllDevList is a sub component to manually add developers to the list. Modal is just a React Bootstrap modal. My containers have the same name as the components, but in two different folders.

AllDevList

const composer = (params, onData) => {
  const subscription = Meteor.subscribe('developers.list');
  if (subscription.ready()) {
    const matchingDevelopers = Developers.find().fetch();
    onData(null, { matchingDevelopers });
  }
};
export default composeWithTracker(composer, Loading)(AllDevList);

TeamDevList

const composer = ({ params }, onData) => {
  const subscription = Meteor.subscribe('developers.by.team', teamId);

  if (subscription.ready()) {    
    const developersInTeam = Developers.find().fetch();
    onData(null, { developersInTeam });
  }
};
export default composeWithTracker(composer, Loading)(TeamDevList);

Now, whenever a click on the "Show modal" button to display the whole list... both subscriptions are updated and both show the same list. The team parameter gets ignored. I've added a debug in both containers, and they return the same list of developers, even if these are two different subscriptions. This only occurs when both subscriptions are linked to the same collection.

I guess I somehow need to "stop" or "unsubscribe" somewhere in the code, but I can't find how, and where.

KyneSilverhide commented 7 years ago

Ok, my fault...

I'm very new to Meteor, and I didn't understood subscriptions properly. When subscribing to multiple subscriptions on the same collections, data is put into the "client minimongo". So I have to manually filter after calling the subscirption, otherwise I will get the "union" of both subscriptions.

It works properly now

const developersSub = Meteor.subscribe('developers.by.team', teamId);
...
const developers = Developers.find({ 'teamId':  teamId }).fetch();