inProgress-team / react-native-meteor

Meteor Reactivity for your React Native application :)
MIT License
693 stars 210 forks source link

Possible unhandled promise rejection (id: 0): TypeError: undefined is not an object (evaluating 'this._meteorDataManager.calculateData') #224

Closed JulianKingman closed 7 years ago

JulianKingman commented 7 years ago

Sorry I don't have many details for this error, I can't pin down where it's coming from. Anyone have experience with it?

screen shot 2017-05-01 at 2 11 02 pm

noris666 commented 7 years ago

Can you create gists of your server and client side code ?

JulianKingman commented 7 years ago

I don't have access to the server-side code, and the client-side code is pretty big, but here's the part in question (I took out some parts for simplicity):

export default
  withNavigation(connect((state) => {
    return {
      selectedProjectId: state.appState.selectedProjectId,
      subsReadyOnce: state.appState.subsReadyOnce,
      selectedStatuses: state.appState.selectedStatuses,
      parentTaskIds: state.appState.parentTaskIds,
    };
  })(hoistNonReactStatic(createContainer((props) => {
    const {selectedProjectId, route, selectedStatuses, parentTaskIds} = props;
    const currentTaskId = (route.params && route.params.taskId) || '0';

    // This prevents duplicate subscriptions when multiple instances of this component exist
    const subscriptionExists = route.params && route.params.subscriptionExists;
    let taskSubscription = {ready: () => subscriptionExists};
    if (selectedProjectId && !subscriptionExists) {
      taskSubscription = Meteor.subscribe('tasks',
        () => {
          Store.dispatch({type: 'SET_SUBSREADYONCE', subsReadyOnce: true});
        },
      );
    }
    const projects = _.map(Meteor.collection('projects').find({}),
      (project, i) => Object.assign({index: i}, project));

    const currentProject = _.filter(projects, {_id: selectedProjectId})[0];
    const members = currentProject ? currentProject.members : [];
    const memberIds = _.map(members, '_id');
    Meteor.subscribe('users', memberIds);
    let allTasks;

    let tasks;
    if (selectedStatuses && selectedStatuses.length) {
      allTasks = Meteor.collection('ProjectTasks').find({state: {$in: selectedStatuses || []}});
      tasks = Meteor.collection('ProjectTasks').find({query});
    } else {
      allTasks = Meteor.collection('ProjectTasks').find({query});
      tasks = Meteor.collection('ProjectTasks').find({query});
    }

    const statusQuery = (selectedStatuses && selectedStatuses.length) ?
      {state: {$in: selectedStatuses || []}} : {};

    const directTasks = Meteor.collection('ProjectTasks').find(
      {
        ...query,
        ...userQuery,
        ...statusQuery,
      });
    return {
      tasks,
      projects,
      userId: Meteor.userId(),
      taskSubscription,
      selectedProjectId,
      tasksReady: taskSubscription.ready(),
      members: currentTaskId === '0' ?
        _.filter(memberIds.map((userId) => {
          const userTasks = Meteor.collection('ProjectTasks').find({
            ...query,
          });
          if (userTasks && userTasks.length) {
            return Meteor.collection('users').findOne(userId);
          }
          return false;
        }), (userObject) => !_.isEmpty(userObject)) :
        [],
      allTasks,
      directTasks: currentTaskId === '0' ? directTasks : [],
    };
  },Projects),
    Projects,
  )));
JulianKingman commented 7 years ago

I think it had to do with not being connected before returning collections, etc... In any case, that solved it.