Manual Reference Source Test

src/helpers/discuss/Thread.js

import Helper from '../Helper';
import DiscussService from '../../services/DiscussService';
import ThreadModel from '../../models/discuss/Thread';
import Commentable from '../../utilities/mixins/Commentable';
import { aggregate } from '../../utilities/ClassUtility';

/**
 * Helper class representing a Thread.
 */
class Thread extends aggregate(ThreadModel, Helper, Commentable) {
  /**
   * Constructor for helper class representing Thread
   *
   * @param {Object} json - json api response from server
   */
  constructor(json = {}) {
    super(json);
    this.deserializeRelationshipStubs(json);
    this.syncRelationships(json);
    // this.syncRelationships(json).then(() => this.getComments());
    this.getComments();
  }

  /** @type {String}  - The type */
  static get type() {
    return 'commentable__threads';
  }

  /** @type {any} */
  get commentable() {
    return this._relationships.commentable;
  }

  /** @type {any} */
  set commentable(commentable) {
    /** @type {any} */
    this._relationships.commentable = commentable;
  }

  /** @type {Comment[]} */
  get comments() {
    return this._relationships.comments;
  }

  /** @type {Comment[]} */
  set comments(comments) {
    /** @type {Comment[]} */
    this._relationships.comments = comments;
  }

  /** @type {User} */
  get owner() {
    return this._relationships.owner;
  }

  /** @type {User} */
  set owner(owner) {
    /** @type {User} */
    this._relationships.owner = owner;
  }

  /**
   * Returns comments for the current thread
   */
  getComments(cacheMode = undefined) {
    return (new DiscussService()).getComments(this, cacheMode).then((comments) => {
      this.syncRelationships();
      return comments;
    });
  }
}

export default Thread;