1

I don't really understand any of this from https://github.com/Akryum/meteor-vuex-example/tree/master/imports/vuex/modules: from init(data) all the way to if data in getters at the bottom references to vue instance data or state of vuex.

subModule.addTrackers({
  selectedThread() {
    let sub;
    return {
      init(data) {
        data.selectedThread = null;
        data.posts = [];
      },
      watch(state) {
        // Dynamic subscription
        if(sub) {
          sub.stop();
        }
        if(state.selectedThreadId) {
          sub = Meteor.subscribe('posts', state.selectedThreadId);
          console.log('subscribed posts to thread ', state.selectedThreadId);
        }

        return {
          id: state.selectedThreadId
        }
      },
      update(data, {id}) {
        data.selectedThread = Object.freeze(Threads.findOne({
          _id: id
        }));
        data.posts = Object.freeze(Posts.find({
          thread_id: id
        }, {
          sort: {created: -1}
        }).fetch());
        console.log('posts', data.posts);
      },
      getters: {
        getSelectedThread: data => data.selectedThread,
        getPosts: data => data.posts
      }
    }
  }
})
janat08
  • 1,725
  • 2
  • 16
  • 27
  • Trackers aren't awfully well documented other than in API, but the gist of it is that you combine reactive data source to processing program behaving as a variable of reactive source. I don't think I found the these options in API documents nonetheless, with getters and possibly init being akryum ones. – janat08 Jan 04 '17 at 03:41

0 Answers0