meteor-vue / vue-meteor-tracker

Use Meteor Tracker reactivity inside Vue components
90 stars 20 forks source link

Options API: functions in meteor object cannot access other properties #80

Open rickynaps opened 1 year ago

rickynaps commented 1 year ago
<script>
  export default {
    data() {
      return {
        selectedThreadId: 'test',
      };
    },
    computed: {
      testComputed() {
        return 'testComputed';
      },
    },
    meteor: {
      $subscribe: {
        threads: [],
      },
      meteorTestComputed() {
        // returns undefined
        return this.testComputed;
      },
      testSubReady() {
        // this.$subReady.threads == undefined
        if (this.$subReady.threads) {
          console.log('test If');
        }
      },
      threads() {
        //  Works as expected.
        return Threads.find(
          {},
          {
            sort: { date: -1 },
          }
        );
      },
      threadsTest() {
        // Returns undefined
        return this.threads;
      },
      selectedThread() {
        // Doesn't work as expected.
        const test = this.selectedThreadId;
        // test == undefined
        // The same happens with properties in computed and meteor sections.
        return Threads.findOne(this.selectedThreadId);
      },
    },
  };
</script>

<!-- 
computed
can access meteor properties
cursor is not reactive

meteor
cursor is reactive
cannot access computed, meteor or data properties
can access this correctly -->
xolott commented 1 year ago

Same here, with:

We can't access data or computed properties inside the meteor block.

I had to change the component to composition API