Data once appeared on client will remain in client side?


#1

Hello,
Current I am dealing with two components

  1. ListComponent
  2. EditComponent

I fetched list persons from the collection and showed in list component - Done No problem
I want to fetch only one person from the collection whose ID I am going to provide.
But here comes the problem. Same data available in both the component.
If you subscribe and publish for one component same data is available for 2nd component also.
No need to publish again.

Publication File

import {Meteor} from 'meteor/meteor';
import BirthdayKeeper from '../birthday.keeper';

if (Meteor.isServer) {
  Meteor.publish('readBirthdays', function () {
    return BirthdayKeeper.find();
  });

  Meteor.publish('readOneBirthday', function (id) {
    if (!id) return;
    let x = BirthdayKeeper.find({ _id: id });
    console.log(x.fetch());
    return x;
  });
}

2.List Component

import React from 'react';
import { Meteor } from 'meteor/meteor';
import { withTracker } from 'meteor/react-meteor-data';
import BirthdayKeeper from '../../api/birthday-keeper/birthday.keeper';
import PropTypes from 'prop-types';

export class BdayListComponent extends React.Component {
  render() {
     console.log(this.props)
    return (
      <div style={styles.listWrapper}>
         List goes here
      </div>
    )
  }
}

BdayListComponent.propTypes = {
  birthdays: PropTypes.arrayOf(Object),
  loading: PropTypes.bool,
}

export default BdayListContainer = withTracker(() => {
  let data = { loading: true };
  let getBirthdays = Meteor.subscribe('readBirthdays');
  if (!getBirthdays.ready()) return { data };
  data.birthdays = BirthdayKeeper.find().fetch() || [];
  data.loading = false;
  return { ...data };
})(Radium(BdayListComponent));

3.Birthday Editor

import React from 'react';
import { Meteor } from 'meteor/meteor';
import PropTypes from 'prop-types';
import { withTracker } from 'meteor/react-meteor-data';
import BirthdayKeeper from '../../api/birthday-keeper/birthday.keeper';

export class BdayEditorComponent extends React.Component {
  render() {
    return (
      <div>
        This is bday editor
      </div>
    )
  }
}

export default BdayEditorContainer = withTracker((bdayInfo) => {
  const id = bdayInfo.bdaySelected;
  let data = { loading: true };
  let getSelectedBday = Meteor.subscribe('readOneBirthday', id);
  if (!getSelectedBday.ready()) return { data };
  data.birthday = BirthdayKeeper.find().fetch();
  data.loading = false;
  console.log(data);
  return { ...data }
})(BdayEditorComponent);

My Question IS -
If data comes toward client side - will it always be there during the session.

Can we restrict data from component to component.
Please help


#2

All subscriptions will get cleaned up when your component is unmounted.

meteor/react-meteor-data package: